Changeset 38:966d0fb94b1b in rrlib_xml


Ignore:
Timestamp:
12.01.2012 15:10:28 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Renamed a few methods

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tXMLDocument.cpp

    r37 r38  
    132132 
    133133//---------------------------------------------------------------------- 
    134 // tXMLDocument GetRootNode 
     134// tXMLDocument RootNode 
    135135//---------------------------------------------------------------------- 
    136 tXMLNode &tXMLDocument::GetRootNode() 
     136tXMLNode &tXMLDocument::RootNode() 
    137137{ 
    138138  if (!this->root_node) 
  • tXMLDocument.h

    r36 r38  
    145145   * \returns A reference to the root node 
    146146   */ 
    147   tXMLNode &GetRootNode(); 
     147  tXMLNode &RootNode(); 
    148148 
    149   inline const tXMLNode &GetRootNode() const 
     149  inline const tXMLNode &RootNode() const 
    150150  { 
    151     return const_cast<tXMLDocument *>(this)->GetRootNode(); 
     151    return const_cast<tXMLDocument *>(this)->RootNode(); 
    152152  } 
    153153 
  • tXMLNode.cpp

    r35 r38  
    8787 
    8888//---------------------------------------------------------------------- 
    89 // tXMLNode GetName 
    90 //---------------------------------------------------------------------- 
    91 const std::string tXMLNode::GetName() const 
     89// tXMLNode Name 
     90//---------------------------------------------------------------------- 
     91const std::string tXMLNode::Name() const 
    9292{ 
    9393  return reinterpret_cast<const char *>(this->name); 
     
    9595 
    9696//---------------------------------------------------------------------- 
    97 // tXMLNode GetChildrenEnd 
    98 //---------------------------------------------------------------------- 
    99 const tXMLNode::iterator &tXMLNode::GetChildrenEnd() 
     97// tXMLNode ChildrenEnd 
     98//---------------------------------------------------------------------- 
     99const tXMLNode::iterator &tXMLNode::ChildrenEnd() 
    100100{ 
    101101  static iterator end; 
     
    103103} 
    104104 
    105 const tXMLNode::const_iterator &tXMLNode::GetChildrenEnd() const 
     105const tXMLNode::const_iterator &tXMLNode::ChildrenEnd() const 
    106106{ 
    107107  static const_iterator end; 
     
    110110 
    111111//---------------------------------------------------------------------- 
    112 // tXMLNode GetFirstChild 
    113 //---------------------------------------------------------------------- 
    114 tXMLNode &tXMLNode::GetFirstChild() 
     112// tXMLNode FirstChild 
     113//---------------------------------------------------------------------- 
     114tXMLNode &tXMLNode::FirstChild() 
    115115{ 
    116116  if (!this->HasChildren()) 
     
    118118    throw tXML2WrapperException("Node has no children!"); 
    119119  } 
    120   return *this->GetChildrenBegin(); 
     120  return *this->ChildrenBegin(); 
    121121} 
    122122 
     
    155155void tXMLNode::RemoveChildNode(tXMLNode &node) 
    156156{ 
    157   iterator it = std::find(this->GetChildrenBegin(), this->GetChildrenEnd(), node); 
    158   if (it == this->GetChildrenEnd()) 
     157  iterator it = std::find(this->ChildrenBegin(), this->ChildrenEnd(), node); 
     158  if (it == this->ChildrenEnd()) 
    159159  { 
    160160    throw tXML2WrapperException("Given node is not a child of this!"); 
     
    164164 
    165165//---------------------------------------------------------------------- 
    166 // tXMLNode GetNextSiblingsEnd 
    167 //---------------------------------------------------------------------- 
    168 const tXMLNode::iterator &tXMLNode::GetNextSiblingsEnd() 
     166// tXMLNode NextSiblingsEnd 
     167//---------------------------------------------------------------------- 
     168const tXMLNode::iterator &tXMLNode::NextSiblingsEnd() 
    169169{ 
    170170  static iterator end; 
     
    172172} 
    173173 
    174 const tXMLNode::const_iterator &tXMLNode::GetNextSiblingsEnd() const 
     174const tXMLNode::const_iterator &tXMLNode::NextSiblingsEnd() const 
    175175{ 
    176176  static const_iterator end; 
     
    179179 
    180180//---------------------------------------------------------------------- 
    181 // tXMLNode GetNextSibling 
    182 //---------------------------------------------------------------------- 
    183 tXMLNode &tXMLNode::GetNextSibling() 
     181// tXMLNode NextSibling 
     182//---------------------------------------------------------------------- 
     183tXMLNode &tXMLNode::NextSibling() 
    184184{ 
    185185  if (!this->HasNextSibling()) 
     
    187187    throw tXML2WrapperException("Node has no sibling!"); 
    188188  } 
    189   return *this->GetNextSiblingsBegin(); 
     189  return *this->NextSiblingsBegin(); 
    190190} 
    191191 
  • tXMLNode.h

    r34 r38  
    241241  } 
    242242 
    243   /*! Comparison of name with given string (equality) 
    244    * 
    245    * This method can be used to find a specific node using e.g. std::find 
    246    * 
    247    * \param name   The name to be compared to the node's name 
    248    * 
    249    * \returns Whether this has the given name or not 
    250    */ 
    251   inline bool operator == (const std::string &name) const 
    252   { 
    253     return this->GetName() == name; 
    254   } 
    255  
    256243  /*! Check if this node is part of the subtree of the given node 
    257244   * 
     
    272259   * \returns A reference to the node's name 
    273260   */ 
    274   const std::string GetName() const; 
     261  const std::string Name() const; 
    275262 
    276263  /*! Get an iterator to the first of this node's children of type XML_ELEMENT_NODE 
     
    278265   * \returns A begin-iterator 
    279266   */ 
    280   inline const iterator GetChildrenBegin() 
     267  inline const iterator ChildrenBegin() 
    281268  { 
    282269    return iterator(reinterpret_cast<tXMLNode *>(this->children)); 
     
    287274   * \returns A begin-const_iterator 
    288275   */ 
    289   inline const const_iterator GetChildrenBegin() const 
     276  inline const const_iterator ChildrenBegin() const 
    290277  { 
    291278    return const_iterator(reinterpret_cast<tXMLNode *>(this->children)); 
     
    296283   * \returns An end-iterator 
    297284   */ 
    298   const iterator &GetChildrenEnd(); 
     285  const iterator &ChildrenEnd(); 
    299286 
    300287  /*! Get a const_iterator to mark the end of children traversal 
     
    302289   * \returns An end-const_iterator 
    303290   */ 
    304   const const_iterator &GetChildrenEnd() const; 
     291  const const_iterator &ChildrenEnd() const; 
    305292 
    306293  /*! Check if this node has children of type XML_ELEMENT_NODE 
     
    314301  inline const bool HasChildren() const 
    315302  { 
    316     return this->GetChildrenBegin() != this->GetChildrenEnd(); 
     303    return this->ChildrenBegin() != this->ChildrenEnd(); 
    317304  } 
    318305 
     
    325312  inline const size_t GetNumberOfChildren() const 
    326313  { 
    327     return std::distance(this->GetChildrenBegin(), this->GetChildrenEnd()); 
     314    return std::distance(this->ChildrenBegin(), this->ChildrenEnd()); 
    328315  } 
    329316 
     
    337324   * \returns Whether \a this has children or not 
    338325   */ 
    339   tXMLNode &GetFirstChild(); 
     326  tXMLNode &FirstChild(); 
    340327 
    341328  /*! Get access to first child of this node in const context 
     
    348335   * \returns Whether \a this has children or not 
    349336   */ 
    350   inline const tXMLNode &GetFirstChild() const 
    351   { 
    352     return const_cast<tXMLNode *>(this)->GetFirstChild(); 
     337  inline const tXMLNode &FirstChild() const 
     338  { 
     339    return const_cast<tXMLNode *>(this)->FirstChild(); 
    353340  } 
    354341 
     
    398385   * \returns A begin-iterator 
    399386   */ 
    400   inline const iterator GetNextSiblingsBegin() 
     387  inline const iterator NextSiblingsBegin() 
    401388  { 
    402389    return iterator(reinterpret_cast<tXMLNode *>(this->next)); 
     
    407394   * \returns A begin-const_iterator 
    408395   */ 
    409   inline const const_iterator GetNextSiblingsBegin() const 
     396  inline const const_iterator NextSiblingsBegin() const 
    410397  { 
    411398    return const_iterator(reinterpret_cast<tXMLNode *>(this->next)); 
     
    416403   * \returns An end-iterator 
    417404   */ 
    418   const iterator &GetNextSiblingsEnd(); 
     405  const iterator &NextSiblingsEnd(); 
    419406 
    420407  /*! Get a const_iterator to mark the end of sibling traversal 
     
    422409   * \returns An end-const_iterator 
    423410   */ 
    424   const const_iterator &GetNextSiblingsEnd() const; 
     411  const const_iterator &NextSiblingsEnd() const; 
    425412 
    426413  /*! Check if siblings of type XML_ELEMENT_NODE are reachable via \c GetNextSibling from this node 
     
    434421  inline const bool HasNextSibling() 
    435422  { 
    436     return this->GetNextSiblingsBegin() != this->GetNextSiblingsEnd(); 
     423    return this->NextSiblingsBegin() != this->NextSiblingsEnd(); 
    437424  } 
    438425 
     
    446433   * \returns Whether \a this has children or not 
    447434   */ 
    448   tXMLNode &GetNextSibling(); 
     435  tXMLNode &NextSibling(); 
    449436 
    450437  /*! Get access to first child of this node in const context 
     
    457444   * \returns Whether \a this has children or not 
    458445   */ 
    459   inline const tXMLNode &GetNextSibling() const 
    460   { 
    461     return const_cast<tXMLNode *>(this)->GetNextSibling(); 
     446  inline const tXMLNode &NextSibling() const 
     447  { 
     448    return const_cast<tXMLNode *>(this)->NextSibling(); 
    462449  } 
    463450 
     
    577564  inline const long int GetLongIntAttribute(const std::string &name, int base = 10) const 
    578565  { 
    579     return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), strtol, base); 
     566    return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), std::strtol, base); 
    580567  } 
    581568 
     
    595582  inline const long long int GetLongLongIntAttribute(const std::string &name, int base = 10) const 
    596583  { 
    597     return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), strtoll, base); 
     584    return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), std::strtoll, base); 
    598585  } 
    599586 
     
    611598  inline const float GetFloatAttribute(const std::string &name) const 
    612599  { 
    613     return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), strtof); 
     600    return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), std::strtof); 
    614601  } 
    615602 
     
    627614  inline const double GetDoubleAttribute(const std::string &name) const 
    628615  { 
    629     return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), strtod); 
     616    return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), std::strtod); 
    630617  } 
    631618 
     
    643630  inline const long double GetLongDoubleAttribute(const std::string &name) const 
    644631  { 
    645     return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), strtold); 
     632    return tXMLNode::ConvertStringToNumber(this->GetStringAttribute(name), std::strtold); 
    646633  } 
    647634 
     
    668655    if (it == enum_names.end()) 
    669656    { 
    670       throw tXML2WrapperException("Invalid value for " + this->GetName() + "." + name + ": `" + value + "'"); 
     657      throw tXML2WrapperException("Invalid value for " + this->Name() + "." + name + ": `" + value + "'"); 
    671658    } 
    672659    return static_cast<TEnum>(std::distance(enum_names.begin(), it)); 
     
    687674  inline const bool GetBoolAttribute(const std::string &name) const 
    688675  { 
    689     static const char *bool_names_init[2] = { "false", "true" }; 
    690     static const std::vector<std::string> bool_names(bool_names_init, bool_names_init + 2); 
    691     // FIXME: with c++0x this can be static const std::vector<std::string> bool_strings = { "false", "true" }; 
    692  
     676    static const std::vector<std::string> bool_names = { "false", "true" }; 
    693677    return this->GetEnumAttribute<bool>(name, bool_names); 
    694678  } 
  • test/test_xml2_wrapper.cpp

    r34 r38  
    9393  node1.RemoveChildNode(node2); 
    9494 
    95   std::cout << "Accessing node with content: " << document1.GetRootNode().GetXMLDump() << std::endl; 
     95  std::cout << "Accessing node with content: " << document1.RootNode().GetXMLDump() << std::endl; 
    9696 
    97   std::cout << document1.GetRootNode().GetName() << std::endl; 
    98   std::cout << document1.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
    99   std::cout << document1.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
    100   std::cout << document1.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
    101   std::cout << document1.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     97  std::cout << document1.RootNode().Name() << std::endl; 
     98  std::cout << document1.RootNode().GetStringAttribute("prop_1") << std::endl; 
     99  std::cout << document1.RootNode().GetBoolAttribute("prop_2") << std::endl; 
     100  std::cout << document1.RootNode().GetDoubleAttribute("prop_3") << std::endl; 
     101  std::cout << document1.RootNode().GetIntAttribute("prop_4") << std::endl; 
    102102 
    103   for (tXMLNode::iterator it = document1.GetRootNode().GetChildrenBegin(); it != document1.GetRootNode().GetChildrenEnd(); ++it) 
     103  for (tXMLNode::iterator it = document1.RootNode().ChildrenBegin(); it != document1.RootNode().ChildrenEnd(); ++it) 
    104104  { 
    105105    std::cout << "Accessing node with content: " << it->GetXMLDump() << std::endl; 
    106106 
    107     std::cout << it->GetName() << std::endl; 
     107    std::cout << it->Name() << std::endl; 
    108108    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
    109109    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     
    121121  std::cout << "doc 2" << std::endl; 
    122122 
    123   std::cout << "Accessing node with content: " << document2.GetRootNode().GetXMLDump() 
    124             << " and " << document2.GetRootNode().GetNumberOfChildren() << " children." << std::endl; 
     123  std::cout << "Accessing node with content: " << document2.RootNode().GetXMLDump() 
     124            << " and " << document2.RootNode().GetNumberOfChildren() << " children." << std::endl; 
    125125 
    126   std::cout << document2.GetRootNode().GetName() << std::endl; 
    127   std::cout << document2.GetRootNode().GetStringAttribute("prop_1") << std::endl; 
    128   std::cout << document2.GetRootNode().GetBoolAttribute("prop_2") << std::endl; 
    129   std::cout << document2.GetRootNode().GetDoubleAttribute("prop_3") << std::endl; 
    130   std::cout << document2.GetRootNode().GetIntAttribute("prop_4") << std::endl; 
     126  std::cout << document2.RootNode().Name() << std::endl; 
     127  std::cout << document2.RootNode().GetStringAttribute("prop_1") << std::endl; 
     128  std::cout << document2.RootNode().GetBoolAttribute("prop_2") << std::endl; 
     129  std::cout << document2.RootNode().GetDoubleAttribute("prop_3") << std::endl; 
     130  std::cout << document2.RootNode().GetIntAttribute("prop_4") << std::endl; 
    131131 
    132   document2.GetRootNode().GetFirstChild().AddNextSibling(document1.GetRootNode().GetFirstChild()); 
     132  document2.RootNode().FirstChild().AddNextSibling(document1.RootNode().FirstChild()); 
    133133 
    134   std::cout << "Accessing node with content: " << document2.GetRootNode().GetXMLDump(true) << std::endl; 
     134  std::cout << "Accessing node with content: " << document2.RootNode().GetXMLDump(true) << std::endl; 
    135135 
    136   for (tXMLNode::iterator it = document2.GetRootNode().GetChildrenBegin(); it != document2.GetRootNode().GetChildrenEnd(); ++it) 
     136  for (tXMLNode::iterator it = document2.RootNode().ChildrenBegin(); it != document2.RootNode().ChildrenEnd(); ++it) 
    137137  { 
    138138    std::cout << "Accessing node with content: " << it->GetXMLDump() << std::endl; 
    139139 
    140     std::cout << "name = " << it->GetName() << std::endl; 
     140    std::cout << "name = " << it->Name() << std::endl; 
    141141    std::cout << it->GetStringAttribute("prop_1") << std::endl; 
    142142    std::cout << it->GetBoolAttribute("prop_2") << std::endl; 
     
    148148  } 
    149149 
    150   std::cout << "doc 1: " << document1.GetRootNode().GetXMLDump() << std::endl; 
    151   std::cout << "doc 2: " << document2.GetRootNode().GetXMLDump() << std::endl; 
     150  std::cout << "doc 1: " << document1.RootNode().GetXMLDump() << std::endl; 
     151  std::cout << "doc 2: " << document2.RootNode().GetXMLDump() << std::endl; 
    152152 
    153153  { 
     
    156156    document3.AddRootNode("foo"); 
    157157 
    158     xmlNewChild(reinterpret_cast<xmlNode *>(&document3.GetRootNode()), 0, reinterpret_cast<const xmlChar *>("child1"), reinterpret_cast<const xmlChar *>("text1")); 
    159     xmlNewChild(reinterpret_cast<xmlNode *>(&document3.GetRootNode().GetFirstChild()), 0, reinterpret_cast<const xmlChar *>("child2"), reinterpret_cast<const xmlChar *>("text2")); 
     158    xmlNewChild(reinterpret_cast<xmlNode *>(&document3.RootNode()), 0, reinterpret_cast<const xmlChar *>("child1"), reinterpret_cast<const xmlChar *>("text1")); 
     159    xmlNewChild(reinterpret_cast<xmlNode *>(&document3.RootNode().FirstChild()), 0, reinterpret_cast<const xmlChar *>("child2"), reinterpret_cast<const xmlChar *>("text2")); 
    160160 
    161     xmlNodeAddContent(reinterpret_cast<xmlNode *>(&document3.GetRootNode().GetFirstChild()), reinterpret_cast<const xmlChar *>("text3")); 
     161    xmlNodeAddContent(reinterpret_cast<xmlNode *>(&document3.RootNode().FirstChild()), reinterpret_cast<const xmlChar *>("text3")); 
    162162 
    163     std::cout << "doc 3: " << document3.GetRootNode().GetXMLDump() << std::endl; 
     163    std::cout << "doc 3: " << document3.RootNode().GetXMLDump() << std::endl; 
    164164 
    165     std::cout << "content = " << document3.GetRootNode().GetFirstChild().GetTextContent() << std::endl; 
     165    std::cout << "content = " << document3.RootNode().FirstChild().GetTextContent() << std::endl; 
    166166 
    167     document3.GetRootNode().GetFirstChild().RemoveTextContent(); 
     167    document3.RootNode().FirstChild().RemoveTextContent(); 
    168168 
    169     std::cout << "content = " << document3.GetRootNode().GetFirstChild().GetTextContent() << std::endl; 
     169    std::cout << "content = " << document3.RootNode().FirstChild().GetTextContent() << std::endl; 
    170170 
    171     for (tXMLNode::iterator it = document3.GetRootNode().GetFirstChild().GetChildrenBegin(); it != document3.GetRootNode().GetFirstChild().GetChildrenEnd(); ++it) 
     171    for (tXMLNode::iterator it = document3.RootNode().FirstChild().ChildrenBegin(); it != document3.RootNode().FirstChild().ChildrenEnd(); ++it) 
    172172    { 
    173173      std::cout << "child: " << it->GetXMLDump() << std::endl; 
    174174    } 
    175175 
    176     document1.GetRootNode().AddChildNode(document3.GetRootNode().GetFirstChild()); 
     176    document1.RootNode().AddChildNode(document3.RootNode().FirstChild()); 
    177177  } 
    178178 
    179179 
    180   std::cout << "doc 1: " << document1.GetRootNode().GetXMLDump() << std::endl 
    181             << " has " << document1.GetRootNode().GetNumberOfChildren() << " children." << std::endl; 
     180  std::cout << "doc 1: " << document1.RootNode().GetXMLDump() << std::endl 
     181            << " has " << document1.RootNode().GetNumberOfChildren() << " children." << std::endl; 
    182182 
    183183  return EXIT_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.