ICF 3.1.1.10
Technical documentation of ICF Libraries
TWeightedFeatureWrap.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// ICF includes
11#include <iser/CArchiveTag.h>
13
14
15namespace iipr
16{
17
18
22template <class BaseObject>
25 public BaseObject
26{
27public:
29 typedef BaseObject BaseClass2;
30
31 TWeightedFeatureWrap(double weight = 1.0);
32
33 double GetWeight() const;
34 void SetWeight(double weight);
35
36 // reimplemented (imeas::INumericValue)
37 bool IsValueTypeSupported(ValueTypeId valueTypeId, bool editableOnly = false) const override;
38 double GetComponentValue(ValueTypeId valueTypeId) const override;
39 bool SetComponentValue(ValueTypeId valueTypeId, double value) override;
40
41 // reimplemented (iser::ISerializable)
42 bool Serialize(iser::IArchive& archive) override;
43
44 // reimplemented (istd::IChangeable)
45 bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
46 std::unique_ptr<istd::IChangeable> CloneMe(CompatibilityMode mode = CM_WITHOUT_REFS) const override;
48
49protected:
50 double m_weight;
51};
52
53
54// public methods
55
56template <class BaseObject>
58 :m_weight(weight)
59{
60}
61
62
63template <class BaseObject>
65{
66 return m_weight;
67}
68
69
70template <class BaseObject>
72{
73 m_weight = weight;
74}
75
76
77// reimplemented (imeas::INumericValue)
78
79template <class BaseObject>
81{
82 return (valueTypeId == VTI_WEIGHT) || BaseClass::IsValueTypeSupported(valueTypeId, editableOnly);
83}
84
85
86template <class BaseObject>
88{
89 if (valueTypeId == VTI_WEIGHT) {
90 return m_weight;
91 }
92
93 return BaseClass::GetComponentValue(valueTypeId);
94}
95
96
97template <class BaseObject>
99{
100 if (valueTypeId == VTI_WEIGHT) {
101 m_weight = value;
102 return true;
103 }
104
105 return BaseClass::SetComponentValue(valueTypeId, value);
106}
107
108
109// reimplemented (iser::ISerializable)
110
111template <class BaseObject>
113{
114 iser::CArchiveTag weightTag("Weight", "Weight", iser::CArchiveTag::Type::Leaf);
115
116 istd::CChangeNotifier notifier(archive.IsChanging()? this: nullptr);
117
118 return BaseClass::Serialize(archive) &&
119 BaseClass2::Serialize(archive) &&
120 archive.ProcessLeaf(weightTag, m_weight);
121}
122
123
124// reimplemented (istd::IChangeable)
125
126template <class BaseObject>
128{
129 const TWeightedFeatureWrap<BaseObject>* objectPtr = dynamic_cast<const TWeightedFeatureWrap<BaseObject>*>(&object);
130 if (objectPtr != nullptr) {
131 m_weight = objectPtr->GetWeight();
132 }
133
134 return BaseObject::CopyFrom(object, mode);
135}
136
137
138template <class BaseObject>
139std::unique_ptr<istd::IChangeable> TWeightedFeatureWrap<BaseObject>::CloneMe(CompatibilityMode mode) const
140{
141 std::unique_ptr<istd::IChangeable> clonePtr{new TWeightedFeatureWrap<BaseObject>()};
142
143 if (clonePtr->CopyFrom(*this, mode)) {
144 return clonePtr;
145 }
146
147 return nullptr;
148}
149
150
151template <class BaseObject>
153{
154 istd::CChangeNotifier notifier(this);
155
156 BaseClass::ResetData(mode);
157
158 m_weight = 0;
159
160 return true;
161}
162
163
164} // namespace iipr
165
166
Wrapper allowing to create feature object from some another serializable one.
bool IsValueTypeSupported(ValueTypeId valueTypeId, bool editableOnly=false) const override
bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
std::unique_ptr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
TWeightedFeatureWrap(double weight=1.0)
bool SetComponentValue(ValueTypeId valueTypeId, double value) override
bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS) override
Reset data to its default state.
imeas::CGeneralNumericValue BaseClass
double GetComponentValue(ValueTypeId valueTypeId) const override
INumericConstraints::ValueTypeId ValueTypeId
Process tag used to group data in archive stream.
Definition CArchiveTag.h:25
@ Leaf
Leaf tag, it can contain only one primitive element.
Represent input/output persistence archive.
Definition IArchive.h:34
virtual bool ProcessLeaf(const CArchiveTag &tag, bool &value)=0
Process primitive type.
virtual bool IsChanging() const =0
Check if this archive processing change the object state.
Help class which provides the automatic update mechanism of the model.
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
Contains the image processing classes.

© Witold Gantzke and Kirill Lepskiy