Leviathan  0.8.0.0
Leviathan game engine
AccessMask.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "AccessMask.h"
3 
4 #include "Exceptions.h"
5 using namespace Leviathan;
6 // ------------------------------------ //
8 {
9  AccessFlags access = 0;
10 
11  // Handle in chunks delimited by + //
12  size_t start = 0;
13  size_t end = 0;
14 
15  for(size_t i = 0; i < flagstring.size(); ++i) {
16 
17  if(flagstring[i] == '+') {
18 
19  // Parse subpart //
20  access |= StringToScriptAccess(flagstring.substr(start, end - start + 1));
21  start = i + 1;
22  end = i + 1;
23 
24  } else {
25 
26  end = i;
27  }
28  }
29 
30  // Add last part if there is still something //
31  if(end > start) {
32 
33  access |= StringToScriptAccess(flagstring.substr(start, end - start + 1));
34  }
35 
36  // Give error about ending with a plus sign //
37  if(end == start && end > 0)
38  throw InvalidArgument("ScriptAccess value ended in '" +
39  std::string(flagstring.substr(start - 1, 1)) + "'");
40 
41  return access;
42 }
43 
44 #define STRING_TO_VALUE_HELPER(x) \
45  if(str == #x) \
46  return static_cast<AccessFlags>(ScriptAccess::x);
47 
49 {
50 
52 
56 
57  throw InvalidArgument("No ScriptAccess value named '" + std::string(str) + "'");
58  return static_cast<AccessFlags>(ScriptAccess::Nothing);
59 }
Access to the builtin types like string and math functions.
Can access none of the bound functions or "inbuilt" math and string types.
uint32_t AccessFlags
Definition: AccessMask.h:54
#define STRING_TO_VALUE_HELPER(x)
Definition: AccessMask.cpp:44
Default mask for engine classes (some things are accessible even with this off)
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT AccessFlags ParseScriptAccess(std::string_view flagstring)
Parses a string for access flags.
Definition: AccessMask.cpp:7
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT AccessFlags StringToScriptAccess(std::string_view str)
Returns ScriptAccess matching string.
Definition: AccessMask.cpp:48