Drive Engine  1.0.0
Plateforme de reconstruction 3D
CollectionsImplementationUtilities.h
1 // Copyright (c) 2015. All rights reserved to DriveEngine Team.
2 
3 #pragma once
4 
5 
9 #define _GENERATE_COLLECTION_COMMON(collectionClassName, collectionStdName) \
10 /* ICollection */\
11 \
12 Size collectionClassName::GetSize() const\
13 {\
14  return this->collectionStdName.size();\
15 }\
16 \
17 bool collectionClassName::IsEmpty() const\
18 {\
19  return this->collectionStdName.empty();\
20 }\
21 \
22 IEnumerator* collectionClassName::GetEnumerator() const\
23 {\
24  return Enumerator::Create(collectionStdName.begin(), collectionStdName.end());\
25 }\
26 \
27 IConstEnumerator* collectionClassName::GetConstEnumerator() const\
28 {\
29  return ConstEnumerator::Create(collectionStdName.begin(), collectionStdName.end());\
30 }
31 
32 
36 #define _GENERATE_COLLECTION_GENERIC_ENUMERATOR_H(enumeratorInterfaceName, enumeratorClassName, mustBeConst, collectionStdType)\
37 private:\
38  class enumeratorClassName : public enumeratorInterfaceName\
39  {\
40  private:\
41  bool hasMovedAtLeastOnce;\
42  collectionStdType::const_iterator iterator;\
43  collectionStdType::const_iterator begin;\
44  collectionStdType::const_iterator end;\
45 \
46  public:\
47  CONSTRUCTOR_H(enumeratorInterfaceName, enumeratorClassName, collectionStdType::const_iterator& begin, collectionStdType::const_iterator& end); \
48  DESTRUCTOR_H(enumeratorClassName); \
49 \
50 \
51  /* enumeratorInterfaceName */\
52 \
53  virtual bool MoveNext();\
54  virtual mustBeConst IExportable* GetCurrent() const;\
55  virtual void Reset();\
56  };
57 
58 
62 #define _GENERATE_COLLECTION_ENUMERATOR_H(collectionStdType) _GENERATE_COLLECTION_GENERIC_ENUMERATOR_H(IEnumerator, Enumerator,,collectionStdType)
63 
64 
68 #define _GENERATE_COLLECTION_CONST_ENUMERATOR_H(collectionStdType) _GENERATE_COLLECTION_GENERIC_ENUMERATOR_H(IConstEnumerator, ConstEnumerator, const, collectionStdType)
69 
70 
74 #define _GENERATE_COLLECTION_GENERIC_ENUMERATOR(enumeratorInterfaceName, enumeratorClassName, mustBeConst, collectionClassName, collectionStdType, getCurrentLogic)\
75 \
76 /* Enumerator */\
77 \
78 CONSTRUCTOR_INNER(enumeratorInterfaceName, collectionClassName, enumeratorClassName, (collectionStdType::const_iterator&) begin, (collectionStdType::const_iterator&) end)\
79  : begin(begin),\
80  end(end),\
81  iterator(begin),\
82  hasMovedAtLeastOnce(false)\
83 {}\
84 \
85 DESTRUCTOR_INNER(collectionClassName, enumeratorClassName)\
86 {\
87 \
88 }\
89 \
90 bool collectionClassName::enumeratorClassName::MoveNext()\
91 {\
92  if (!hasMovedAtLeastOnce)\
93  {\
94  iterator = begin;\
95  hasMovedAtLeastOnce = true;\
96  }\
97  else if (iterator != end)\
98  {\
99  ++iterator;\
100  }\
101 \
102  return (iterator != end);\
103 }\
104 \
105 mustBeConst IExportable* collectionClassName::enumeratorClassName::GetCurrent() const\
106 {\
107  IExportable* result = nullptr;\
108  if (hasMovedAtLeastOnce && iterator != end)\
109  {\
110  getCurrentLogic\
111  }\
112  return result;\
113 }\
114 \
115 void collectionClassName::enumeratorClassName::Reset()\
116 {\
117  iterator = begin;\
118  hasMovedAtLeastOnce = false;\
119 }
120 
121 
125 #define _GENERATE_COLLECTION_ENUMERATOR(collectionClassName, collectionStdType, getCurrentLogic)\
126  _GENERATE_COLLECTION_GENERIC_ENUMERATOR(IEnumerator, Enumerator,, collectionClassName, collectionStdType, getCurrentLogic)
127 
128 
132 #define _GENERATE_COLLECTION_CONST_ENUMERATOR(collectionClassName, collectionStdType, getCurrentLogic)\
133  _GENERATE_COLLECTION_GENERIC_ENUMERATOR(IConstEnumerator, ConstEnumerator, const, collectionClassName, collectionStdType, getCurrentLogic)