Better alternative to initialization in a static class? (for SVN keywords)
I store SVN keyword extended literals for .cpp files in static char const * const 'members and want to keep the .h descriptions as close as possible. In short, I need to ensure that there is only one static member creation (presumably in a .cpp file) for an auto-generated non-integer literal living in a potentially shared .h file. Unfortunately, the language does not attempt to allow multiple instances resulting from assignments made outside of class definitions, and explicitly disallows non-integers within class definitions. My best attempt (using static wrappers of inner classes) isn't too messy, but I'd really like to do better. Does anyone have a way to wrapper pattern below or have a completely different approach?
// Foo.h: class with .h/.cpp SVN info stored and logged statically
class Foo {
static Logger const verLog;
struct hInfoWrap;
public:
static hInfoWrap const hInfo;
static char const *const cInfo;
};
// Would like to eliminate this per-class boilerplate.
struct Foo::hInfoWrap {
hInfoWrapper() : text("$Id$") { }
char const *const text;
};
...
// Foo.cpp: static inits called here
Foo::hInfoWrap const Foo::hInfo;
char const *const Foo::cInfo = "$Id$";
Logger const Foo::verLog(Foo::cInfo, Foo::hInfo.text);
...
// Helper.h: output on construction, with no subsequent activity or stored fields
class Logger {
Logger(char const *info1, char const *info2) {
cout << info0 << endl << info1 << endl;
}
};
Is there a way to get around the static address problem for hInfoWrap templates in string literals? Extern char pointers assigned to define external classes are linguistically valid, but do not execute in essentially the same way as initializing direct members. I understand why the language dodges the whole resolution problem, but it would be very convenient if an inverted extern member classifier was provided where the definition code was visible in the class definitions to any caller, but actually only called in one special elsewhere.
Anyway, I'm distracted. What's the best solution for the language we have, template or otherwise? Thanks!
a source to share
perhaps with a static function?
// Foo.h:
class Foo {
static Logger const verLog;
static char const*const getHInfo() { return "$Id$"; }
public:
static char const *const cInfo;
};
// Foo.cpp: static inits called here
char const *const Foo::cInfo = "$Id$";
Logger const Foo::verLog(Foo::cInfo, Foo::getHInfo());
a source to share