any ideas?
The use of define and singleton
Any questions?
Do you mean what are 'define' and what is a singleton?
#define is a preprocessor instruction. Before compile any code, it will replace the first value with the second. For instance, if I've got:
#define NAME "Sam"
I can write:
lprintfln(NAME);
When it compiles the code, it will replace the NAME with "Sam" before compiling, so what it actually compiles is
lprintfln("Sam");
It's very useful when working with settings, because you can't mistype something.
A singleton is a design pattern. A singleton class only has one instance, and every consumer of that class uses the same instance. Typically, this is done by having a static method which will return a pointer or a reference to the instance.
thanks sam i understand the define part. but for singleton still not quite sure anyway to understand them?
Hi,
check this:
http://en.wikipedia.org/wiki/Singleton_pattern
In fact, you don't need to use defines. Check this example:
class Globais {
public:
Globais();
~Globais();
static Globais& getInstance();
static void disposeInstance();
uint getUInt32(MAUtil::String param);
double getDouble(MAUtil::String param);
bool getBoolean(MAUtil::String param);
void getString(MAUtil::String param, MAUtil::String& value);
void setParam(MAUtil::String param, double dValue, MAUtil::String sValue);
private:
MAUtil::HashMap<MAUtil::String,MAUtil::String> mConfig;
static Globais *instance;
char* nullString;
};
Diego