Choreonoid  1.5
ValueTreeUtil.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_VALUE_TREE_UTIL_H_INCLUDED
6 #define CNOID_UTIL_VALUE_TREE_UTIL_H_INCLUDED
7 
8 #include "ValueTree.h"
9 
10 namespace cnoid {
11 
12 template<class Container>
13 bool writeElements(Mapping& mapping, const std::string& key, const Container& elements, bool isFlowStyle = false)
14 {
15  ListingPtr listing = new Listing();
16  if(isFlowStyle){
17  listing->setFlowStyle(true);
18  }
19  for(typename Container::const_iterator p = elements.begin(); p != elements.end(); ++p){
20  listing->append(*p);
21  }
22  if(!listing->empty()){
23  mapping.insert(key, listing);
24  return true;
25  }
26  return false;
27 }
28 
29 template<class Container>
30 bool readElements(const Mapping& mapping, const std::string& key, Container& elements)
31 {
32  bool completed = false;
33  const Listing& listing = *mapping.findListing(key);
34  if(listing.isValid()){
35  for(int i=0; i < listing.size(); ++i){
36  elements.push_back(listing[i].to<typename Container::value_type>());
37  }
38  }
39  return !elements.empty();
40 }
41 }
42 
43 #endif
bool isValid() const
Definition: ValueTree.h:51
void insert(const std::string &key, ValueNode *node)
Definition: ValueTree.cpp:612
Definition: ValueTree.h:224
void append(ValueNode *node)
Definition: ValueTree.h:484
Listing * findListing(const std::string &key) const
Definition: ValueTree.cpp:545
void setFlowStyle(bool isFlowStyle=true)
Definition: ValueTree.h:444
int size() const
Definition: ValueTree.h:440
Definition: ValueTree.h:424
bool writeElements(Mapping &mapping, const std::string &key, const Container &elements, bool isFlowStyle=false)
Definition: ValueTreeUtil.h:13
bool empty() const
Definition: ValueTree.h:439
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
bool readElements(const Mapping &mapping, const std::string &key, Container &elements)
Definition: ValueTreeUtil.h:30