IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
DynamicByRangeDataSplit.h
1 // DynamicByRangeDataSplit.h:
3 // --------------------------
4 //
16 
17 #ifndef __IPSDKBASEPROCESSING_DYNAMICBYRANGEDATASPLIT_H__
18 #define __IPSDKBASEPROCESSING_DYNAMICBYRANGEDATASPLIT_H__
19 
20 #include <IPSDKBaseProcessing/DataSplit/Dynamic/BaseDynamicSplit.h>
21 #include <boost/utility/enable_if.hpp>
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/make_shared.hpp>
24 #include <vector>
25 
26 namespace ipsdk {
27 namespace processor {
28 
31 
32 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
34 {
35 // predefined public types
36 public:
38  static const eSplitDynamicType::domain g_splitDynamicType = eSplitDynamicType::eSDT_ByRangeData;
39 
41  typedef TProcessor ProcessorType;
42 
44  typedef TAttribute AttributeType;
45 
47  typedef typename boost::enable_if<typename boost::is_same<boost::mpl::int_<AttributeType::g_attributeType>,
48  boost::mpl::int_<processor::eAttributeType::eAT_DataItem> >::type,
49  typename AttributeType::ValueType>::type DataItemType;
50 
52  typedef typename TAttribute::StorageType StorageType;
53 
55  typedef typename TAttribute::ValueType ValueType;
56 
57 public:
63 
64 // methods
65 public:
68 
70  const std::string& getAttributeName() const;
71 
73  const std::string& getAttributeToolTip() const;
74 
77  void init(const StorageType& pDataItem,
78  const IdxCollMapPtr& pIdxCollMap);
79  void init(const StorageType& pDataItem);
81 
82 
83 protected:
85  bool checkProcessorType(const BaseProcessor& processor);
86 
91  const ipUInt64 elementIdx,
92  const ipUInt64 nbElements,
93  const core::BaseRequestOrigin& requestOrigin);
94 
95 // attributes
96 protected:
99 
102 };
103 
106 
107 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
109 {
110 
111 }
112 
113 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
114 DynamicByRangeDataSplit<TProcessor, TAttribute, CollField, ValueField>::~DynamicByRangeDataSplit()
115 {
116 
117 }
118 
119 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
120 inline eSplitDynamicType
122 {
123  return g_splitDynamicType;
124 }
125 
126 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
127 inline const std::string&
129 {
130  return TAttribute::getObjectNameStr();
131 }
132 
133 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
134 inline const std::string&
136 {
137  return TAttribute::getToolTipStr();
138 }
139 
140 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
141 inline void
143  const IdxCollMapPtr& pIdxCollMap)
144 {
145  // check for input shared pointers validity
146  if (pDataItem.get() == 0 || pIdxCollMap.get() == 0)
147  throwNullInputSharedPtr();
148 
149  // call of base class initialization method
150  ElementsLocationInfo elementsLocationInfo;
151  elementsLocationInfo.insertNonLocalized(ElementsRange(0, 1), 0);
152  this->initUnSplitted(elementsLocationInfo);
153 
154  // data item associated to dynamic split
155  _pDataItem = pDataItem;
156 
157  // default value for newly created elements
158  _pIdxCollMap = pIdxCollMap;
159  _pIdxCollMap->clear();
160 }
161 
162 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
163 inline void
165 {
166  // check for input shared pointers validity
167  if (pDataItem.get() == 0)
168  throwNullInputSharedPtr();
169 
170  // call of base class initialization method
171  ElementsLocationInfo elementsLocationInfo;
172  elementsLocationInfo.insertNonLocalized(ElementsRange(0, 1), 0);
173  this->initUnSplitted(elementsLocationInfo);
174 
175  // data item associated to dynamic split
176  _pDataItem = pDataItem;
177 
178  // default value for newly created elements
179  _pIdxCollMap.reset();
180 }
181 
182 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
183 inline bool
185 {
186  // check for consistency between processor and attribute
188  "This attribute is not part of processor class");
189 
190  return dynamic_cast<const TProcessor*>(&processor) != 0;
191 }
192 
193 template <typename TProcessor, typename TAttribute, typename CollField, typename ValueField>
194 inline BoolResult
196  const ipUInt64 elementIdx,
197  const ipUInt64 nbElements,
198  const core::BaseRequestOrigin& requestOrigin)
199 {
200  // cast of input processor object
201  TProcessor& tProcessor = static_cast<TProcessor&>(processor);
202 
203  // creation of collections of index and of attribute parameters
204  IdxCollPtr pIdxColl(boost::make_shared<IdxColl>());
205  boost::shared_ptr<ValueType> pParamColl(boost::make_shared<ValueType>());
206 
207  // retrieve range end index
208  const ipUInt64 endElementIdx = elementIdx + nbElements;
209 
210  // retrieve collection of data items
211  typedef typename DataItemType::template ChildNodeInfo<CollField>::CollType ParameterPtrCollType;
212  const ParameterPtrCollType& vPrms = _pDataItem->template getNode<CollField>().getColl();
213  const ipUInt64 nbData = static_cast<ipUInt64>(vPrms.size());
214 
215  // parse all data from collection
216  for(ipUInt64 i=0; i<nbData; ++i) {
217 
218  // retrieve current data item
219  typedef typename TAttribute::ValueType::template ChildNodeInfo<CollField>::CollNodePtrType ParameterPtrType;
220  const ParameterPtrType& pCurDataItem = vPrms[i];
221 
222  // retrieve value field for current data
223  const ipUInt64 curValue = static_cast<ipUInt64>(pCurDataItem->template getValue<ValueField>());
224 
225  // check whether value field match requested range
226  if(curValue >= elementIdx && curValue < endElementIdx) {
227 
228  // insertion of index and of parameter into collections
229  if (_pIdxCollMap.get() != 0)
230  pIdxColl->push_back(i);
231  pParamColl->template push_back<CollField>(pCurDataItem);
232  }
233  }
234 
235  // update of index collection associated to range
236  if (_pIdxCollMap.get() != 0)
237  (*_pIdxCollMap)[ElementsRange(elementIdx, nbElements)] = pIdxColl;
238 
239  // update of processor attribute value
240  tProcessor.TProcessor::template set<TAttribute>(pParamColl);
241 
242  return true;
243 }
244 
247 
248 } // end of namespace processor
249 } // end of namespace ipsdk
250 
251 #endif // __IPSDKBASEPROCESSING_DYNAMICRESULTSPLIT_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
TProcessor ProcessorType
processor type associated to object
Definition: DynamicByRangeDataSplit.h:41
ipUInt64 insertNonLocalized(const ElementsRange &elementsRange, const ipUInt64 dataMemorySize)
insertion of a new non localized information into collection
void init(const StorageType &pDataItem, const IdxCollMapPtr &pIdxCollMap)
object initialization method
Definition: DynamicByRangeDataSplit.h:142
uint64_t ipUInt64
Base types definition.
Definition: BaseTypes.h:55
eSplitDynamicType
Enumerate describing dynamic split operation type.
Definition: DynamicSplitTypes.h:36
TAttribute::ValueType ValueType
parameter type associated to object
Definition: DynamicByRangeDataSplit.h:55
eSplitDynamicType getSplitDynamicType() const
retrieve dynamic split operation type
Definition: DynamicByRangeDataSplit.h:121
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: DynamicByRangeDataSplit.h:195
static const eSplitDynamicType::domain g_splitDynamicType
type associated to split operation
Definition: DynamicByRangeDataSplit.h:38
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
Dynamic split operation type for valued data with value used to match elements range.
Definition: DynamicSplitTypes.h:44
Base class for data dynamic split objets used for data dispatch.
Definition: BaseDynamicSplit.h:31
bool checkProcessorType(const BaseProcessor &processor)
check processor type in derived class
Definition: DynamicByRangeDataSplit.h:184
boost::shared_ptr< IdxCollMap > IdxCollMapPtr
shared pointer to collections of indices
Definition: DynamicSplitTypes.h:66
boost::shared_ptr< IdxColl > IdxCollPtr
shared pointer to collection of indices
Definition: DynamicSplitTypes.h:59
const std::string & getAttributeName() const
retrieve attribute name associated to split operation
Definition: DynamicByRangeDataSplit.h:128
TAttribute AttributeType
attribute type associated to object
Definition: DynamicByRangeDataSplit.h:44
Class allowing to store information about elements range (start offset and number of elements) ...
Definition: ElementsRange.h:27
Base class for request origin description.
Definition: BaseRequestOrigin.h:28
IdxCollMapPtr _pIdxCollMap
collection of elements index associated to each splits
Definition: DynamicByRangeDataSplit.h:101
const std::string & getAttributeToolTip() const
retrieve attribute tooltip associated to split operation
Definition: DynamicByRangeDataSplit.h:135
boost::enable_if< typename boost::is_same< boost::mpl::int_< AttributeType::g_attributeType >, boost::mpl::int_< processor::eAttributeType::eAT_DataItem > >::type, typename AttributeType::ValueType >::type DataItemType
retrieve DataItem node type associated to attribute
Definition: DynamicByRangeDataSplit.h:49
StorageType _pDataItem
collection of elements associated to dynamic split
Definition: DynamicByRangeDataSplit.h:98
TAttribute::StorageType StorageType
parameter storage type associated to object
Definition: DynamicByRangeDataSplit.h:52
Class allowing to store elements location informations.
Definition: ElementsLocationInfo.h:32
Template class for split range data used for dynamic data dispatch.
Definition: DynamicByRangeDataSplit.h:33