IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
DynamicByCopyResultSplit.h
1 // DynamicByCopyResultSplit.h:
3 // ---------------------------
4 //
15 
16 #ifndef __IPSDKBASEPROCESSING_DYNAMICBYCOPYRESULTSPLIT_H__
17 #define __IPSDKBASEPROCESSING_DYNAMICBYCOPYRESULTSPLIT_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 ValueType&)> CopyFunType;
64 
65 public:
71 
72 // methods
73 public:
76 
78  const std::string& getAttributeName() const;
79 
81  const std::string& getAttributeToolTip() const;
82 
89  void init(const ParameterCollPtr& pParameterColl,
90  const ParameterType& pDefaultValue);
91  void init(const ParameterCollPtr& pParameterColl,
92  const ParameterType& pDefaultValue,
93  const CopyFunType& pCopyFunction);
95 
96 protected:
98  bool checkProcessorType(const BaseProcessor& processor);
99 
103  BoolResult processAttribute(BaseProcessor& processor,
104  const ipUInt64 elementIdx,
105  const ipUInt64 nbElements,
106  const core::BaseRequestOrigin& requestOrigin);
107 
108 // attributes
109 protected:
112 
115 
118 };
119 
122 
123 template <typename TProcessor, typename TAttribute>
124 inline eSplitDynamicType
126 {
127  return g_splitDynamicType;
128 }
129 
130 template <typename TProcessor, typename TAttribute>
131 inline const std::string&
133 {
134  return TAttribute::getObjectNameStr();
135 }
136 
137 template <typename TProcessor, typename TAttribute>
138 inline const std::string&
140 {
141  return TAttribute::getToolTipStr();
142 }
143 
144 template <typename TProcessor, typename TAttribute>
145 inline void
147  const ParameterType& pDefaultValue)
148 {
149  init(pParameterColl, pDefaultValue, static_cast<ParameterType (*)(const ValueType&)>(&boost::make_shared<ValueType>));
150 }
151 
152 template <typename TProcessor, typename TAttribute>
153 inline void
155  const ParameterType& pDefaultValue,
156  const CopyFunType& pCopyFunction)
157 {
158  // check for input shared pointers validity
159  if (pParameterColl.get() == 0)
160  throwNullInputSharedPtr();
161  if (pDefaultValue.get() == 0)
162  throwNullInputSharedPtr();
163 
164  // call of base class initialization method
165  ElementsLocationInfo elementsLocationInfo;
166  elementsLocationInfo.insertNonLocalized(ElementsRange(0, 1), 0);
167  this->initUnSplitted(elementsLocationInfo);
168 
169  // collection of elements associated to dynamic split
170  _pParameterColl = pParameterColl;
171  _pParameterColl->clear();
172 
173  // default value for newly created elements
174  _pDefaultValue = pDefaultValue;
175 
176  // store copy function
177  _pCopyFunction = pCopyFunction;
178 }
179 
180 template <typename TProcessor, typename TAttribute>
181 inline bool
183 {
184  // check for consistency between processor and attribute
186  "This attribute is not part of processor class");
187 
188  return dynamic_cast<const TProcessor*>(&processor) != 0;
189 }
190 
191 template <typename TProcessor, typename TAttribute>
192 inline BoolResult
194  const ipUInt64 elementIdx,
195  const ipUInt64 nbElements,
196  const core::BaseRequestOrigin& requestOrigin)
197 {
198  // cast of input processor object
199  TProcessor& tProcessor = static_cast<TProcessor&>(processor);
200 
201  // creation of a new result element
202  ParameterType pCurResult = _pCopyFunction(*_pDefaultValue);
203 
204  // insertion of element into collection
205  (*_pParameterColl)[ElementsRange(elementIdx, nbElements)] = pCurResult;
206 
207  // update of processor attribute value
208  tProcessor.TProcessor::template set<TAttribute>(pCurResult);
209 
210  return true;
211 }
212 
215 
216 } // end of namespace processor
217 } // end of namespace ipsdk
218 
219 #endif // __IPSDKBASEPROCESSING_DYNAMICBYCOPYRESULTSPLIT_H__
boost::function< ParameterType(const ValueType &)> CopyFunType
used copy fonction type
Definition: DynamicByCopyResultSplit.h:63
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
const std::string & getAttributeToolTip() const
retrieve attribute tooltip associated to split operation
Definition: DynamicByCopyResultSplit.h:139
std::map< ElementsRange, ParameterType > ParameterColl
collection of elements associated to dynamic split indexed by elements range
Definition: DynamicByCopyResultSplit.h:57
bool checkProcessorType(const BaseProcessor &processor)
check processor type in derived class
Definition: DynamicByCopyResultSplit.h:182
CopyFunType _pCopyFunction
used copy function
Definition: DynamicByCopyResultSplit.h:117
ipUInt64 insertNonLocalized(const ElementsRange &elementsRange, const ipUInt64 dataMemorySize)
insertion of a new non localized information into collection
uint64_t ipUInt64
Base types definition.
Definition: BaseTypes.h:55
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: DynamicByCopyResultSplit.h:54
eSplitDynamicType
Enumerate describing dynamic split operation type.
Definition: DynamicSplitTypes.h:36
const std::string & getAttributeName() const
retrieve attribute name associated to split operation
Definition: DynamicByCopyResultSplit.h:132
static const eSplitDynamicType::domain g_splitDynamicType
type associated to split operation
Definition: DynamicByCopyResultSplit.h:40
Dynamic split operation type for &#39;by creation&#39; results elements.
Definition: DynamicSplitTypes.h:42
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: DynamicByCopyResultSplit.h:193
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
boost::shared_ptr< ParameterColl > ParameterCollPtr
shared pointer to collection of elements associated to dynamic split
Definition: DynamicByCopyResultSplit.h:60
Base class for data dynamic split objets used for data dispatch.
Definition: BaseDynamicSplit.h:31
TAttribute::ValueType ValueType
parameter value type
Definition: DynamicByCopyResultSplit.h:49
ParameterType _pDefaultValue
default value for split operation
Definition: DynamicByCopyResultSplit.h:114
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
void init(const ParameterCollPtr &pParameterColl, const ParameterType &pDefaultValue)
object initialization method
Definition: DynamicByCopyResultSplit.h:146
eSplitDynamicType getSplitDynamicType() const
retrieve dynamic split operation type
Definition: DynamicByCopyResultSplit.h:125
TProcessor ProcessorType
processor type associated to object
Definition: DynamicByCopyResultSplit.h:43
TAttribute AttributeType
attribute type associated to object
Definition: DynamicByCopyResultSplit.h:46
Template class for results splitted data used for dynamic data dispatch.
Definition: DynamicByCopyResultSplit.h:35
ParameterCollPtr _pParameterColl
collection of elements associated to dynamic split
Definition: DynamicByCopyResultSplit.h:111
Class allowing to store elements location informations.
Definition: ElementsLocationInfo.h:32