00001 #ifndef IONFLUX_TOOLS_CONFIGTREE 00002 #define IONFLUX_TOOLS_CONFIGTREE 00003 /* ========================================================================== 00004 * Ionflux Tools 00005 * Copyright (c) 2004 Joern P. Meier 00006 * mail@ionflux.org 00007 * -------------------------------------------------------------------------- 00008 * ConfigTree.hpp Configuration tree. 00009 * ========================================================================== 00010 * 00011 * This file is part of Ionflux Tools. 00012 * 00013 * Ionflux Tools is free software; you can redistribute it and/or modify it 00014 * under the terms of the GNU General Public License as published by the Free 00015 * Software Foundation; either version 2 of the License, or (at your option) 00016 * any later version. 00017 * 00018 * Ionflux Tools is distributed in the hope that it will be useful, but 00019 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00020 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00021 * for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with Ionflux Tools; if not, write to the Free Software Foundation, 00025 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 * 00027 * ========================================================================== */ 00028 00029 #include <string> 00030 #include <iostream> 00031 #include <fstream> 00032 #include <sstream> 00033 #include <vector> 00034 #include "ionflux/tools.hpp" 00035 #include "ionflux/Config.hpp" 00036 #include "ionflux/Tree.hpp" 00037 #include "ionflux/NodeDump.hpp" 00038 #include "ionflux/Tokenizer.hpp" 00039 #include "ionflux/StringManipulator.hpp" 00040 00041 namespace Ionflux 00042 { 00043 00044 namespace Tools 00045 { 00046 00055 struct ConfigTreeEntry 00056 { 00058 ConfigLine line; 00060 DataEntry data; 00061 }; 00062 00068 class ConfigTree 00069 : public Tree, public Config, public NodeDump 00070 { 00071 protected: 00073 std::string inputFile; 00075 Tokenizer tok; 00077 std::vector<ConfigTreeEntry> entries; 00078 00089 virtual int findFirstLine(Node *searchNode); 00090 00101 virtual int findLastLine(Node *searchNode); 00102 00109 virtual int getAutoInsertPos(); 00110 00111 public: 00113 static const TokenType TT_COMMENT; 00115 static const TokenType TT_ASSIGN; 00117 static const TokenType TT_MULTILINE; 00119 static const TokenType TT_TREEPATH; 00121 static const TokenType TT_NESTED_OPEN; 00123 static const TokenType TT_NESTED_CLOSE; 00125 static const std::string AUTO_INSERT_MARKER; 00127 static const std::string SPECIAL_VALUE_CHARS; 00128 00133 ConfigTree(); 00134 00139 virtual ~ConfigTree(); 00140 00146 virtual void clear(); 00147 00154 virtual void parseConfig(const std::string& configData); 00155 00163 virtual void readConfig(const std::string& configFile); 00164 00172 virtual void writeConfig(const std::string& configFile); 00173 00179 virtual void writeConfig(); 00180 00191 virtual std::string get(const std::string& key); 00192 00200 virtual void set(const std::string& key, const std::string& value); 00201 00210 virtual void dump(Node *node); 00211 00221 static std::string escapeValue(const std::string& value); 00222 }; 00223 00224 } 00225 00226 } 00227 00231 #endif