TDataNodePolyline.h
Go to the documentation of this file.
1 #ifndef i2d_TDataNodePolyline_included
2 #define i2d_TDataNodePolyline_included
3 
4 
5 // STL includes
6 #include <vector>
7 
8 // ACF includes
10 #include <istd/CChangeNotifier.h>
11 
12 
13 namespace i2d
14 {
15 
16 
21 template<class NodeData>
23 {
24 public:
26 
30  const NodeData& GetTNodeData(int nodeIndex) const;
31 
35  NodeData& GetTNodeDataRef(int nodeIndex);
36 
37  // reimplemented (i2d::CDataNodePolylineBase)
38  virtual const iser::ISerializable& GetNodeData(int nodeIndex) const;
39  virtual iser::ISerializable& GetNodeDataRef(int nodeIndex);
40 
41  // reimplemented (i2d::CPolypoint)
42  virtual void Clear();
43  virtual void SetNodesCount(int nodesCount);
44  virtual bool InsertNode(const i2d::CVector2d& position);
45  virtual bool InsertNode(int index, const i2d::CVector2d& position);
46  virtual bool RemoveNode(int index);
47 
48  // reimplemented istd::IChangeable
49  virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
50 
51 private:
52  typedef std::vector<NodeData> NodesData;
53  NodesData m_nodesData;
54 };
55 
56 
57 template<class NodeData>
58 inline const NodeData& TDataNodePolyline<NodeData>::GetTNodeData(int nodeIndex) const
59 {
60  Q_ASSERT(nodeIndex >= 0);
61  Q_ASSERT(nodeIndex < int(m_nodesData.size()));
62 
63  return m_nodesData[nodeIndex];
64 }
65 
66 
67 template<class NodeData>
68 inline NodeData& TDataNodePolyline<NodeData>::GetTNodeDataRef(int nodeIndex)
69 {
70  Q_ASSERT(nodeIndex >= 0);
71  Q_ASSERT(nodeIndex < int(m_nodesData.size()));
72 
73  return m_nodesData[nodeIndex];
74 }
75 
76 
77 // reimplemented (i2d::CDataNodePolylineBase)
78 
79 template<class NodeData>
81 {
82  Q_ASSERT(nodeIndex >= 0);
83  Q_ASSERT(nodeIndex < int(m_nodesData.size()));
84 
85  return m_nodesData[nodeIndex];
86 }
87 
88 
89 template<class NodeData>
91 {
92  Q_ASSERT(nodeIndex >= 0);
93  Q_ASSERT(nodeIndex < int(m_nodesData.size()));
94 
95  return m_nodesData[nodeIndex];
96 }
97 
98 
99 // reimplemented (i2d::CPolypoint)
100 
101 template<class NodeData>
103 {
104  if (!m_nodesData.empty()){
105  istd::CChangeNotifier changeNotifier(this, &s_clearAllNodesChange);
106  Q_UNUSED(changeNotifier);
107 
108  m_nodesData.clear();
109 
110  BaseClass::Clear();
111  }
112 }
113 
114 
115 template<class NodeData>
117 {
118  istd::CChangeNotifier changeNotifier(this, &s_createPolygonNodesChange);
119  Q_UNUSED(changeNotifier);
120 
121  m_nodesData.resize(nodesCount);
122 
123  BaseClass::SetNodesCount(nodesCount);
124 }
125 
126 
127 template<class NodeData>
129 {
130  istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
131  Q_UNUSED(changeNotifier);
132 
133  m_nodesData.insert(m_nodesData.end(), NodeData());
134 
135  return BaseClass::InsertNode(position);
136 }
137 
138 
139 template<class NodeData>
140 inline bool TDataNodePolyline<NodeData>::InsertNode(int index, const i2d::CVector2d& position)
141 {
142  istd::CChangeNotifier changeNotifier(this, &s_insertPolygonNodeChange);
143  Q_UNUSED(changeNotifier);
144 
145  typename NodesData::iterator iter = m_nodesData.begin();
146  iter += index;
147  m_nodesData.insert(iter, NodeData());
148 
149  return BaseClass::InsertNode(index, position);
150 }
151 
152 
153 template<class NodeData>
155 {
156  istd::CChangeNotifier changeNotifier(this, &s_removePolygonNodeChange);
157  Q_UNUSED(changeNotifier);
158 
159  typename NodesData::iterator iter = m_nodesData.begin();
160  iter += index;
161  m_nodesData.erase(iter);
162 
163  return BaseClass::RemoveNode(index);
164 }
165 
166 
167 // reimplemented istd::IChangeable
168 
169 template<class NodeData>
170 bool TDataNodePolyline<NodeData>::CopyFrom(const IChangeable& object, CompatibilityMode mode)
171 {
172  Clear();
173 
174  const TDataNodePolyline<NodeData>* polygonPtr = dynamic_cast<const TDataNodePolyline<NodeData>*>(&object);
175 
176  if (polygonPtr != NULL){
177  istd::CChangeNotifier changeNotifier(this);
178 
179  int sourceNodesCount = polygonPtr->GetNodesCount();
180  for (int nodesIndex = 0; nodesIndex < sourceNodesCount; nodesIndex++){
181  InsertNode(polygonPtr->GetNodePos(nodesIndex));
182 
183  m_nodesData[nodesIndex] = polygonPtr->m_nodesData[nodesIndex];
184  }
185 
186  CObject2dBase::CopyFrom(object, mode);
187 
188  return true;
189  }
190 
191  return false;
192 }
193 
194 
195 } // namespace i2d
196 
197 
198 #endif // !i2d_TDataNodePolyline_included
199 
200 
External references are simple ignored.
Definition: IChangeable.h:197
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition: IChangeable.h:186
virtual void Clear()
Removes all nodes.
Base class for polylines with additional data stored in each node.
NodeData & GetTNodeDataRef(int nodeIndex)
Get reference of user data in the given node.
Generic polyline implementation with additional information stored for each node. ...
Common class for all classes which objects can be archived or restored from archive.
Definition: ISerializable.h:23
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
const NodeData & GetTNodeData(int nodeIndex) const
Get user data from the given node.
virtual bool InsertNode(const i2d::CVector2d &position)
Insert a node at the end of node table.
virtual const i2d::CVector2d & GetNodePos(int index) const
Return position of node at specified index.
Definition: CPolypoint.h:149
virtual bool RemoveNode(int index)
Remove a node at specified index.
virtual iser::ISerializable & GetNodeDataRef(int nodeIndex)
This is an overloaded member function, provided for convenience. It differs from the above function o...
CDataNodePolylineBase BaseClass
virtual const iser::ISerializable & GetNodeData(int nodeIndex) const
Get user data from the given node.
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
Help class which provides the automatic update mechanism of the model.
virtual void SetNodesCount(int nodesCount)
Set new nodes count.
#define NULL
Definition: istd.h:64
virtual int GetNodesCount() const
Return size of node table.
Definition: CPolypoint.h:143
virtual bool CopyFrom(const istd::IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
Copy this object from another one.

© 2007-2017 Witold Gantzke and Kirill Lepskiy