|
From: <cn...@us...> - 2009-06-28 21:57:21
|
Revision: 385
http://hgengine.svn.sourceforge.net/hgengine/?rev=385&view=rev
Author: cnlohr
Date: 2009-06-28 21:57:18 +0000 (Sun, 28 Jun 2009)
Log Message:
-----------
add named resource (useful for making easily readable things)
Added Paths:
-----------
Mercury2/src/MercuryNamedResource.cpp
Mercury2/src/MercuryNamedResource.h
Added: Mercury2/src/MercuryNamedResource.cpp
===================================================================
--- Mercury2/src/MercuryNamedResource.cpp (rev 0)
+++ Mercury2/src/MercuryNamedResource.cpp 2009-06-28 21:57:18 UTC (rev 385)
@@ -0,0 +1,110 @@
+#include <MercuryNamedResource.h>
+#include <MercuryUtil.h>
+
+
+MString MercuryNamedResource::GetValueS( const MString & sDataPointer )
+{
+ MString ret;
+ GetValue( sDataPointer, ret );
+ return ret;
+}
+
+MString MercuryNamedResource::GetValueS( const MString & sDataPointer, MString sDefaultValue, bool bSetValue )
+{
+ MString ret;
+ if( GetValue( sDataPointer, ret ) )
+ return ret;
+
+ if( bSetValue )
+ SetValueS( sDataPointer, sDefaultValue );
+ return sDefaultValue;
+}
+
+
+float MercuryNamedResource::GetValueF( const MString & sDataPointer, float fDefaultValue, bool bSetValue )
+{
+ MString tmpret;
+ if( GetValue( sDataPointer, tmpret ) )
+ return StrToFloat( tmpret );
+ if( bSetValue )
+ SetValueF( sDataPointer, fDefaultValue );
+
+ return fDefaultValue;
+}
+
+void MercuryNamedResource::SetValueF( const MString & sDataPointer, float fValue )
+{
+ char sset[64];
+ snprintf( sset, 63, "%f", fValue );
+ SetValueS( sDataPointer, sset );
+}
+
+bool MercuryNamedResource::GetValueB( const MString & sDataPointer, bool bDefaultValue, bool bSetValue )
+{
+ MString tmpret;
+ if( GetValue( sDataPointer, tmpret ) )
+ return StrToInt( tmpret );
+ if( bSetValue )
+ SetValueB( sDataPointer, bDefaultValue );
+
+ return bDefaultValue;
+}
+
+void MercuryNamedResource::SetValueB( const MString & sDataPointer, bool bValue )
+{
+ if( bValue )
+ SetValueS( sDataPointer, "1" );
+ else
+ SetValueS( sDataPointer, "0" );
+}
+
+int MercuryNamedResource::GetValueI( const MString & sDataPointer, int iDefaultValue, bool bSetValue )
+{
+ MString tmpret;
+ if( GetValue( sDataPointer, tmpret ) )
+ return StrToInt( tmpret );
+ if( bSetValue )
+ SetValueI( sDataPointer, iDefaultValue );
+
+ return iDefaultValue;
+}
+
+void MercuryNamedResource::SetValueI( const MString & sDataPointer, int iValue )
+{
+ char sset[64];
+ snprintf( sset, 63, "%d", iValue );
+ SetValueS( sDataPointer, sset );
+}
+
+
+/****************************************************************************
+ * Copyright (C) 2009 by Charles Lohr *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/MercuryNamedResource.h
===================================================================
--- Mercury2/src/MercuryNamedResource.h (rev 0)
+++ Mercury2/src/MercuryNamedResource.h 2009-06-28 21:57:18 UTC (rev 385)
@@ -0,0 +1,82 @@
+#ifndef _MERCURY_NAMED_RESOURCE
+#define _MERCURY_NAMED_RESOURCE
+
+#include <MercuryString.h>
+
+///Base class for several named resources (I.e. Preferences, Theme, etc.)
+class MercuryNamedResource
+{
+public:
+ ///Get a Value
+ /** This function _must_ be overloaded by the base class, as there is no
+ mechanism for the named resource to figure this out. */
+ virtual bool GetValue( const MString & sDataPointer, MString & sReturn ) = 0;
+
+ ///Set a named value.
+ /** This function should be overloaded by the base class, unless you have no
+ means to write back. For instance, the theme will simply ignore this
+ function. */
+ virtual void SetValueS( const MString & sDataPointer, const MString & sValToSet ) { }
+
+ ///Retrieve a named value
+ /** This function can be overloaded by the base class, otherwise, it
+ just makes approprate calls to GetValue */
+ virtual MString GetValueS( const MString & sDataPointer, MString sDefaultValue, bool bSetValue = false );
+
+ ///Shorthand for retrieving a named value (calls GetValueS with null Parameters)
+ /** This function may be overloaded if you wish to improve performance slightly
+ when users are simply doing reads and do not intend to set default values */
+ virtual MString GetValueS( const MString & sDataPointer );
+
+ ///Retrieve a named value and convert it to a float.
+ float GetValueF( const MString & sDataPointer, float fDefaultValue = 0.0f, bool bSetValue = false );
+
+ ///Set a float value on a named resource.
+ void SetValueF( const MString & sDataPointer, float fValue );
+
+ ///Retrieve a named value and convert it to a boolean.
+ bool GetValueB( const MString & sDataPointer, bool bDefaultValue = false, bool bSetValue = false );
+
+ ///Set a float value on a named resource.
+ void SetValueB( const MString & sDataPointer, bool bValue );
+
+ ///Retrieve a named value and convert it to a float.
+ int GetValueI( const MString & sDataPointer, int iDefaultValue = 0, bool bSetValue = false );
+
+ ///Set a float value on a named resource.
+ void SetValueI( const MString & sDataPointer, int iValue );
+};
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2009 by Charles Lohr *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|