-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathABDatabase.hpp
109 lines (93 loc) · 3.01 KB
/
ABDatabase.hpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// ABDatabase.hpp
// Maw Kit
//
// Created by Lluís Ulzurrun de Asanza Sàez on 25/02/16.
//
//
#ifndef ABDatabase_hpp
#define ABDatabase_hpp
#include <functional>
#include <string>
namespace MK {
/**
* `ABDatabase` namespace offers a read-only key-value storage system backed by
* MixPanel's AB test utilities so values can be changed at any moment.
*/
namespace ABDatabase {
/**
* Well known ABDatabase keys.
*
* @note Implementation details: this is wrapped in a namespace and not in an
* `enum class` because we need a mapping from each key to a string as
* native implementation of these methods use string keys and not numeric
* keys. Although any number could be converted to a string it makes it
* easier to debug if the string values of keys are actual string
* representations of he literals used in the code. As for the moment
* we are supporting C++11 and it does not allow setting a `std::string`
* nor `char *` associated values for `enum class`, we will stick to
* a set of constant values, wrapped in a namespace so they look more
* similar to an enumeration.
*/
namespace Key {
}; // namespace Key
/**
* Initializes A/B database and calls given callback if this is the first
* time database has been initialized since the game started.
*
* @native
*
* @param callback Callback to be run after initialising database for the first
* time.
*/
void init( const std::function<void( void )> callback = nullptr );
//------------------------------------------------------------------------------
// MARK: - Getters
//------------------------------------------------------------------------------
/**
* Returns string value associated with given key.
*
* @native
*
* @param key Key to retrieve.
* @param _default Value to return by default.
*
* @return String value associated with given key or default value.
*/
const std::string getStringValueForKey( const std::string &key, const std::string &_default );
/**
* Returns long value associated with given key.
*
* @native
*
* @param key Key to retrieve.
* @param _default Value to return by default.
*
* @return Long value associated with given key or default value.
*/
const long long getLongValueForKey( const std::string &key, const long long _default );
/**
* Returns bool value associated with given key.
*
* @native
*
* @param key Key to retrieve.
* @param _default Value to return by default.
*
* @return Long value associated with given key or default value.
*/
const bool getBoolValueForKey( const std::string &key, const bool _default );
/**
* Returns float value associated with given key.
*
* @native
*
* @param key Key to retrieve.
* @param _default Value to return by default.
*
* @return Long value associated with given key or default value.
*/
const float getFloatValueForKey( const std::string &key, const float _default );
}; // namespace ABDatabase
}; // namespace MK
#endif /* ABDatabase_hpp */