aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/config_builder.h
blob: 4f651e5435a3d20b3520be071ac108c458613134 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef CFGINTERNALS_H
#define CFGINTERNALS_H

#include "config_builder/cfgmain.h"
#include "config_builder/cfgcategory.h"
#include "config_builder/cfgentry.h"
#include "config_builder/cfglazyinitializer.h"

#define CFG_CATEGORIES(Type,Body) _CFG_CATEGORIES_WITH_METANAME_AND_TITLE(Type,Body,"",QString(),API_EXPORT)

#define CFG_CATEGORY(Name,Body) \
    _CFG_CATEGORY_WITH_TITLE(Name,Body,QString())

#define CFG_ENTRY(Type, Name, ...) CfgTypedEntry<Type> Name = CfgTypedEntry<Type>(#Name, ##__VA_ARGS__);

#define CFG_DEFINE(Type) _CFG_DEFINE(Type, true)
#define CFG_DEFINE_RUNTIME(Type) _CFG_DEFINE(Type, false)
#define CFG_LOCAL(Type, Name) Cfg::Type Name = Cfg::Type(false);
#define CFG_LOCAL_PERSISTABLE(Type, Name) Cfg::Type Name = Cfg::Type(true);
#define CFG_DEFINE_LAZY(Type) \
    namespace Cfg\
    {\
        Type* cfgMainInstance##Type = nullptr;\
        void init##Type##Instance()\
        {\
            cfgMainInstance##Type = new Type(true);\
        }\
        Type* get##Type##Instance()\
        {\
            return cfgMainInstance##Type;\
        }\
        CfgLazyInitializer* cfgMainInstance##Type##LazyInit = new CfgLazyInitializer(init##Type##Instance, #Type);\
    }

#define CFG_INSTANCE(Type) (*Cfg::get##Type##Instance())

#define CFG_DELETE_INSTANCE(Type) \
    if (Cfg::cfgMainInstance##Type) \
        delete Cfg::cfgMainInstance##Type; \
    Cfg::cfgMainInstance##Type = nullptr;


// Macros below are kind of private. You should not need to use them explicitly.
// They are called from macros above.

#define _CFG_CATEGORIES_WITH_METANAME(Type,Body,MetaName) \
    _CFG_CATEGORIES_WITH_METANAME_AND_TITLE(Type,Body,MetaName,QString(),API_EXPORT)

#define _CFG_CATEGORIES_WITH_TITLE(Type,Body,Title) \
    _CFG_CATEGORIES_WITH_METANAME_AND_TITLE(Type,Body,"",Title,API_EXPORT)

#define _CFG_CATEGORIES_WITH_METANAME_AND_TITLE(Type,Body,MetaName,Title,ExportType) \
    namespace Cfg\
    {\
        struct ExportType Type : public CfgMain\
        {\
            Type(bool persistable) : CfgMain(#Type, persistable, MetaName, Title) {}\
            Body\
        };\
        ExportType Type* get##Type##Instance();\
    }

#define _CFG_DEFINE(Type, Persistant) \
    namespace Cfg\
    {\
        Type* cfgMainInstance##Type = new Type(Persistant);\
        Type* get##Type##Instance()\
        {\
            return cfgMainInstance##Type;\
        }\
    }

#define _CFG_CATEGORY_WITH_TITLE(Name,Body,Title) \
    struct API_EXPORT _##Name##Type : public CfgCategory\
    {\
        _##Name##Type() : CfgCategory(#Name, Title) {}\
        Body\
    };\
    _##Name##Type Name;


#endif // CFGINTERNALS_H