S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_config_node.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00031 #ifndef S3_CONFIG_NODE_H
00032 #define S3_CONFIG_NODE_H
00033 
00034 #include <vector>
00035 #include <list>
00036 #include <string>
00037 #include <map>
00038 #include <iostream>
00039 #include <sstream>
00040 #include <s3fc/s3_conversion.h>
00041 
00089 class s3_config_node
00090 {
00091   public:
00095    static s3_config_node empty_node;
00099    static s3_config_node at_end;
00100 #if 0
00101    void dump() const;
00102 #endif
00103   protected:
00107    std::string a_name;
00111    std::string a_value;
00115    s3_config_node* a_parent;
00119    std::map<std::string, std::string> a_attributes;
00123    std::vector<s3_config_node> a_children;
00124   public:
00125    // This typedef is necessary for the default construction values
00126    typedef  std::map<std::string, std::string> map_type;
00127    
00136    s3_config_node(const std::string& n_name = "",
00137                   const std::string& n_value = "",
00138                   const s3_config_node* n_parent = &empty_node,
00139                   const std::map<std::string, std::string>& n_attributes = map_type(),
00140                   const std::vector<s3_config_node>& n_children = std::vector<s3_config_node>() );
00141    
00177    s3_config_node(const s3_config_node& src);
00192    s3_config_node& operator=(const s3_config_node& src);
00198    bool empty() const;
00204    bool is_rootnode() const;
00209    s3_config_node*& parent();
00213    std::string& name();
00217    std::string& value();
00222    std::map<std::string, std::string>& attributes();
00227    std::vector<s3_config_node>& children();
00236    s3_config_node* insert_child(const s3_config_node& child = empty_node,
00237             const s3_config_node& before = at_end);
00243    void remove_child(const s3_config_node& child);
00244   protected:
00251    std::vector<s3_config_node>::iterator find_child(const s3_config_node& child);
00252 
00253   public:
00258    const s3_config_node& get_parent() const;
00263    s3_config_node& get_parent();
00268    void set_parent(s3_config_node& n_parent);
00273    const std::string& get_name() const;
00278    void set_name(const std::string& n_name);
00287    const std::string& get_value() const;
00292    void set_value(const std::string& n_value);
00303    template <typename T>
00304    T get_value() const;
00305 
00310    template <typename T>
00311    void set_value( const T& n_value );
00312 
00318    const std::map<std::string, std::string>& get_attributes() const;
00324    std::map<std::string, std::string>& get_attributes();
00329    unsigned int get_num_children() const;
00335    const s3_config_node& get_child(unsigned int i) const;
00341    s3_config_node& get_child(unsigned int i);
00351    const std::vector<const s3_config_node*>
00352    get_children(const std::string& name_filter = "") const;
00362    std::vector<s3_config_node*>
00363    get_children(const std::string& name_filter = "");
00372    bool node_exists(const std::string& path) const;
00382    const s3_config_node& get_node_at(const std::string& path) const;
00392    s3_config_node& get_node_at(const std::string& path);
00401    template<typename T>
00402    T get_value_at(const std::string& path) const;
00403 
00411    template<typename T>
00412    T get_attribute_at( const std::string& attr_name ) const;
00413   protected:
00414    // helper function that does all the dirty work for @c node_exists and
00415    // @c get_node_at
00416    const s3_config_node* gna_helper(const std::string& path) const;
00417 
00418 };
00419 
00420 #include <s3fc/s3_config_node.tcc>
00421 
00422 #endif
00423 

Send comments to: s3fc@stonethree.com SourceForge Logo