A template class for binding member variables with strings.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
ReadMe.txt
stdafx.cpp
stdafx.h
string_bindable_property.cpp
string_bindable_property.sln
string_bindable_property.vcxproj
string_bindable_property.vcxproj.filters
targetver.h

README.md

Defining a class by inheriting StringBindableClass

In the constructor, What you have to do is to bind the member variable with its string alias.

class TestClass : public StringBindableClass< TestClass >
{
public:
	TestClass()
	{
		this->Bind( "A", &TestClass::A );
		this->Bind( "B", &TestClass::B );
		this->Bind( "C", &TestClass::C );
	}

private:
	int A;
	float B;
	std::string C;
};

Retrieve the value of a member variable

Since there is no way to infer the type of the member variable at runtime, you have to specify a type of the template function, get.

	int a = testClass.Get< int >( "A" );
	float b = testClass.Get< float >( "B" );
	const std::string& c = testClass.Get< std::string >( "C" ); 

Set the value of a member variable

If the compiler can infer the type of the argument, you don't have to specify the type for the template function, set. I wouldn't recommend this though.

	testClass.Set( "A", 123 );
	testClass.Set( "B", 2.71828f );
	testClass.Set( "C", std::string( "Smith" ) );