Main Page   Class Hierarchy   Compound List   File List   Compound Members  

resConfigRegistry.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #include <freecloth/resmgt/resConfigRegistry.imp.h>
00020 #include <freecloth/base/stdio.h>
00021 
00022 FREECLOTH_NAMESPACE_START
00023 
00024 ////////////////////////////////////////////////////////////////////////////////
00025 // CLASS ResConfigRegistryW
00026 
00027 //------------------------------------------------------------------------------
00028 
00029 ResConfigRegistryW::~ResConfigRegistryW()
00030 {
00031 }
00032 
00033 //------------------------------------------------------------------------------
00034 
00035 void ResConfigRegistryW::writeUInt32(
00036     const String& key,
00037     UInt32 value
00038 ) {
00039     writeString( key, BaStringUtil::fromUInt32( value ) );
00040 }
00041 
00042 //------------------------------------------------------------------------------
00043 
00044 void ResConfigRegistryW::writeFloat(
00045     const String& key,
00046     Float value
00047 ) {
00048     writeString( key, BaStringUtil::fromFloat( value ) );
00049 }
00050 
00051 //------------------------------------------------------------------------------
00052 
00053 void ResConfigRegistryW::writeEnum(
00054     const String& key,
00055     UInt32 value
00056 ) {
00057     writeUInt32( key, value );
00058 }
00059 
00060 //------------------------------------------------------------------------------
00061 
00062 void ResConfigRegistryW::writeBool(
00063     const String& key,
00064     bool value
00065 ) {
00066     writeUInt32( key, value ? 1 : 0 );
00067 }
00068 
00069 //------------------------------------------------------------------------------
00070 
00071 void ResConfigRegistryW::writeTimeDuration(
00072     const String& key,
00073     BaTime::Duration value
00074 ) {
00075     writeUInt32( key, value );
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////////////////
00079 // CLASS ResConfigRegistryW
00080 
00081 //------------------------------------------------------------------------------
00082 
00083 ResConfigRegistryR::~ResConfigRegistryR()
00084 {
00085 }
00086 
00087 //------------------------------------------------------------------------------
00088 
00089 UInt32 ResConfigRegistryR::readUInt32(
00090     const String& key,
00091     UInt32 def
00092 ) const {
00093     UInt32 result = def;
00094 
00095     if ( hasKey( key ) ) {
00096         String s = readString( key );
00097         ::sscanf( s.c_str(), "%d", &result );
00098     }
00099     return result;
00100 }
00101 
00102 //------------------------------------------------------------------------------
00103 
00104 Float ResConfigRegistryR::readFloat(
00105     const String& key,
00106     Float def
00107 ) const {
00108     Float result = def;
00109 
00110     if ( hasKey( key ) ) {
00111         String s = readString( key );
00112         ::sscanf( s.c_str(), "%f", &result );
00113     }
00114     return result;
00115 }
00116 
00117 //------------------------------------------------------------------------------
00118 
00119 UInt32 ResConfigRegistryR::readEnum(
00120     const String& key,
00121     UInt32 nbEntries,
00122     UInt32 def
00123 ) const {
00124     UInt32 result = def;
00125 
00126     if ( hasKey( key ) ) {
00127         result = readUInt32( key, def );
00128         if ( result >= nbEntries ) {
00129             result = def;
00130         }
00131     }
00132     return result;
00133 }
00134 
00135 //------------------------------------------------------------------------------
00136 
00137 bool ResConfigRegistryR::readBool(
00138     const String& key,
00139     bool def
00140 ) const {
00141     bool result = def;
00142 
00143     if ( hasKey( key ) ) {
00144         result = readUInt32( key, def ? 1 : 0 ) != 0 ? true : false;
00145     }
00146     return result;
00147 }
00148 
00149 //------------------------------------------------------------------------------
00150 
00151 BaTime::Duration ResConfigRegistryR::readTimeDuration(
00152     const String& key,
00153     BaTime::Duration def
00154 ) const {
00155     return readUInt32( key, def );
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////////////////
00159 // TEMPLATE INSTANTIATIONS
00160 
00161 FREECLOTH_NAMESPACE_END

Generated on Wed Apr 23 15:58:46 2003 for Freecloth by doxygen1.3-rc3