Choreonoid  1.8
ValueTreeUtil.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_VALUE_TREE_UTIL_H
6 #define CNOID_UTIL_VALUE_TREE_UTIL_H
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  const Listing& listing = *mapping.findListing(key);
33  if(listing.isValid()){
34  for(int i=0; i < listing.size(); ++i){
35  elements.push_back(listing[i].to<typename Container::value_type>());
36  }
37  }
38  return !elements.empty();
39 }
40 
41 }
42 
43 #endif
cnoid::ValueNode::isValid
bool isValid() const
Definition: ValueTree.h:54
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::writeElements
bool writeElements(Mapping &mapping, const std::string &key, const Container &elements, bool isFlowStyle=false)
Definition: ValueTreeUtil.h:13
cnoid::Listing::empty
bool empty() const
Definition: ValueTree.h:501
ValueTree.h
cnoid::ref_ptr< Listing >
cnoid::Listing::size
int size() const
Definition: ValueTree.h:502
cnoid::Listing
Definition: ValueTree.h:486
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Mapping::findListing
Listing * findListing(const std::string &key) const
Definition: ValueTree.cpp:578
cnoid::Listing::append
void append(ValueNode *node)
Definition: ValueTree.h:551
cnoid::readElements
bool readElements(const Mapping &mapping, const std::string &key, Container &elements)
Definition: ValueTreeUtil.h:30
cnoid::Listing::setFlowStyle
void setFlowStyle(bool isFlowStyle=true)
Definition: ValueTree.h:506
cnoid::Mapping::insert
void insert(const std::string &key, ValueNode *node)
Definition: ValueTree.cpp:701