ConfigElement.h

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2006-07-13 11:56:58 -0500 (Thu, 13 Jul 2006) $
00028  * Version:       $Revision: 19047 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #ifndef _JCCL_CONFIG_ELEMENT_H_
00034 #define _JCCL_CONFIG_ELEMENT_H_
00035 
00036 #include <jccl/jcclConfig.h>
00037 #include <vector>
00038 
00039 #include <sstream>
00040 #include <cppdom/cppdom.h>
00041 #include <vpr/Util/Assert.h>
00042 
00043 #include <jccl/Config/ConfigElementPtr.h>
00044 #include <jccl/Config/ConfigDefinitionPtr.h>
00045 
00046 namespace jccl
00047 {
00048 
00055 class JCCL_CLASS_API ConfigElement
00056 {
00057 public:
00059    ConfigElement();
00060 
00064    ConfigElement(ConfigDefinitionPtr def);
00065 
00067    ConfigElement(const ConfigElement& c);
00068 
00074    ~ConfigElement();
00075 
00076    bool isValid() const;
00077 
00084    bool initFromNode(cppdom::NodePtr elementNode);
00085 
00087    ConfigElement& operator=(const ConfigElement& c);
00088 
00092    bool operator==(const ConfigElement& c) const;
00093 
00095    bool operator!=(const ConfigElement& c) const;
00096 
00098    bool operator<(const ConfigElement& c) const;
00099 
00111    ConfigElementPtr getChildElement(const std::string &path);
00112 
00118    friend JCCL_API(std::ostream&) operator<<(std::ostream& out,
00119                                              const ConfigElement& self);
00120 
00132    unsigned int getNum(const std::string& property) const;
00133 
00140    std::string getName() const;
00141 
00149    std::string getFullName() const;
00150 
00154    unsigned int getVersion() const;
00155 
00157    std::string getID() const;
00158 
00173    template<class T>
00174    T getProperty(const std::string& prop, int ind) const
00175    {
00176       std::string prop_string = getPropertyString(prop,ind);
00177 
00178       T ret_val = T();
00179       std::istringstream iss(prop_string);
00180       iss >> ret_val;
00181       return ret_val;
00182    }
00183 
00184    // Specializations of getProperty<T> placed inline for Visual Studio 7.
00185    // MIPSpro and GCC do not handle this.  They get out-of-line
00186    // specializations, found below.
00187 #if defined(_MSC_VER) && _MSC_VER == 1300
00188    template<>
00189    std::string getProperty<std::string>(const std::string& prop, int ind) const
00190    {
00191       std::string prop_string = getPropertyString(prop,ind);
00192       return prop_string;
00193    }
00194 
00199    template<>
00200    bool getProperty<bool>(const std::string& prop, int ind) const
00201    {
00202       return getProperty_bool(prop, ind);
00203    }
00204 
00205    template<>
00206    ConfigElementPtr getProperty<ConfigElementPtr>(const std::string& prop,
00207                                                   int ind) const
00208    {
00209       return getProperty_ElementPtr(prop, ind);
00210    }
00211 #endif /* defined(_MSC_VER) && _MSC_VER == 1300 */
00212 
00221 #if defined(_MSC_VER) && _MSC_VER == 1300
00222    template<class T>
00223    T getProperty(const std::string& prop) const
00224    {
00225       return getProperty<T>(prop, 0);
00226    }
00227 #else
00228    template<class T>
00229    T getProperty(const std::string& prop) const;
00230 #endif
00231 
00241    template<class T>
00242    bool setProperty(const std::string& prop, const int ind, T val)
00243    {
00244       cppdom::NodePtr cdata_node = getPropertyCdataNode(prop, ind, true);
00245       vprASSERT(cdata_node.get() != NULL && "Autogrow failed");
00246 
00247       std::ostringstream oss;
00248       oss << val;
00249       cdata_node->setCdata(oss.str());
00250       return true;
00251    }
00252 
00256    bool setProperty(const std::string& prop, const int ind, bool val);
00257 
00259    bool setProperty(const std::string& prop, const int ind,
00260                     ConfigElementPtr val);
00261 
00270    std::vector<std::string> getElementPtrDependencies() const;
00271 
00278    std::vector<jccl::ConfigElementPtr> getChildElements() const;
00279 
00283    void setDefinition(ConfigDefinitionPtr d);
00284    
00286    ConfigDefinitionPtr getConfigDefinition();
00287 
00288    cppdom::NodePtr getNode() const;
00289 
00290 protected:
00299    std::string getPropertyString(const std::string& prop, int ind) const;
00300 
00310    cppdom::NodePtr getPropertyCdataNode(const std::string& prop, int ind,
00311                                         bool autoCreate) const;
00312 
00318    bool getProperty_bool(const std::string& prop, int ind) const;
00319 
00325    ConfigElementPtr getProperty_ElementPtr(const std::string& prop,
00326                                            int ind) const;
00327 
00328 protected:
00329    cppdom::NodePtr     mNode;  
00330    ConfigDefinitionPtr mDef;   
00331    bool                mValid; 
00332 };
00333 
00334 #if ! defined(_MSC_VER) || _MSC_VER > 1300
00335 template<>
00336 inline std::string ConfigElement::getProperty<std::string>(const std::string& prop, int ind) const
00337 {
00338    std::string prop_string = getPropertyString(prop,ind);
00339    return prop_string;
00340 }
00341 
00346 template<>
00347 inline bool ConfigElement::getProperty<bool>(const std::string& prop, int ind) const
00348 {
00349    return getProperty_bool(prop, ind);
00350 }
00351 
00356 template<>
00357 inline ConfigElementPtr ConfigElement::getProperty<ConfigElementPtr>(const std::string& prop, int ind) const
00358 {
00359    return getProperty_ElementPtr(prop,ind);
00360 }
00361 
00362 template<class T>
00363 inline T ConfigElement::getProperty(const std::string& prop) const
00364 {
00365    return getProperty<T>(prop, 0);
00366 }
00367 #endif /* ! defined(_MSC_VER) || _MSC_VER > 1300 */
00368 
00369 } // namespace jccl
00370 
00371 #endif

Generated on Thu Jan 4 10:49:32 2007 for JCCL: Juggler Configuration and Control Library by  doxygen 1.5.1