00001 /* 00002 Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are met: 00007 00008 1. Redistributions of source code must retain the above copyright notice, this 00009 list of conditions and the following disclaimer. 00010 00011 2. Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation 00013 and/or other materials provided with the distribution. 00014 00015 3. Neither the name of the University of Amsterdam nor the names of its 00016 contributors may be used to endorse or promote products derived from this 00017 software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00023 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00047 #ifndef _GENERIC_VALUES_ 00048 #define _GENERIC_VALUES_ 00049 00050 #include <ostream.h> // needed for output stream 00051 00053 enum GenericValueKind 00054 { 00055 GENERIC_VALUE_DOUBLE = 0, 00056 GENERIC_VALUE_STRING = 1, 00057 GENERIC_VALUE_BOOLEAN = 2, 00058 GENERIC_VALUE_INTEGER = 3, 00059 }; 00060 00061 /******************************************************************************/ 00062 /******************** CLASS GENERICVALUET *********************************/ 00063 /******************************************************************************/ 00064 00069 class GenericValueT 00070 { 00071 // private member data 00072 private: 00073 00074 const char* m_strName; 00076 void* m_vAddress; 00077 GenericValueKind m_type; 00080 // public methods 00081 public: 00082 00083 // constructor for the GenericValueT class 00084 GenericValueT( const char *strName, void *vAddress, GenericValueKind type ); 00085 00086 // destructor for the GenericValueT class 00087 ~GenericValueT( ); 00088 00089 // get methods for private member variables 00090 const char* getName ( ); 00091 00092 // methods to set/get the value of this generic variable 00093 bool setValue( const char *strValue ); 00094 char* getValue( char *strValue ); 00095 00096 // display method 00097 void show( ostream& out, const char *strSeparator ); 00098 }; 00099 00100 /******************************************************************************/ 00101 /******************** CLASS GENERICVALUES *********************************/ 00102 /******************************************************************************/ 00103 00113 class GenericValues 00114 { 00115 // private member data 00116 private: 00117 00118 char *m_strClassName; 00121 GenericValueT ** m_values; 00123 int m_iValuesTotal; 00125 int m_iMaxGenericValues; 00129 GenericValueT* getValuePtr( const char *strName ); 00130 00131 public: 00132 00133 // constructor for the GenericValues class 00134 GenericValues ( char *strName, int iMaxValues ); 00135 00136 // destructor for the GenericValues class 00137 virtual ~GenericValues ( ); 00138 00139 // get methods for private member variables 00140 char* getClassName ( ); 00141 int getValuesTotal ( ); 00142 00143 // method for adding a generic value to the collection 00144 bool addSetting( const char *strName, void *vAddress, GenericValueKind t ); 00145 00146 // methods for reading and writing generic values and collections of values 00147 virtual char* getValue ( const char *strName, char *strValue ); 00148 virtual bool setValue ( const char *strName, const char *strValue ); 00149 virtual bool readValues( const char *strFile, const char *strSeparator = 0 ); 00150 virtual bool saveValues( const char *strFile, const char *strSeparator = 0, 00151 bool bAppend = true ); 00152 00153 // display method 00154 virtual void show ( ostream& out, const char *strSeparator ); 00155 }; 00156 00157 #endif