1 /* 2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "StringConstants.h" 8 9 #include <new> 10 11 12 StringConstants StringConstants::sDefaultInstance; 13 14 15 /*static*/ bool 16 StringConstants::Init() 17 { 18 new(&sDefaultInstance) StringConstants; 19 if (!sDefaultInstance._Init()) { 20 sDefaultInstance.Cleanup(); 21 return false; 22 } 23 24 return true; 25 } 26 27 28 /*static*/ void 29 StringConstants::Cleanup() 30 { 31 sDefaultInstance.~StringConstants(); 32 } 33 34 35 bool 36 StringConstants::_Init() 37 { 38 // generate the member variable initializations 39 #define DEFINE_STRING_CONSTANT(name, value) \ 40 if (!name.SetTo(value)) \ 41 return false; 42 #define DEFINE_STRING_ARRAY_CONSTANT(name, size, ...) \ 43 { \ 44 const char* const _values[size] = { __VA_ARGS__ }; \ 45 for (size_t i = 0; i < sizeof(_values) / sizeof(_values[0]); \ 46 i++) { \ 47 if (!name[i].SetTo(_values[i])) \ 48 return false; \ 49 } \ 50 } 51 52 #include "StringConstantsPrivate.h" 53 54 #undef DEFINE_STRING_CONSTANT 55 #undef DEFINE_STRING_ARRAY_CONSTANT 56 57 return true; 58 } 59