00001 /* 00002 * Copyright (C) 2008 Patrick Ohly 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License version 2 as 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00017 * 02111-1307 USA 00018 */ 00019 00020 #ifndef INCL_EVOLUTION_FILE_CONFIG_NODE 00021 # define INCL_EVOLUTION_FILE_CONFIG_NODE 00022 00023 #include "ConfigNode.h" 00024 00025 #include <string> 00026 #include <list> 00027 using namespace std; 00028 00029 /** 00030 * This class started its life as the Posix implementation of the 00031 * ManagementNode in the Funambol C++ client library. Nowadays it is 00032 * part of the SyncEvoluition ConfigTree (see there for details). 00033 * 00034 * Each node is mapped to one file whose location is determined by 00035 * the ConfigTree when the node gets created. Each node represents 00036 * one .ini file with entries of the type 00037 * <property>\s*=\s*<value>\s*\n 00038 * 00039 * Comments look like: 00040 * \s*# <comment> 00041 * 00042 * @todo rewrite with standard C++ containers 00043 */ 00044 class FileConfigNode : public ConfigNode { 00045 string m_path; 00046 string m_fileName; 00047 00048 list<string> m_lines; 00049 bool m_modified; 00050 bool m_exists; 00051 00052 void read(); 00053 00054 public: 00055 /** 00056 * Open or create a new file. The file will be physically created 00057 * right away whereas changes to its content will not be written 00058 * immediately. 00059 * 00060 * @param path node name, maps to directory 00061 * @param fileName name of file inside that directory 00062 */ 00063 FileConfigNode(const string &path, const string &fileName); 00064 00065 virtual string getName() const { return m_path + "/" + m_fileName; } 00066 00067 virtual void flush(); 00068 virtual string readProperty(const string &property) const; 00069 virtual void setProperty(const string &property, 00070 const string &value, 00071 const string &comment = "", 00072 const string *defValue = NULL); 00073 virtual void readProperties(map<string, string> &props) const; 00074 virtual void removeProperty(const string &property); 00075 virtual bool exists() const { return m_exists; } 00076 }; 00077 00078 #endif