Entity Attributes
no worries. I sincerely appreciate the conversation. Everyone has a different methodology, and chatting like this helps us both. I was able to rebuild my property manager system slightly based on our talk here. I still am not sure that I like the lack of strong type checking though.... anyhow, back to the grindstone for me. I will see you next time.
well i kinda liked ur idea about the set/get thing. so i decided to add this feature. Btw my system has and had strong type checking. Its done internaly with the typeid().name() function. that way i made sure that both classes are of the same type. anyway my new system supports the following and is really awesome.
The user has the choice to either set his own Set/Get methods or to use the premade ones.
Code: Select all
class Test : public AppFrame::SAttributeContainer
{
public:
Test(void)
{
Health = 100;
Power = 100.f;
Bind("Health", &Test::setHealth, &Test::getHealth, &Test::setHealthStr, &Test::getHealthStr);
Bind("Power", &Power);
}
protected:
int Health;
float Power;
AppFrame::string getHealthStr(void)
{
char buffer[128];
sprintf(buffer, "%i", Health);
return buffer;
}
bool setHealthStr(const AppFrame::string& health)
{
sscanf(health.c_str(), "%i", &Health);
return true;
}
bool getHealth(int& health)
{
health = Health;
return true;
}
bool setHealth(const int& health)
{
Health = health;
return true;
}
};
int main()
{
int value = 0;
float value1 = 0.f;
Test t;
t.getValue("Health", value);
printf("Health: %i\n", value);
t.setValue("Health", "35");
t.getValue("Health", value);
printf("Health: %i\n", value);
t.setValue("Health", 1);
t.getValue("Health", value);
printf("Health: %i\n", value);
t.setValue("Health", "2");
printf("HealthString: %s\n", t.getValue("Health").c_str());
printf("--------------------------------------------------------------\n");
t.getValue("Power", value1);
printf("Power: %f\n", value1);
t.setValue("Power", "54.02");
t.getValue("Power", value1);
printf("Power: %f\n", value1);
t.setValue("Power", 87.010f);
t.getValue("Power", value1);
printf("Power: %f\n", value1);
t.setValue("Power", "11.50");
printf("PowerString: %s\n", t.getValue("Power").c_str());
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Awesome i just replaced my old Attribute system with the one i just showed.
Just had to make some name changes and it works so perfect. Its double the speed of the old system. (well microseconds...) not really noticeable
Just had to make some name changes and it works so perfect. Its double the speed of the old system. (well microseconds...) not really noticeable
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.