21 static Value mkCopy(EP value) {
return (Value(value,
false)); }
24 static Value mkShare(EP value) {
return (Value(value,
true)); }
28 EP get()
const {
return (value_); }
32 bool isShared()
const {
return (shared_); }
38 Value(EP value,
bool shared) : value_(value), shared_(shared) { }
54 Value<EP> moveComments1(EP element) {
55 bool modified =
false;
60 typedef std::vector<ElementPtr> ListType;
61 const ListType& list = element->listValue();
62 for (ListType::const_iterator it = list.cbegin();
63 it != list.cend(); ++it) {
64 Value<ElementPtr> item = moveComments1(*it);
65 result->add(item.get());
66 if (!item.isShared()) {
71 return (Value<EP>::mkShare(element));
73 return (Value<EP>::mkCopy(result));
76 return (Value<EP>::mkShare(element));
81 bool has_comment =
false;
82 typedef std::map<std::string, ConstElementPtr> map_type;
83 const map_type& map = element->mapValue();
84 for (map_type::const_iterator it = map.cbegin(); it != map.cend(); ++it) {
85 if (it->first ==
"comment") {
88 }
else if (it->first ==
"user-context") {
90 result->set(
"user-context", it->second);
93 Value<ConstElementPtr> item = moveComments1(it->second);
94 result->set(it->first, item.get());
95 if (!item.isShared()) {
101 if (!has_comment && !modified) {
102 return (Value<EP>::mkShare(element));
109 moved->set(
"comment", comment);
113 merge(moved, previous);
115 result->set(
"user-context", moved);
118 return (Value<EP>::mkCopy(result));
127 Value<ElementPtr> result = moveComments1(element);
128 return (result.get());
132 Value<ConstElementPtr> result = moveComments1(element);
133 return (result.get());
150 template<
typename EP>
151 Value<EP> extractComments1(EP element) {
152 bool modified =
false;
157 typedef std::vector<ElementPtr> ListType;
158 const ListType& list = element->listValue();
159 for (ListType::const_iterator it = list.cbegin();
160 it != list.cend(); ++it) {
161 Value<ElementPtr> item = extractComments1(*it);
162 result->add(item.get());
163 if (!item.isShared()) {
168 return (Value<EP>::mkShare(element));
170 return (Value<EP>::mkCopy(result));
173 return (Value<EP>::mkShare(element));
178 bool has_comment =
false;
179 typedef std::map<std::string, ConstElementPtr> map_type;
180 const map_type& map = element->mapValue();
181 for (map_type::const_iterator it = map.cbegin(); it != map.cend(); ++it) {
182 if (it->first ==
"comment") {
184 result->set(
"comment", it->second);
185 }
else if (it->first ==
"user-context") {
186 if (it->second->contains(
"comment")) {
191 result->set(
"user-context", it->second);
195 Value<ConstElementPtr> item = extractComments1(it->second);
196 result->set(it->first, item.get());
197 if (!item.isShared()) {
203 if (!has_comment && !modified) {
204 return (Value<EP>::mkShare(element));
209 const map_type& uc_map = element->get(
"user-context")->mapValue();
212 for (map_type::const_iterator it = uc_map.cbegin();
213 it != uc_map.cend(); ++it) {
214 if (it->first ==
"comment") {
215 comment = it->second;
217 user_context->set(it->first, it->second);
220 if (user_context->size() > 0) {
221 result->set(
"user-context", user_context);
223 result->set(
"comment", comment);
226 return (Value<EP>::mkCopy(result));
235 Value<ElementPtr> result = extractComments1(element);
236 return (result.get());
240 Value<ConstElementPtr> result = extractComments1(element);
241 return (result.get());