-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex_model_element_base.cpp
144 lines (113 loc) · 3.38 KB
/
complex_model_element_base.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/extended_type_info.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "complex_model_element_base.h"
#include <glibmm/i18n.h>
#include <boost/serialization/export.hpp>
BOOST_CLASS_EXPORT(cppgef::ComplexModelElementBase)
template
void cppgef::ComplexModelElementBase::serialize(
boost::archive::text_oarchive &ar,
const unsigned int /* file_version */
);
template
void cppgef::ComplexModelElementBase::serialize(
boost::archive::text_iarchive &ar,
const unsigned int /* file_version */
);
template
void cppgef::ComplexModelElementBase::serialize(
boost::archive::xml_oarchive &ar,
const unsigned int /* file_version */
);
template
void cppgef::ComplexModelElementBase::serialize(
boost::archive::xml_iarchive &ar,
const unsigned int /* file_version */
);
namespace cppgef
{
ComplexModelElementBase::ComplexModelElementBase()
{
}
ComplexModelElementBase::~ComplexModelElementBase()
{
}
void ComplexModelElementBase::addChild(shared_ptr< ModelElementBase > element)
{
children_.push_back (element);
signal_child_added_.emit (element);
}
void ComplexModelElementBase::insertChild(shared_ptr< ModelElementBase > element, size_t pos)
{
if (pos >= children_.size())
children_.push_back (element);
else
children_.insert (children_.begin() + pos, element);
signal_child_added_.emit (element);
}
void ComplexModelElementBase::eraseChild(shared_ptr< ModelElementBase > element)
{
// TODO: use an unordered_map for fast seek?
iterator child_itor = std::find (children_.begin(), children_.end(), element);
if (child_itor != children_.end())
{
children_.erase (child_itor);
signal_child_erased_.emit (element);
}
else
{
throw Error(
Glib::ustring(_("Can not erase element that is not added to the ComplexModelElementBase.")));
}
}
int ComplexModelElementBase::getChildIndex(shared_ptr< ModelElementBase > element)
{
for (size_t i = 0; i < children_.size(); i++)
{
if (children_[i] == element)
return i;
}
return -1;
}
ComplexModelElementBase::iterator ComplexModelElementBase::getChildrenBegin()
{
return children_.begin();
}
ComplexModelElementBase::const_iterator ComplexModelElementBase::getChildrenBegin() const
{
return children_.begin();
}
ComplexModelElementBase::iterator ComplexModelElementBase::getChildrenEnd()
{
return children_.end();
}
ComplexModelElementBase::const_iterator ComplexModelElementBase::getChildrenEnd() const
{
return children_.end();
}
ComplexModelElementBase::size_t ComplexModelElementBase::getChildrenSize() const
{
return children_.size();
}
ComplexModelElementBase::signal_children_property_changed_t ComplexModelElementBase::signalChildAdded()
{
return signal_child_added_;
}
ComplexModelElementBase::signal_children_property_changed_t ComplexModelElementBase::signalChildErased()
{
return signal_child_erased_;
}
template< class Archive >
void ComplexModelElementBase::serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ModelElementBase);
ar & BOOST_SERIALIZATION_NVP(children_);
}
}