IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
DynamicByCreationResultSplit.h
1 // DynamicByCreationResultSplit.h:
3 // -------------------------------
4 //
15 
16 #ifndef __IPSDKBASEPROCESSING_DYNAMICBYCREATIONRESULTSPLIT_H__
17 #define __IPSDKBASEPROCESSING_DYNAMICBYCREATIONRESULTSPLIT_H__
18 
19 #include <IPSDKBaseProcessing/DataSplit/Dynamic/BaseDynamicSplit.h>
20 #include <IPSDKBaseData/Range/ElementsRange.h>
21 #include <boost/utility/enable_if.hpp>
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/static_assert.hpp>
24 #include <boost/make_shared.hpp>
25 #include <boost/function.hpp>
26 #include <map>
27 
28 namespace ipsdk {
29 namespace processor {
30 
33 
34 template <typename TProcessor, typename TAttribute>
36 {
37 // predefined public types
38 public:
40  static const eSplitDynamicType::domain g_splitDynamicType = eSplitDynamicType::eSDT_ByCreationResult;
41 
43  typedef TProcessor ProcessorType;
44 
46  typedef TAttribute AttributeType;
47 
49  typedef typename TAttribute::ValueType ValueType;
50 
52  typedef typename boost::enable_if<typename boost::is_same<typename TAttribute::StorageType,
53  boost::shared_ptr<typename TAttribute::ValueType> >::type,
54  typename TAttribute::StorageType>::type ParameterType;
55 
57  typedef std::map<ElementsRange, ParameterType> ParameterColl;
58 
60  typedef boost::shared_ptr<ParameterColl> ParameterCollPtr;
61 
63  typedef boost::function<ParameterType (const ipUInt64, const ipUInt64)> CreationFunType;
64 
65 public:
71 
72 // methods
73 public:
76 
78  const std::string& getAttributeName() const;
79 
81  const std::string& getAttributeToolTip() const;
82 
87  void init(const ParameterCollPtr& pParameterColl);
88  void init(const ParameterCollPtr& pParameterColl,
89  const CreationFunType& pCreationFun);
91 
92 protected:
94  bool checkProcessorType(const BaseProcessor& processor);
95 
99  BoolResult processAttribute(BaseProcessor& processor,
100  const ipUInt64 elementIdx,
101  const ipUInt64 nbElements,
102  const core::BaseRequestOrigin& requestOrigin);
103 
104 // attributes
105 protected:
108 
111 };
112 
115 
116 template <typename TProcessor, typename TAttribute>
117 inline eSplitDynamicType
119 {
120  return g_splitDynamicType;
121 }
122 
123 template <typename TProcessor, typename TAttribute>
124 inline const std::string&
126 {
127  return TAttribute::getObjectNameStr();
128 }
129 
130 template <typename TProcessor, typename TAttribute>
131 inline const std::string&
133 {
134  return TAttribute::getToolTipStr();
135 }
136 
137 template <typename T>
138 inline boost::shared_ptr<T>
139 defaultDynamicByCreationResultSplitCreationFun(const ipUInt64, const ipUInt64)
140 {
141  return boost::make_shared<T>();
142 }
143 
144 template <typename TProcessor, typename TAttribute>
145 inline void
147 {
148  init(pParameterColl, static_cast<ParameterType (*)(const ipUInt64, const ipUInt64)>(&defaultDynamicByCreationResultSplitCreationFun));
149 }
150 
151 template <typename TProcessor, typename TAttribute>
152 inline void
154  const CreationFunType& pCreationFun)
155 {
156  // check for input shared pointers validity
157  if (pParameterColl.get() == 0)
158  throwNullInputSharedPtr();
159 
160  // call of base class initialization method
161  ElementsLocationInfo elementsLocationInfo;
162  elementsLocationInfo.insertNonLocalized(ElementsRange(0, 1), 0);
163  this->initUnSplitted(elementsLocationInfo);
164 
165  // collection of elements associated to dynamic split
166  _pParameterColl = pParameterColl;
167  _pParameterColl->clear();
168 
169  // store creation function
170  _pCreationFun = pCreationFun;
171 }
172 
173 template <typename TProcessor, typename TAttribute>
174 inline bool
176 {
177  // check for consistency between processor and attribute
179  "This attribute is not part of processor class");
180 
181  return dynamic_cast<const TProcessor*>(&processor) != 0;
182 }
183 
184 template <typename TProcessor, typename TAttribute>
185 inline BoolResult
187  const ipUInt64 elementIdx,
188  const ipUInt64 nbElements,
189  const core::BaseRequestOrigin& requestOrigin)
190 {
191  // cast of input processor object
192  TProcessor& tProcessor = static_cast<TProcessor&>(processor);
193 
194  // creation of a new result element
195  ParameterType pCurResult = _pCreationFun(elementIdx, nbElements);
196 
197  // insertion of element into collection
198  (*_pParameterColl)[ElementsRange(elementIdx, nbElements)] = pCurResult;
199 
200  // update of processor attribute value
201  tProcessor.TProcessor::template set<TAttribute>(pCurResult);
202 
203  return true;
204 }
205 
208 
209 } // end of namespace processor
210 } // end of namespace ipsdk
211 
212 #endif // __IPSDKBASEPROCESSING_DYNAMICBYCREATIONRESULTSPLIT_H__
bool checkProcessorType(const BaseProcessor &processor)
check processor type in derived class
Definition: DynamicByCreationResultSplit.h:175
Class allowing to encapsulate a typed process result associated to a string description.
Definition: ProcessingResult.h:28
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
ipUInt64 insertNonLocalized(const ElementsRange &elementsRange, const ipUInt64 dataMemorySize)
insertion of a new non localized information into collection
eSplitDynamicType getSplitDynamicType() const
retrieve dynamic split operation type
Definition: DynamicByCreationResultSplit.h:118
TProcessor ProcessorType
processor type associated to object
Definition: DynamicByCreationResultSplit.h:43
uint64_t ipUInt64
Base types definition.
Definition: BaseTypes.h:55
const std::string & getAttributeToolTip() const
retrieve attribute tooltip associated to split operation
Definition: DynamicByCreationResultSplit.h:132
boost::shared_ptr< ParameterColl > ParameterCollPtr
shared pointer to collection of elements associated to dynamic split
Definition: DynamicByCreationResultSplit.h:60
eSplitDynamicType
Enumerate describing dynamic split operation type.
Definition: DynamicSplitTypes.h:36
const std::string & getAttributeName() const
retrieve attribute name associated to split operation
Definition: DynamicByCreationResultSplit.h:125
Dynamic split operation type for &#39;by creation&#39; results elements.
Definition: DynamicSplitTypes.h:42
Base class for processor class.
Definition: BaseProcessor.h:43
structure allowing to check whether a given attribute exists in attribute collection information ...
Definition: AttributeCollInfoCheckMacros.h:131
void init(const ParameterCollPtr &pParameterColl)
object initialization method
Definition: DynamicByCreationResultSplit.h:146
TAttribute AttributeType
attribute type associated to object
Definition: DynamicByCreationResultSplit.h:46
Base class for data dynamic split objets used for data dispatch.
Definition: BaseDynamicSplit.h:31
static const eSplitDynamicType::domain g_splitDynamicType
type associated to split operation
Definition: DynamicByCreationResultSplit.h:40
boost::enable_if< typename boost::is_same< typename TAttribute::StorageType, boost::shared_ptr< typename TAttribute::ValueType > >::type, typename TAttribute::StorageType >::type ParameterType
parameter type associated to object
Definition: DynamicByCreationResultSplit.h:54
boost::function< ParameterType(const ipUInt64, const ipUInt64)> CreationFunType
used creation fonction type
Definition: DynamicByCreationResultSplit.h:63
Class allowing to store information about elements range (start offset and number of elements) ...
Definition: ElementsRange.h:27
Template class for results splitted data used for dynamic data dispatch.
Definition: DynamicByCreationResultSplit.h:35
Base class for request origin description.
Definition: BaseRequestOrigin.h:28
CreationFunType _pCreationFun
used creation function
Definition: DynamicByCreationResultSplit.h:110
std::map< ElementsRange, ParameterType > ParameterColl
collection of elements associated to dynamic split indexed by elements range
Definition: DynamicByCreationResultSplit.h:57
Class allowing to store elements location informations.
Definition: ElementsLocationInfo.h:32
TAttribute::ValueType ValueType
parameter value type
Definition: DynamicByCreationResultSplit.h:49
ParameterCollPtr _pParameterColl
collection of elements associated to dynamic split
Definition: DynamicByCreationResultSplit.h:107
BoolResult processAttribute(BaseProcessor &processor, const ipUInt64 elementIdx, const ipUInt64 nbElements, const core::BaseRequestOrigin &requestOrigin)
initialize processor attribute associate to split operation for a given element index ...
Definition: DynamicByCreationResultSplit.h:186