Browse Source

Add operator= and type cast

Daniele Bartolini 12 years ago
parent
commit
1362a14309

+ 10 - 2
src/core/settings/FloatSetting.cpp

@@ -39,7 +39,7 @@ FloatSetting::FloatSetting(const char* name, const char* synopsis, float value,
 	m_max(max),
 	m_max(max),
 	m_next(NULL)
 	m_next(NULL)
 {
 {
-	set_value(value);
+	*this = value;
 
 
 	if (FloatSetting::g_float_settings_head == NULL)
 	if (FloatSetting::g_float_settings_head == NULL)
 	{
 	{
@@ -84,7 +84,13 @@ float FloatSetting::max() const
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void FloatSetting::set_value(float value)
+FloatSetting::operator float()
+{
+	return m_value;
+}
+
+//-----------------------------------------------------------------------------
+FloatSetting& FloatSetting::operator=(const float value)
 {
 {
 	if (value > m_max)
 	if (value > m_max)
 	{
 	{
@@ -98,6 +104,8 @@ void FloatSetting::set_value(float value)
 	{
 	{
 		m_value = value;
 		m_value = value;
 	}
 	}
+
+	return *this;
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 4 - 1
src/core/settings/FloatSetting.h

@@ -38,11 +38,14 @@ public:
 
 
 	const char*			name() const;
 	const char*			name() const;
 	const char*			synopsis() const;
 	const char*			synopsis() const;
+
 	float				value() const;
 	float				value() const;
 	float				min() const;
 	float				min() const;
 	float				max() const;
 	float				max() const;
 
 
-	void				set_value(float value);
+						operator float();
+
+	FloatSetting&		operator=(const float value);
 
 
 private:
 private:
 
 

+ 10 - 2
src/core/settings/IntSetting.cpp

@@ -39,7 +39,7 @@ IntSetting::IntSetting(const char* name, const char* synopsis, int32_t value, in
 	m_max(max),
 	m_max(max),
 	m_next(NULL)
 	m_next(NULL)
 {
 {
-	set_value(value);
+	*this = value;
 
 
 	if (IntSetting::g_int_settings_head == NULL)
 	if (IntSetting::g_int_settings_head == NULL)
 	{
 	{
@@ -84,7 +84,13 @@ int32_t IntSetting::max() const
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void IntSetting::set_value(int32_t value)
+IntSetting::operator int()
+{
+	return m_value;
+}
+
+//-----------------------------------------------------------------------------
+IntSetting& IntSetting::operator=(const int32_t value)
 {
 {
 	if (value > m_max)
 	if (value > m_max)
 	{
 	{
@@ -98,6 +104,8 @@ void IntSetting::set_value(int32_t value)
 	{
 	{
 		m_value = value;
 		m_value = value;
 	}
 	}
+
+	return *this;
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 4 - 1
src/core/settings/IntSetting.h

@@ -38,11 +38,14 @@ public:
 
 
 	const char*			name() const;
 	const char*			name() const;
 	const char*			synopsis() const;
 	const char*			synopsis() const;
+
 	int32_t				value() const;
 	int32_t				value() const;
 	int32_t				min() const;
 	int32_t				min() const;
 	int32_t				max() const;
 	int32_t				max() const;
 
 
-	void				set_value(int32_t value);
+						operator int();
+
+	IntSetting&			operator=(const int32_t value);
 
 
 private:
 private: