TWeightedFeatureWrap.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 // ACF includes
5 #include <istd/CChangeNotifier.h>
6 #include <iser/CArchiveTag.h>
7 
8 // ACF-Solutions includes
10 
11 
12 namespace iipr
13 {
14 
15 
19 template <class BaseObject>
22  public BaseObject
23 {
24 public:
26  typedef BaseObject BaseClass2;
27 
28  TWeightedFeatureWrap(double weight = 1.0);
29 
30  double GetWeight() const;
31  void SetWeight(double weight);
32 
33  // reimplemented (imeas::INumericValue)
34  virtual bool IsValueTypeSupported(ValueTypeId valueTypeId) const;
35  virtual imath::CVarVector GetComponentValue(ValueTypeId valueTypeId) const;
36 
37  // reimplemented (iser::ISerializable)
38  virtual bool Serialize(iser::IArchive& archive);
39 
40  // reimplemented (istd::IChangeable)
41  virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
42 
43 protected:
44  double m_weight;
45 };
46 
47 
48 // public methods
49 
50 template <class BaseObject>
52  :m_weight(weight)
53 {
54 }
55 
56 
57 template <class BaseObject>
59 {
60  return m_weight;
61 }
62 
63 
64 template <class BaseObject>
66 {
67  m_weight = weight;
68 }
69 
70 
71 // reimplemented (imeas::INumericValue)
72 
73 template <class BaseObject>
75 {
76  return (valueTypeId == VTI_AUTO || valueTypeId == VTI_WEIGHT);
77 }
78 
79 
80 template <class BaseObject>
82 {
83  if (valueTypeId == VTI_AUTO){
84  return m_values;
85  }
86 
87  if (valueTypeId == VTI_WEIGHT){
88  return imath::CVarVector(1, m_weight);
89  }
90 
91  return imath::CVarVector();
92 }
93 
94 
95 // reimplemented (iser::ISerializable)
96 
97 template <class BaseObject>
99 {
100  iser::CArchiveTag weightTag("Weight", "Weight", iser::CArchiveTag::TT_LEAF);
101 
102  istd::CChangeNotifier notifier(archive.IsStoring()? NULL: this);
103  Q_UNUSED(notifier);
104 
105  bool retVal = true;
106 
107  retVal = retVal && BaseClass::Serialize(archive);
108  retVal = retVal && BaseClass2::Serialize(archive);
109 
110  retVal = retVal && archive.BeginTag(weightTag);
111  retVal = retVal && archive.Process(m_weight);
112  retVal = retVal && archive.EndTag(weightTag);
113 
114  return retVal;
115 }
116 
117 
118 // reimplemented (istd::IChangeable)
119 
120 template <class BaseObject>
121 bool TWeightedFeatureWrap<BaseObject>::CopyFrom(const IChangeable& object, CompatibilityMode mode)
122 {
123  const TWeightedFeatureWrap<BaseObject>* objectPtr = dynamic_cast<const TWeightedFeatureWrap<BaseObject>*>(&object);
124  if (objectPtr != NULL){
125  m_weight = objectPtr->GetWeight();
126  }
127 
128  return BaseObject::CopyFrom(object, mode);
129 }
130 
131 
132 } // namespace iipr
133 
134 
imeas::CSimpleNumericValue BaseClass
TWeightedFeatureWrap(double weight=1.0)
virtual bool Serialize(iser::IArchive &archive)
Basic implementation of imeas::INumericValue interface.
#define NULL
virtual bool IsValueTypeSupported(ValueTypeId valueTypeId) const
Check if the given value type (or value component) is supported.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
virtual imath::CVarVector GetComponentValue(ValueTypeId valueTypeId) const
Get access to component value of the given type.
Wrapper allowing to create feature object from some another serializable one.
ValueTypeId
Define standard numeric value types.
Definition: INumericValue.h:26

© 2007-2017 Witold Gantzke and Kirill Lepskiy