Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Criteria
- {
- typedef std::string Criteria::* DataRefType;
- std::string firstname;
- std::string lastname;
- std::string website;
- };
- class Field
- {
- public:
- Field( const std::string& name,
- Criteria::DataRefType ref ):
- name_( name ),
- ref_( ref )
- {}
- std::string getData( const Criteria& criteria )
- {
- return criteria.*ref_;
- }
- std::string name_;
- private:
- Criteria::DataRefType ref_;
- };
- class Fields
- {
- public:
- Fields()
- {
- fields_.push_back( Field( "First Name", &Criteria::firstname ) );
- fields_.push_back( Field( "Last Name", &Criteria::lastname ) );
- fields_.push_back( Field( "Website", &Criteria::website ) );
- }
- template < typename TFunction >
- void forEach( TFunction function )
- {
- std::for_each( fields_.begin(), fields_.end(),
- function );
- }
- private:
- std::vector< Field > fields_;
- };
- GuiWindow( Criteria& criteria ):
- criteria_( criteria )
- {
- fields_.forEach( std::bind1st(
- std::mem_fun( &GuiWindow::bindWithGui ),
- this ) );
- }
- void bindWithGui( Field field )
- {
- std::cout << "name " << field.name_
- << " value " << field.getData( criteria_ ) << std::endl;
- };
- SET NETWORK ROUTE 192.168.0.0 HOPS 1
- QUERY NETWORK NAMESERVER servername
- vector<SomeClass*> v = getAVector();
- for_each(v.begin(), v.end(), mem_fun(&SomeClass::print));
- #define DomainList(Class, Description, First, Next, Item, UpdateItem, DeleteItem, IsItemRequired, MaxLength) {
- CWFLHandler *handler = new CWFLHandler;
- handler->pWFL = new Class;
- handler->LoadFirstType = (LoadFirst)&Class::First;
- handler->LoadNextType = (LoadNext)&Class::Next;
- handler->LoadType = (Load)&Class::Item;
- handler->UpdateType = (Update)&Class::UpdateItem;
- handler->DeleteType = (Delete)&Class::DeleteItem;
- handler->IsRequiredType= (IsRequired)&Class::IsItemRequired;
- handler->MAX_LENGTH = MaxLength;
- PopulateListBox(m_Domain, Description, (long)handler); }
- DomainList(CConfigWFL, "Application Parameter Types", LoadFirstParameterType, LoadNextParameterType, LoadParameterTypeByTypeId, UpdateParameterType, DeleteParameterType, IsParameterTypeRequired, LEN_APPL_PARAMETER_DESC);
- if((pWFLPtr->pWFL->*pWFLPtr->LoadFirstType)(true))
- {
- do
- {
- m_Grid.AddGridRow();
- m_Grid.SetCheck(COLUMN_SYSTEM, (pWFLPtr->pWFL->*pWFLPtr->IsRequiredType)(pWFLPtr->pWFL->TypeId));
- m_Grid.SetCheck(COLUMN_STATUS, pWFLPtr->pWFL->InactiveIndc == false);
- m_Grid.AddTextToGrid(COLUMN_NAME, pWFLPtr->pWFL->TypeDesc);
- m_Grid.AddTextToGrid(COLUMN_DEBUG, pWFLPtr->pWFL->TypeId);
- m_Grid.AddTextToGrid(COLUMN_ID, pWFLPtr->pWFL->TypeId);
- }
- while((pWFLPtr->pWFL->*pWFLPtr->LoadNextType)());
- typedef bool (CMyWFL::*LoadFirst)(bool);
- typedef bool (CMyWFL::*LoadNext)();
- typedef bool (CMyWFL::*Load)(long);
- typedef bool (CMyWFL::*Update)(long, const char*, bool);
- typedef bool (CMyWFL::*Delete)(long);
- typedef bool (CMyWFL::*IsRequired)(long);
- class CWFLHandler {
- public:
- CWFLHandler() {};
- ~CWFLHandler() { if(pWFL) delete pWFL; }
- CMyWFL *pWFL;
- LoadFirst LoadFirstType;
- LoadNext LoadNextType;
- Load LoadType;
- Update UpdateType;
- Delete DeleteType;
- IsRequired IsRequiredType;
- int MAX_LENGTH;
- };
- CWFLHandler *pWFLPtr;
- template<class STRUCT, typename FIELDTYPE>
- struct FieldBinderImpl : public FieldBinder<STRUCT>
- {
- typedef FIELDTYPE (STRUCT::*MemberPtr);
- FieldBinderImpl (const std::string& tag, MemberPtr memberPtr)
- : FieldBinder (tag)
- , memberPtr_ (memberPtr)
- {
- }
- virtual SerialiserBase* createSerialiser (STRUCT& data) const
- {
- return new Serialiser<FIELDTYPE> (&(data.*memberPtr_));
- }
- private:
- MemberPtr memberPtr_;
- };
- template<class T>
- class StructSerialiser : public SerialiserData<T>
- {
- public:
- typedef std::vector<FieldBinder<T>*> FieldBinderList;
- private:
- static FieldBinderList fieldBinderList_;
- protected:
- template<typename FIELDTYPE>
- static void bind (const std::string& tag, FIELDTYPE (T::* member))
- {
- fieldBinderList_.push_back (new FieldBinderImpl<T, FIELDTYPE> (tag, member));
- if (tag.empty ())
- fieldBinderList_.back ()->tags_ = Serialiser<FIELDTYPE>::getTags ();
- }
- // ...
- }
- // ...
- class Index
- {
- public:
- std::string currency;
- std::string name;
- };
- template<>
- class Serialiser<Index> : public StructSerialiser<Index>
- {
- public:
- Serialiser (Index* data) : StructSerialiser<Index> (data) {}
- static void initialise ()
- {
- bind ("currency", &Index::currency);
- bind ("name", &Index::name);
- }
- };
Add Comment
Please, Sign In to add comment