[Yake-svn] SF.net SVN: yake: [1740] branches/v0-6-0/yake
Status: Beta
Brought to you by:
psyclonist
From: <psy...@us...> - 2007-04-24 17:58:38
|
Revision: 1740 http://svn.sourceforge.net/yake/?rev=1740&view=rev Author: psyclonist Date: 2007-04-24 10:58:38 -0700 (Tue, 24 Apr 2007) Log Message: ----------- relaxed include dependencies Modified Paths: -------------- branches/v0-6-0/yake/scripts/premake/yake.lua branches/v0-6-0/yake/src/base/yake.cpp branches/v0-6-0/yake/yake/base/yake.h branches/v0-6-0/yake/yake/base/yakeConfigFile.h Added Paths: ----------- branches/v0-6-0/yake/src/base/yakeConfigFile.cpp Modified: branches/v0-6-0/yake/scripts/premake/yake.lua =================================================================== --- branches/v0-6-0/yake/scripts/premake/yake.lua 2007-04-24 17:44:36 UTC (rev 1739) +++ branches/v0-6-0/yake/scripts/premake/yake.lua 2007-04-24 17:58:38 UTC (rev 1740) @@ -106,14 +106,6 @@ addMatching("src/base/native/Linux/*.cpp") end - -- add dependency to TinyXML - -- Reason: boost::property_tree used in yake::Configuration - -- can use TinyXML or boost::spirit for parsing XML. - -- By default we enable it to use TinyXML. - addMatching("dependencies/tinyxml/*.h") - addMatching("dependencies/tinyxml/*.cpp") - addIncludePath("dependencies/tinyxml/") - useDep("boost") Modified: branches/v0-6-0/yake/src/base/yake.cpp =================================================================== --- branches/v0-6-0/yake/src/base/yake.cpp 2007-04-24 17:44:36 UTC (rev 1739) +++ branches/v0-6-0/yake/src/base/yake.cpp 2007-04-24 17:58:38 UTC (rev 1740) @@ -26,4 +26,5 @@ */ #include <yake/base/yakePCH.h> #include <yake/base/yake.h> -#include <yake/base/templates/yakeSignals.h> \ No newline at end of file + + Added: branches/v0-6-0/yake/src/base/yakeConfigFile.cpp =================================================================== --- branches/v0-6-0/yake/src/base/yakeConfigFile.cpp (rev 0) +++ branches/v0-6-0/yake/src/base/yakeConfigFile.cpp 2007-04-24 17:58:38 UTC (rev 1740) @@ -0,0 +1,149 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ + +#include <yake/base/yakePCH.h> +#include <yake/base/yakeConfigFile.h> + +namespace yake { +namespace base { + + namespace detail { + } // namespace detail + + Configuration::Configuration() : tree_( new tree_type() ) + { + } + Configuration::Configuration(const Configuration& other) : tree_(other.tree_), prefix_(other.prefix_) + { + } + const Configuration& Configuration::operator=(const Configuration& rhs) + { + if (this == &rhs) + return *this; + tree_ = rhs.tree_; + prefix_ = rhs.prefix_; + return *this; + } + Configuration::Configuration(const Configuration& cfg, const String& path) : tree_( cfg.tree_ ), prefix_(path) + { + if (!prefix_.empty()) + { + // make sure there's a trailing '/' + if (prefix_.at( prefix_.size() -1 ) != '/') + prefix_ += '/'; + } + } + void Configuration::copyFrom(const Configuration& other) + { + tree_.reset( new tree_type() ); + if (other.tree_) + *tree_ = *other.tree_; + prefix_ = other.prefix_; + } + Configuration::~Configuration() + { + } + Configuration::const_iterator Configuration::begin(const String& path) const + { + try { + return tree_->get_child('/',prefix_+path).begin(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + Configuration::const_iterator Configuration::end(const String& path) const + { + try { + return tree_->get_child('/',prefix_+path).end(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + bool Configuration::exists(const String& path) const + { + try { + tree_->get_child('/',prefix_+path); + return true; + } + catch (boost::property_tree::ptree_error&) + { + return false; + } + } + String Configuration::get(const String& pathToValue, const String& defaultValue) const + { + try { + return tree_->get<String>('/',prefix_+pathToValue); + } + catch (...) + { + return defaultValue; + } + } + void Configuration::readFromFile(const String& fn, const String& insertAt) + { + YAKE_ASSERT( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_info(in,*tree_); + } + void Configuration::readFromXML(const String& fn, const String& insertAt) + { + YAKE_ASSERT( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_xml(in,*tree_); + } + void Configuration::writeToFile(const String& fn, const String& startAt) + { + YAKE_ASSERT( startAt.empty() && "not yet supported" ); + //boost::property_tree::write_info(cout,*tree_); + + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_info(out,*tree_); + } + void Configuration::writeToXML(const String& fn, const String& startAt) + { + YAKE_ASSERT( startAt.empty() && "not yet supported" ); + //boost::property_tree::write_xml(cout,*tree_); + + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_xml(out,*tree_); + } + +} // base +} // yake Modified: branches/v0-6-0/yake/yake/base/yake.h =================================================================== --- branches/v0-6-0/yake/yake/base/yake.h 2007-04-24 17:44:36 UTC (rev 1739) +++ branches/v0-6-0/yake/yake/base/yake.h 2007-04-24 17:58:38 UTC (rev 1740) @@ -60,7 +60,6 @@ //#include "yakeDebugOutputStream.h" #include "yakeLibrary.h" #include <yake/base/type_info.h> -#include "yakeConfigFile.h" #include "math/yakeQuaternion.h" #include "math/yakeVector3.h" Modified: branches/v0-6-0/yake/yake/base/yakeConfigFile.h =================================================================== --- branches/v0-6-0/yake/yake/base/yakeConfigFile.h 2007-04-24 17:44:36 UTC (rev 1739) +++ branches/v0-6-0/yake/yake/base/yakeConfigFile.h 2007-04-24 17:58:38 UTC (rev 1740) @@ -38,7 +38,10 @@ #pragma warning(push) #pragma warning(disable: 4267) // '=' : conversion from 'size_t' to 'unsigned int' ... #endif -#define BOOST_PROPERTY_TREE_XML_PARSER_TINYXML +//#define BOOST_PROPERTY_TREE_XML_PARSER_TINYXML +//#if defined(TIXML_USE_STL) // property_tree/xml_parser_read_tinyxml.hpp will redefine this. +//#undef TIXML_USE_STL +//#endif #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/info_parser.hpp> @@ -69,83 +72,28 @@ typedef tree_type::value_type value_type; /** Construct empty configuration object. */ - Configuration() : tree_( new tree_type() ) - { - } + Configuration(); /** Copy-construct configuration object. @note Both Configurations share the data! */ - Configuration(const Configuration& other) : tree_(other.tree_), prefix_(other.prefix_) - { - } + Configuration(const Configuration& other); /** Copy configuration data. @note Both Configurations share the data! */ - Configuration& operator=(const Configuration& rhs) - { - if (this == &rhs) - return *this; - tree_ = rhs.tree_; - prefix_ = rhs.prefix_; - return *this; - } + const Configuration& operator=(const Configuration& rhs); /** Copy-construct configuration but with optional offset into the hierarchy (i.e. path != ""). */ - Configuration(const Configuration& cfg, const String& path) : tree_( cfg.tree_ ), prefix_(path) - { - if (!prefix_.empty()) - { - // make sure there's a trailing '/' - if (prefix_.at( prefix_.size() -1 ) != '/') - prefix_ += '/'; - } - } - void copyFrom(const Configuration& other) - { - tree_.reset( new tree_type() ); - if (other.tree_) - *tree_ = *other.tree_; - prefix_ = other.prefix_; - } - ~Configuration() - { - } + Configuration(const Configuration& cfg, const String& path); + void copyFrom(const Configuration& other); + ~Configuration(); /** Returns iterator to the first of any children. */ - const_iterator begin(const String& path = "") const - { - try { - return tree_->get_child('/',prefix_+path).begin(); - } - catch (boost::property_tree::ptree_error&) - { - return tree_->end(); - } - } + const_iterator begin(const String& path = "") const; /** Returns iterator to one element beyond the last of any children. */ - const_iterator end(const String& path = "") const - { - try { - return tree_->get_child('/',prefix_+path).end(); - } - catch (boost::property_tree::ptree_error&) - { - return tree_->end(); - } - } - bool exists(const String& path) const - { - try { - tree_->get_child('/',prefix_+path); - return true; - } - catch (boost::property_tree::ptree_error&) - { - return false; - } - } + const_iterator end(const String& path = "") const; + bool exists(const String& path) const; /** Returns the value for the given path. @note Throws if node does not exist! @@ -158,22 +106,13 @@ /** Returns either value for the given path, or the default value if the path does not exist or if the type conversion failed. */ - String get(const String& pathToValue, const String& defaultValue) - { - try { - return tree_->get<String>('/',prefix_+pathToValue); - } - catch (...) - { - return defaultValue; - } - } + String get(const String& pathToValue, const String& defaultValue) const; /** Returns either value for the given path, or the default value if the path does not exist or if the type conversion failed. @note Type conversion is done automatically. */ template<typename T> - T get(const String& pathToValue, const T& defaultValue) + T get(const String& pathToValue, const T& defaultValue) const { try { return tree_->get<T>('/',prefix_+pathToValue); @@ -195,51 +134,19 @@ /** Overwrites existing configuration values if conflicts appear! */ - void readFromFile(const String& fn, const String& insertAt = "") - { - YAKE_ASSERT( insertAt.empty() && "not yet supported" ); - std::ifstream in(fn.c_str()); - if (!in.is_open()) - return; //@todo - boost::property_tree::read_info(in,*tree_); - } + void readFromFile(const String& fn, const String& insertAt = ""); /** Overwrites existing configuration values if conflicts appear! */ - void readFromXML(const String& fn, const String& insertAt = "") - { - YAKE_ASSERT( insertAt.empty() && "not yet supported" ); - std::ifstream in(fn.c_str()); - if (!in.is_open()) - return; //@todo - boost::property_tree::read_xml(in,*tree_); - } + void readFromXML(const String& fn, const String& insertAt = ""); /** @note Ignores any set offset/prefix! */ - void writeToFile(const String& fn, const String& startAt = "") - { - YAKE_ASSERT( startAt.empty() && "not yet supported" ); - //boost::property_tree::write_info(cout,*tree_); - - std::ofstream out(fn.c_str()); - if (!out.is_open()) - return; //@todo - boost::property_tree::write_info(out,*tree_); - } + void writeToFile(const String& fn, const String& startAt = ""); /** @note Ignores any set offset/prefix! */ - void writeToXML(const String& fn, const String& startAt = "") - { - YAKE_ASSERT( startAt.empty() && "not yet supported" ); - //boost::property_tree::write_xml(cout,*tree_); + void writeToXML(const String& fn, const String& startAt = ""); - std::ofstream out(fn.c_str()); - if (!out.is_open()) - return; //@todo - boost::property_tree::write_xml(out,*tree_); - } - private: tree_ptr tree_; String prefix_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |