From 8f7737b9c28e3c3adca3d5721961b746c3231232 Mon Sep 17 00:00:00 2001
From: meini <meini@meini-desktop.ARBEITSGRUPPE>
Date: Sun, 22 Mar 2009 16:01:56 +0100
Subject: removed void* add stringfunctions

---
 src/configVariable.h |  177 +++++++++++++++++++-------------------------------
 1 files changed, 67 insertions(+), 110 deletions(-)

diff --git a/src/configVariable.h b/src/configVariable.h
index 5abcb01a923e7b0a9fb6ff7e539a3bbcb588045d..0810db759c8f4ee4b8450c46922118c322c001bb 100644
--- a/src/configVariable.h
+++ b/src/configVariable.h
@@ -3,11 +3,22 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
+#include "remoteConfig.h"
 class RemoteConfig;
 
 typedef int (*variableSetHandler) (void* classref,const void* value);
 typedef int (*variableGetHandler) (void* classref,void* value);
+typedef int (*variableBoolSetHandler) (void* classref,const void* value);
+typedef int (*variableBoolGetHandler) (void* classref,void* value);
+typedef int (*variableIntSetHandler) (void* classref,const void* value);
+typedef int (*variableIntGetHandler) (void* classref,void* value);
+typedef int (*variableFloatSetHandler) (void* classref,const void* value);
+typedef int (*variableFloatGetHandler) (void* classref,void* value);
+typedef int (*variableStringSetHandler) (void* classref,const void* value);
+typedef int (*variableStringGetHandler) (void* classref,void* value);
+typedef int (*variableDoubleSetHandler) (void* classref,const void* value);
+typedef int (*variableDoubleGetHandler) (void* classref,void* value);
+
 
 enum
 {
@@ -17,6 +28,7 @@ enum
 	CONFIG_VARIABLE_CACHED = 3,
 	CONFIG_VARIABLE_READ = 4
 };
+
 class ConfigVariable
 {
 
@@ -43,7 +55,7 @@ class ConfigVariable
 				m_name = new char[length+1];
 				memcpy(m_name,name,length);
 				m_name[length]=0;
-				m_namelength=length+1;
+				m_namelength=length;
 			}
 			else
 			{
@@ -82,11 +94,8 @@ class ConfigVariable
 			m_vsh(m_thisref,value);
 			return 0;
 		}
-		void setFromString(const char * value)
-		{
-			this->fromString(value);
-			m_vsh(m_thisref,value);
-		}
+		virtual std::string toStdString()=0;
+		virtual int fromStdString(std::string)=0;
 
 		virtual char* toString(char* &buffer)=0;
 		virtual int fromString(const char * value)=0;
@@ -100,33 +109,30 @@ class ConfigVariableInt : public ConfigVariable
 	protected:
 	public:
 		
-		virtual int get(void* value)
+		virtual int get(int* value)
 		{
-			//*((int*)(value))=m_value;
 			m_vgh(m_thisref,value);
 			return 0;
 
 		}
-		virtual int set(void* value)
+		virtual int set(int* value)
 		{
-			//m_value=*((int*)value);
 			m_vsh(m_thisref,value);
 			return CONFIG_VARIABLE_SUCCESS;
 		}
 
