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_ABSTRACT_CONFIG_NODE 00021 # define INCL_EVOLUTION_ABSTRACT_CONFIG_NODE 00022 00023 #include <map> 00024 #include <utility> 00025 #include <string> 00026 using namespace std; 00027 00028 /** 00029 * This class corresponds to the Funambol C++ client 00030 * DeviceManagementNode, but offers a slightly different API. See 00031 * ConfigTree for details. 00032 */ 00033 class ConfigNode { 00034 public: 00035 /** free resources without saving */ 00036 virtual ~ConfigNode() {} 00037 00038 /** a name for the node that the user can understand */ 00039 virtual string getName() const = 0; 00040 00041 /** 00042 * save all changes persistently 00043 */ 00044 virtual void flush() = 0; 00045 00046 /** 00047 * Returns the value of the given property 00048 * 00049 * @param property - the property name 00050 * @return value of the property or empty string if not set 00051 */ 00052 virtual string readProperty(const string &property) const = 0; 00053 00054 /** 00055 * Sets a property value. 00056 * 00057 * @param property the property name 00058 * @param value the property value (zero terminated string) 00059 * @param comment a comment explaining what the property is about, with 00060 * \n separating lines; might be used by the backend 00061 * when adding a new property 00062 * @param defValue If a defValue is provided and the value 00063 * matches the default, then the node is asked to 00064 * remember that the value hasn't really been changed. 00065 * An implementation can decide to not support this. 00066 */ 00067 virtual void setProperty(const string &property, 00068 const string &value, 00069 const string &comment = string(""), 00070 const string *defValue = NULL) = 0; 00071 00072 /** 00073 * Extract all list of all currently defined properties 00074 * and their values. Does not include values which were 00075 * initialized with their defaults, if the implementation 00076 * remembers that. 00077 * 00078 * @retval props to be filled with key/value pairs; guaranteed 00079 * to be empty before the call 00080 */ 00081 virtual void readProperties(map<string, string> &props) const = 0; 00082 00083 /** 00084 * Remove a certain property. 00085 * 00086 * @param property the name of the property which is to be removed 00087 */ 00088 virtual void removeProperty(const string &property) = 0; 00089 00090 /** 00091 * Node exists in backend storage. 00092 */ 00093 virtual bool exists() const = 0; 00094 }; 00095 00096 #endif