what I want to archive is a simple way to make some variables persistent. For this I wrote a PeristenceProvider Class which wraps the boost property tree functionality to store data in xml / ini files.
At the moment I need to do things like this:
ClassA::ClassA()
{
m_valueI = PersistenceProvider::getInstance.get<int>("valueI");
}
ClassA::~ClassA()
{
PeristenceProvider::getInstance.set<int>("valueI", m_valueI);
}
But is there a chance to hide this in a way like this:
class ClassA
{
Persist<int, "valueI"> m_ValueI;
}
1. Persistent data. When a C program exits, all of its global variables, local variables, and heap-allocated blocks are lost. Its memory is reclaimed by the operating system, erased, and handed out to other programs.
Persistence is "the continuance of an effect after its cause is removed". In the context of storing data in a computer system, this means that the data survives after the process with which it was created has ended. In other words, for a data store to be considered persistent, it must write to non-volatile storage.
Persistent data is static and does not change with time (not dynamic). Persistent data stores core information. For example, an organization's financial data must be persistent. Persistent data cannot be deleted by external processes or objects until the user deletes it, meaning it's stable.
Persistence data: The data which is available after fully closing the application. This type of data must be save into shared preference or database or internal or external memory. Non- persistence data: The data which is not available after fully closing the application.
It's possible but not exactly that way. You cannot use string literals to instantiate template. String objects with external linkage are only allowed to be non-type arguments.
So string constant must be defined as extern
and be char[]
, not just char*
.
See example (it will print "Hello" and "World", really cool, isn't it?):
extern const char hello[] = "Hello";
extern const char world[] = "World";
template<const char* s> struct X
{
X()
{
std::cout << s << std::endl;
}
};
X<hello> z1;
X<world> z2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With