VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
roleAssignmentStore.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <atomic>
12 #include <tbb/spin_rw_mutex.h>
13 #include <json/json.h>
14 
17 {
18  std::string assignmentId;
19  std::string name;
20  std::string description;
21  std::string scenarioName;
22  std::string definitionId;
23 };
24 
48 {
49 public:
52 
57  void initialize(const std::string& assignmentsDir);
58 
60  std::vector<DtAssignmentSetSummary> listAssignmentSets() const;
61 
64  bool getAssignmentSetById(const std::string& assignmentId,
65  Json::Value& outJson,
66  std::string& outError) const;
67 
71  bool loadAssignmentSetById(const std::string& assignmentId, std::string& outError);
72 
77  bool loadAssignmentSet(const std::string& name);
78 
81  std::string createAssignmentSet(const std::string& name,
82  const std::string& description,
83  const std::string& scenarioName,
84  const std::string& definitionId,
85  const std::map<std::string, std::vector<std::string>>& assignments,
86  std::string& outError);
87 
90  bool updateAssignmentSetDescription(const std::string& assignmentId,
91  const std::string& description,
92  std::string& outError);
93 
97  bool updateAssignmentSetUserRoles(const std::string& assignmentId,
98  const std::string& username,
99  const std::vector<std::string>& roleNames,
100  std::string& outError);
101 
106  bool updateActiveAssignmentUserRoles(const std::string& username,
107  const std::vector<std::string>& roleNames,
108  std::string& outError);
109 
112  bool deleteAssignmentSet(const std::string& assignmentId, std::string& outError);
113 
116  bool saveActiveAssignmentSet(const std::map<std::string, std::vector<std::string>>& assignments,
117  std::string& outError);
118 
124  void clearActiveAssignment();
125 
127  std::string activeAssignmentSetId() const;
128 
130  std::string activeAssignmentSetName() const;
131 
133  std::string activeAssignmentSetDescription() const;
134 
136  std::string activeAssignmentDefinitionId() const;
137 
140  std::vector<std::string> savedAssignments(const std::string& username) const;
141 
144  std::map<std::string, std::vector<std::string>> allSavedAssignments() const;
145 
148  uint64_t assignmentGeneration() const;
149 
150 private:
151  DtRoleAssignmentStore() = default;
152 
154  static std::vector<std::string> scanDirectory(const std::string& dir);
155 
157  static std::string generateUuid();
158 
160  static bool readAssignmentFile(const std::string& filePath,
161  Json::Value& outRoot,
162  std::string& outError);
163 
165  static bool writeAssignmentFile(const std::string& filePath,
166  const Json::Value& root,
167  std::string& outError);
168 
169  mutable tbb::spin_rw_mutex myMutex;
170 
171  std::string myAssignmentsDir;
172  std::map<std::string, std::string> myIdToFilePath;
173  std::map<std::string, std::string> myNameToId;
174  std::map<std::string, DtAssignmentSetSummary> myIndex;
175 
176  std::string myActiveSetId;
177  std::string myActiveSetName;
179  std::string myActiveDefinitionId;
180  std::map<std::string, std::vector<std::string>> myActiveAssignments;
181 
182  std::atomic<uint64_t> myAssignmentGeneration{0};
183 };
std::string activeAssignmentDefinitionId() const
Returns the definitionId bound to the currently active assignment set, or empty string.
std::string assignmentId
Stable UUID for this saved assignment set.
Definition: roleAssignmentStore.h:18
std::string myAssignmentsDir
Definition: roleAssignmentStore.h:171
void initialize(const std::string &assignmentsDir)
Scans assignmentsDir for *.json saved assignment files and builds the index. Ensures a reserved &quot;defa...
static bool writeAssignmentFile(const std::string &filePath, const Json::Value &root, std::string &outError)
Writes one assignment file to disk.
bool updateAssignmentSetDescription(const std::string &assignmentId, const std::string &description, std::string &outError)
Updates the saved assignment set description.
std::string myActiveDefinitionId
Definition: roleAssignmentStore.h:179
std::string myActiveSetName
Definition: roleAssignmentStore.h:177
static bool readAssignmentFile(const std::string &filePath, Json::Value &outRoot, std::string &outError)
Reads one assignment file from disk.
std::map< std::string, std::vector< std::string > > allSavedAssignments() const
Returns a copy of the complete username -&gt; roleNames map for the active set. Returns an empty map if ...
std::map< std::string, std::vector< std::string > > myActiveAssignments
username -&gt; roleNames
Definition: roleAssignmentStore.h:180
bool updateActiveAssignmentUserRoles(const std::string &username, const std::vector< std::string > &roleNames, std::string &outError)
Replaces one user&#39;s role list within the currently active assignment set in memory. Passing an empty roleNames vector removes the user entry. Changes are not persisted to disk until saveActiveAssignmentSet() is called.
std::map< std::string, std::string > myIdToFilePath
assignmentId -&gt; absolute file path
Definition: roleAssignmentStore.h:172
std::vector< std::string > savedAssignments(const std::string &username) const
Returns the role names saved for the given username in the active assignment set. Returns an empty ve...
std::string scenarioName
Value of the &quot;scenarioName&quot; field (informational).
Definition: roleAssignmentStore.h:21
std::string description
Optional description.
Definition: roleAssignmentStore.h:20
static std::string generateUuid()
Generates a random UUID in 8-4-4-4-12 lowercase hex format.
DtRoleAssignmentStore — process-wide singleton for saved username-to-role assignments.
Definition: roleAssignmentStore.h:47
std::map< std::string, std::string > myNameToId
name -&gt; assignmentId
Definition: roleAssignmentStore.h:173
tbb::spin_rw_mutex myMutex
Definition: roleAssignmentStore.h:169
Summary information for one saved assignment set file.
Definition: roleAssignmentStore.h:16
std::string definitionId
DefinitionId this assignment set is bound to.
Definition: roleAssignmentStore.h:22
std::vector< DtAssignmentSetSummary > listAssignmentSets() const
Returns summary information for all available assignment set files.
DtRoleAssignmentStore()=default
IMGUI_API void Value(const char *prefix, bool b)
std::string activeAssignmentSetName() const
Returns the name of the currently active assignment set, or an empty string if none.
std::atomic< uint64_t > myAssignmentGeneration
Definition: roleAssignmentStore.h:182
uint64_t assignmentGeneration() const
Monotonically increasing counter incremented whenever assignment metadata or active-assignment state ...
static std::vector< std::string > scanDirectory(const std::string &dir)
Returns full file paths for every *.json file found directly in dir.
std::string myActiveSetDescription
Definition: roleAssignmentStore.h:178
void clearActiveAssignment()
Activates the reserved &quot;default&quot; assignment set and cached mapping.
bool loadAssignmentSet(const std::string &name)
Loads and activates the named assignment set. Replaces any previously active set. Compatibility helpe...
std::string myActiveSetId
Definition: roleAssignmentStore.h:176
bool saveActiveAssignmentSet(const std::map< std::string, std::vector< std::string >> &assignments, std::string &outError)
Saves (overwrites) the active assignment set&#39;s username -&gt; roleNames map.
static DtRoleAssignmentStore & getInstance()
Returns the process-wide singleton instance.
std::string createAssignmentSet(const std::string &name, const std::string &description, const std::string &scenarioName, const std::string &definitionId, const std::map< std::string, std::vector< std::string >> &assignments, std::string &outError)
Creates a new saved assignment set and activates it.
bool updateAssignmentSetUserRoles(const std::string &assignmentId, const std::string &username, const std::vector< std::string > &roleNames, std::string &outError)
Replaces one user&#39;s role list within a saved assignment set. Passing an empty roleNames vector remove...
bool deleteAssignmentSet(const std::string &assignmentId, std::string &outError)
Deletes a saved assignment set by stable assignmentId.
std::string activeAssignmentSetDescription() const
Returns the description of the currently active assignment set, or empty string.
std::string name
Value of the &quot;name&quot; field in the file.
Definition: roleAssignmentStore.h:19
bool loadAssignmentSetById(const std::string &assignmentId, std::string &outError)
Loads and activates the assignment set by stable assignmentId. Replaces any previously active set...
bool getAssignmentSetById(const std::string &assignmentId, Json::Value &outJson, std::string &outError) const
Reads and returns one saved assignment set by stable assignmentId.
std::map< std::string, DtAssignmentSetSummary > myIndex
assignmentId -&gt; summary
Definition: roleAssignmentStore.h:174
std::string activeAssignmentSetId() const
Returns the stable assignmentId of the currently active set, or empty string if none.

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)