Guest User

Untitled

a guest
Jun 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. struct Criteria
  2. {
  3. typedef std::string Criteria::* DataRefType;
  4. std::string firstname;
  5. std::string lastname;
  6. std::string website;
  7. };
  8.  
  9. class Field
  10. {
  11. public:
  12. Field( const std::string& name,
  13. Criteria::DataRefType ref ):
  14. name_( name ),
  15. ref_( ref )
  16. {}
  17. std::string getData( const Criteria& criteria )
  18. {
  19. return criteria.*ref_;
  20. }
  21. std::string name_;
  22. private:
  23. Criteria::DataRefType ref_;
  24. };
  25.  
  26. class Fields
  27. {
  28. public:
  29. Fields()
  30. {
  31. fields_.push_back( Field( "First Name", &Criteria::firstname ) );
  32. fields_.push_back( Field( "Last Name", &Criteria::lastname ) );
  33. fields_.push_back( Field( "Website", &Criteria::website ) );
  34. }
  35. template < typename TFunction >
  36. void forEach( TFunction function )
  37. {
  38. std::for_each( fields_.begin(), fields_.end(),
  39. function );
  40. }
  41. private:
  42. std::vector< Field > fields_;
  43. };
  44.  
  45. GuiWindow( Criteria& criteria ):
  46. criteria_( criteria )
  47. {
  48. fields_.forEach( std::bind1st(
  49. std::mem_fun( &GuiWindow::bindWithGui ),
  50. this ) );
  51. }
  52. void bindWithGui( Field field )
  53. {
  54. std::cout << "name " << field.name_
  55. << " value " << field.getData( criteria_ ) << std::endl;
  56. };
  57.  
  58. SET NETWORK ROUTE 192.168.0.0 HOPS 1
  59.  
  60. QUERY NETWORK NAMESERVER servername
  61.  
  62. vector<SomeClass*> v = getAVector();
  63. for_each(v.begin(), v.end(), mem_fun(&SomeClass::print));
  64.  
  65. #define DomainList(Class, Description, First, Next, Item, UpdateItem, DeleteItem, IsItemRequired, MaxLength) {
  66. CWFLHandler *handler = new CWFLHandler;
  67. handler->pWFL = new Class;
  68. handler->LoadFirstType = (LoadFirst)&Class::First;
  69. handler->LoadNextType = (LoadNext)&Class::Next;
  70. handler->LoadType = (Load)&Class::Item;
  71. handler->UpdateType = (Update)&Class::UpdateItem;
  72. handler->DeleteType = (Delete)&Class::DeleteItem;
  73. handler->IsRequiredType= (IsRequired)&Class::IsItemRequired;
  74. handler->MAX_LENGTH = MaxLength;
  75. PopulateListBox(m_Domain, Description, (long)handler); }
  76.  
  77. DomainList(CConfigWFL, "Application Parameter Types", LoadFirstParameterType, LoadNextParameterType, LoadParameterTypeByTypeId, UpdateParameterType, DeleteParameterType, IsParameterTypeRequired, LEN_APPL_PARAMETER_DESC);
  78.  
  79. if((pWFLPtr->pWFL->*pWFLPtr->LoadFirstType)(true))
  80. {
  81. do
  82. {
  83. m_Grid.AddGridRow();
  84. m_Grid.SetCheck(COLUMN_SYSTEM, (pWFLPtr->pWFL->*pWFLPtr->IsRequiredType)(pWFLPtr->pWFL->TypeId));
  85. m_Grid.SetCheck(COLUMN_STATUS, pWFLPtr->pWFL->InactiveIndc == false);
  86. m_Grid.AddTextToGrid(COLUMN_NAME, pWFLPtr->pWFL->TypeDesc);
  87. m_Grid.AddTextToGrid(COLUMN_DEBUG, pWFLPtr->pWFL->TypeId);
  88. m_Grid.AddTextToGrid(COLUMN_ID, pWFLPtr->pWFL->TypeId);
  89. }
  90. while((pWFLPtr->pWFL->*pWFLPtr->LoadNextType)());
  91.  
  92. typedef bool (CMyWFL::*LoadFirst)(bool);
  93. typedef bool (CMyWFL::*LoadNext)();
  94. typedef bool (CMyWFL::*Load)(long);
  95. typedef bool (CMyWFL::*Update)(long, const char*, bool);
  96. typedef bool (CMyWFL::*Delete)(long);
  97. typedef bool (CMyWFL::*IsRequired)(long);
  98.  
  99. class CWFLHandler {
  100. public:
  101. CWFLHandler() {};
  102. ~CWFLHandler() { if(pWFL) delete pWFL; }
  103.  
  104. CMyWFL *pWFL;
  105. LoadFirst LoadFirstType;
  106. LoadNext LoadNextType;
  107. Load LoadType;
  108. Update UpdateType;
  109. Delete DeleteType;
  110. IsRequired IsRequiredType;
  111. int MAX_LENGTH;
  112. };
  113. CWFLHandler *pWFLPtr;
  114.  
  115. template<class STRUCT, typename FIELDTYPE>
  116. struct FieldBinderImpl : public FieldBinder<STRUCT>
  117. {
  118. typedef FIELDTYPE (STRUCT::*MemberPtr);
  119.  
  120. FieldBinderImpl (const std::string& tag, MemberPtr memberPtr)
  121. : FieldBinder (tag)
  122. , memberPtr_ (memberPtr)
  123. {
  124. }
  125.  
  126. virtual SerialiserBase* createSerialiser (STRUCT& data) const
  127. {
  128. return new Serialiser<FIELDTYPE> (&(data.*memberPtr_));
  129. }
  130.  
  131. private:
  132. MemberPtr memberPtr_;
  133. };
  134.  
  135. template<class T>
  136. class StructSerialiser : public SerialiserData<T>
  137. {
  138. public:
  139. typedef std::vector<FieldBinder<T>*> FieldBinderList;
  140.  
  141. private:
  142. static FieldBinderList fieldBinderList_;
  143.  
  144. protected:
  145. template<typename FIELDTYPE>
  146. static void bind (const std::string& tag, FIELDTYPE (T::* member))
  147. {
  148. fieldBinderList_.push_back (new FieldBinderImpl<T, FIELDTYPE> (tag, member));
  149. if (tag.empty ())
  150. fieldBinderList_.back ()->tags_ = Serialiser<FIELDTYPE>::getTags ();
  151. }
  152.  
  153. // ...
  154. }
  155.  
  156. // ...
  157.  
  158. class Index
  159. {
  160. public:
  161. std::string currency;
  162. std::string name;
  163. };
  164.  
  165. template<>
  166. class Serialiser<Index> : public StructSerialiser<Index>
  167. {
  168. public:
  169. Serialiser (Index* data) : StructSerialiser<Index> (data) {}
  170.  
  171. static void initialise ()
  172. {
  173. bind ("currency", &Index::currency);
  174. bind ("name", &Index::name);
  175. }
  176. };
Add Comment
Please, Sign In to add comment