-		ConfigVariableInt(const char* name, const int value, variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
+		ConfigVariableInt(const char* name, variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
 		{
-			//m_value=value;
+			
 		}
 		ConfigVariableInt(const ConfigVariableInt &c): ConfigVariable(c)
 		{
-			//m_value=c.m_value;
 		}
+
 		virtual char* toString(char* &buffer)
 		{
-			//char buffer[256];
-			memset(buffer,0,256);
 			int value=0;
+			memset(buffer,0,1024);
 			int retval = m_vgh(m_thisref,&value);
 			if(retval==CONFIG_VARIABLE_SUCCESS)
 				retval = sprintf(buffer,"%i",value);
@@ -138,85 +144,61 @@ class ConfigVariableInt : public ConfigVariable
 		}
 		virtual int fromString(const char * value)
 		{
-			printf("so dann machen wir mal nen test\n");fflush(stdout);
 			int mvalue=atoi(value);
-			printf("<%i> <%s>\n",mvalue,value);fflush(stdout);
 			m_vsh(m_thisref,&mvalue);
-			printf("na nanana?\n");fflush(stdout);
 		}
-
+		virtual std::string toStdString()
+		{
+			int value=0;
+			int retval = m_vgh(m_thisref,&value);
+			char buffer[1024];
+			if(retval==CONFIG_VARIABLE_SUCCESS)
+				retval = sprintf(buffer,"%i",value);
+			else
+				retval = sprintf(buffer,"%s","CONFIG_VARIABLE_FAILURE");
+			return std::string(buffer);
+		}
+		virtual int fromStdString(std::string s)
+		{
+			int mvalue=atoi(s.c_str());
+			m_vsh(m_thisref,&mvalue);
+		}
 };
 
 
 class ConfigVariableString : public ConfigVariable
 {
 	private:
-
 	protected:
-		//char* m_value;
-		//unsigned int m_valueLength;
 	public:
 
-		virtual int get(void* value)
+		virtual int get(char* value)
 		{
-			//*((int*)(value))=m_value;
-			//value = new char[m_valueLength];
-			//m_vgh(m_thisref,&value);
-			//memcpy(value,m_value,m_valueLength);
 			m_vgh(m_thisref,value);
-
-
 			return CONFIG_VARIABLE_SUCCESS;
 		}
-		virtual int set(void* value)
+
+		virtual int set(char* value)
 		{
-//			m_value=*((int*)value);
 			int valueLength = strlen((char*)value);
 			if(valueLength>0)
 			{
 				m_vsh(m_thisref,value);
-				//char* value=new char[valueLength];
-				//memcpy(m_value,value,m_valueLength);
 			}
 			return CONFIG_VARIABLE_SUCCESS;
 		}
 
-		ConfigVariableString(const char* name,  const char* value,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
-		{
-			if(value)
-			{
-				unsigned int length = strlen(value);
-				//m_value = new char[length+1];
-			//	memcpy(m_value,value,length);
-			//	m_value[length]=0;
-			//	m_valueLength=length+1;
-			}
-		}
+		ConfigVariableString(const char* name,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
+		{}
 		ConfigVariableString(const ConfigVariableString &c): ConfigVariable(c)
-		{
-			//if(c.m_value)
-			{
-			//	m_value = new char[c.m_valueLength];
-			//	memcpy(m_value,c.m_value,c.m_valueLength);
-			//	m_value[c.m_valueLength]=0;
-			//	m_valueLength=c.m_valueLength;
-			}
-		}
+		{}
 
 		virtual ~ConfigVariableString()
-		{
-			//if(m_value)
-			{
-			//	delete m_value;
-			//	m_value=NULL;
-			//	m_valueLength=0;
-			}
-		}
+		{}
 		virtual char* toString(char* &buffer)
 		{	
 			
 			buffer = new char[1024];
-			//memcpy(buffer,m_value,m_valueLength);
 			memset(buffer,0,1024);
 			m_vgh(m_thisref,buffer);
 			return buffer;
@@ -228,53 +210,39 @@ class ConfigVariableString : public ConfigVariable
 			if(valueLength>0)
 			{
 				m_vsh(m_thisref,value);
-				//if(m_value)
-				//	delete m_value;
-				//m_value = new char[m_valueLength];
-				//memcpy(m_value,value,m_valueLength);
 			}
 			
 		}
+		virtual std::string toStdString(){}
+		virtual int fromStdString(std::string){}
+
 };
 
 
 class ConfigVariableBool : public ConfigVariable
 {
 	private:
-
 	protected:
-		bool m_value;
-
 	public:
 
-		virtual int get(void* value)
+		virtual int get(bool* value)
 		{
-			//*((bool*)(value))=m_value;
 			m_vgh(m_thisref,value);
 			return CONFIG_VARIABLE_SUCCESS;
 		}
-		virtual int set(void* value)
+		virtual int set(bool* value)
 		{
-			//m_value=*((bool*)value);
 			m_vsh(m_thisref,value);
 			return CONFIG_VARIABLE_SUCCESS;
 		}
 
-		ConfigVariableBool(const char* name,  const bool value,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
-		{
-			//m_value=value;
-		}
+		ConfigVariableBool(const char* name,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
+		{}
 		ConfigVariableBool(const ConfigVariableBool &c): ConfigVariable(c)
-		{
-			//m_value=c.m_value;
-		}
+		{}
 
 		virtual char* toString(char* &buffer)
 		{
-			//char buffer[256];
-			
-			//buffer = new char[16];
-			//memcpy(buffer,m_value,m_valueLength);
 			memset(buffer,0,1024);
 			bool value=false;
 			m_vgh(m_thisref,&value);
@@ -300,46 +268,38 @@ class ConfigVariableBool : public ConfigVariable
 			}
 			else GEA.dbg() << "ConfigVariableBool: unknown value: "<< value << endl;
 		}
+		virtual std::string toStdString(){}
+		virtual int fromStdString(std::string){}
 };
 
 class ConfigVariableFloat : public ConfigVariable
 {
 	private:
-
 	protected:
-		float m_value;
-
 	public:
 
-		virtual int get(void* value)
+		virtual int get(float* value)
 		{
-			*((float*)(value))=m_value;
 			m_vgh(m_thisref,value);
 			return 0;
 		}
-		virtual int set(void* value)
+		virtual int set(float* value)
 		{
-			m_value=*((float*)value);
 			m_vsh(m_thisref,value);
 			return CONFIG_VARIABLE_SUCCESS;
 		}
 		virtual char* toString(){}
 
-		ConfigVariableFloat(const char* name, const float value,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
-		{
-		}
+		ConfigVariableFloat(const char* name,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
+		{}
 		ConfigVariableFloat(const ConfigVariableFloat &c): ConfigVariable(c)
-		{
-		}
+		{}
 
 		virtual char* toString(char* &buffer)
 		{
-			//char buffer[256];
 			float value;
 			m_vgh(m_thisref,&value);
-			//buffer = new char[1024];
 			memset(buffer,0,1024);
-			
 			sprintf(buffer,"%f",value);
 			return buffer;
 		}
@@ -348,40 +308,36 @@ class ConfigVariableFloat : public ConfigVariable
 			float mvalue = atof(value);
 			m_vsh(m_thisref,&mvalue);
 		}
+		virtual std::string toStdString(){}
+		virtual int fromStdString(std::string){}
 };
 
 class ConfigVariableDouble : public ConfigVariable
 {
 	private:
-
 	protected:
-		double m_value;
-
 	public:
 
-		virtual int get(void* value)
+		virtual int get(double* value)
 		{
-			*((float*)(value))=m_value;
 			m_vgh(m_thisref,value);
 			return 0;
 
 		}
-		virtual int set(void* value)
+		virtual int set(double* value)
 		{
-			m_value=*((float*)value);
 			m_vsh(m_thisref,value);
 			return CONFIG_VARIABLE_SUCCESS;
 		}
 		virtual char* toString(){}
 
-		ConfigVariableDouble(const char* name, const double value,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
+		ConfigVariableDouble(const char* name,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name,vgh,vsh,classref)
 		{}
 		ConfigVariableDouble(const ConfigVariableDouble &c): ConfigVariable(c)
 		{}
 
 		virtual char* toString(char* &buffer)
 		{
-			//char buffer[256];
 			memset(buffer,0,256);
 			double value;
 			m_vgh(m_thisref,&value);
@@ -390,10 +346,11 @@ class ConfigVariableDouble : public ConfigVariable
 		}
 		virtual int fromString(const char * value)
 		{
-			//m_value = atof(value);
 			double mvalue = atof(value);
 			m_vsh(m_thisref,&mvalue);
 		}
+		virtual std::string toStdString(){}
+		virtual int fromStdString(std::string){}
 };
 
 
-- 
1.6.2.1


