VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
DtRoleAssignmentStore Class Reference

DtRoleAssignmentStore — process-wide singleton for saved username-to-role assignments.

At startup, initialize() scans a directory of JSON saved assignment files and builds an index. A specific set is activated via loadAssignmentSet(); the caller is responsible for applying the returned assignments to active sessions.

Saved assignment JSON format (one file per named set):

{
"assignmentId": "a031a7db-0872-40eb-a468-62641a28811f",
"definitionId": "6cc5fdf1-49f3-42dc-b75d-8dc22618cb83",
"name": "mondayTeam",
"description": "Morning class",
"scenarioName": "blue_vs_red",
"assignments": {
"alice": ["Blue Air Commander"],
"bob": ["Red Ground Commander"]
}
}

Thread safety: all public methods are safe to call from concurrent threads.

Public Member Functions

void initialize (const std::string &assignmentsDir)
 
std::vector
< DtAssignmentSetSummary > 
listAssignmentSets () const
 
bool getAssignmentSetById (const std::string &assignmentId, Json::Value &outJson, std::string &outError) const
 
bool loadAssignmentSetById (const std::string &assignmentId, std::string &outError)
 
bool loadAssignmentSet (const std::string &name)
 
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)
 
bool updateAssignmentSetDescription (const std::string &assignmentId, const std::string &description, std::string &outError)
 
bool updateAssignmentSetUserRoles (const std::string &assignmentId, const std::string &username, const std::vector< std::string > &roleNames, std::string &outError)
 
bool updateActiveAssignmentUserRoles (const std::string &username, const std::vector< std::string > &roleNames, std::string &outError)
 
bool deleteAssignmentSet (const std::string &assignmentId, std::string &outError)
 
bool saveActiveAssignmentSet (const std::map< std::string, std::vector< std::string >> &assignments, std::string &outError)
 
void clearActiveAssignment ()
 
std::string activeAssignmentSetId () const
 
std::string activeAssignmentSetName () const
 
std::string activeAssignmentSetDescription () const
 
std::string activeAssignmentDefinitionId () const
 
std::vector< std::string > savedAssignments (const std::string &username) const
 
std::map< std::string,
std::vector< std::string > > 
allSavedAssignments () const
 
uint64_t assignmentGeneration () const
 

Static Public Member Functions

static DtRoleAssignmentStore & getInstance ()
 

Private Member Functions

 DtRoleAssignmentStore ()=default
 

Static Private Member Functions

static std::vector< std::string > scanDirectory (const std::string &dir)
 
static std::string generateUuid ()
 
static bool readAssignmentFile (const std::string &filePath, Json::Value &outRoot, std::string &outError)
 
static bool writeAssignmentFile (const std::string &filePath, const Json::Value &root, std::string &outError)
 

Private Attributes

tbb::spin_rw_mutex myMutex
 
std::string myAssignmentsDir
 
std::map< std::string,
std::string > 
myIdToFilePath
 
std::map< std::string,
std::string > 
myNameToId
 
std::map< std::string,
DtAssignmentSetSummary > 
myIndex
 
std::string myActiveSetId
 
std::string myActiveSetName
 
std::string myActiveSetDescription
 
std::string myActiveDefinitionId
 
std::map< std::string,
std::vector< std::string > > 
myActiveAssignments
 
std::atomic< uint64_t > myAssignmentGeneration {0}
 

Constructor & Destructor Documentation

DtRoleAssignmentStore::DtRoleAssignmentStore ( )
privatedefault

Member Function Documentation

static DtRoleAssignmentStore& DtRoleAssignmentStore::getInstance ( )
static

Returns the process-wide singleton instance.

void DtRoleAssignmentStore::initialize ( const std::string &  assignmentsDir)

Scans assignmentsDir for *.json saved assignment files and builds the index. Ensures a reserved "default" assignment file exists in the folder. Must be called from main() before any background threads start. Logs a warning if assignmentsDir does not exist or contains no files; not an error.

std::vector<DtAssignmentSetSummary> DtRoleAssignmentStore::listAssignmentSets ( ) const

Returns summary information for all available assignment set files.

bool DtRoleAssignmentStore::getAssignmentSetById ( const std::string &  assignmentId,
Json::Value &  outJson,
std::string &  outError 
) const

Reads and returns one saved assignment set by stable assignmentId.

Returns
false if not found or the file cannot be read/parsed.
bool DtRoleAssignmentStore::loadAssignmentSetById ( const std::string &  assignmentId,
std::string &  outError 
)

Loads and activates the assignment set by stable assignmentId. Replaces any previously active set.

Returns
false if the ID is not found or the file cannot be read/parsed.
bool DtRoleAssignmentStore::loadAssignmentSet ( const std::string &  name)

Loads and activates the named assignment set. Replaces any previously active set. Compatibility helper that resolves name -> assignmentId and forwards to loadAssignmentSetById().

Returns
false if no set with that name was found in the index.
std::string DtRoleAssignmentStore::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.

Returns
new assignmentId on success, empty string on failure (outError populated).
bool DtRoleAssignmentStore::updateAssignmentSetDescription ( const std::string &  assignmentId,
const std::string &  description,
std::string &  outError 
)

Updates the saved assignment set description.

Returns
false if assignmentId is not found or write fails.
bool DtRoleAssignmentStore::updateAssignmentSetUserRoles ( const std::string &  assignmentId,
const std::string &  username,
const std::vector< std::string > &  roleNames,
std::string &  outError 
)

Replaces one user's role list within a saved assignment set. Passing an empty roleNames vector removes the user entry.

Returns
false if assignmentId is not found or write fails.
bool DtRoleAssignmentStore::updateActiveAssignmentUserRoles ( const std::string &  username,
const std::vector< std::string > &  roleNames,
std::string &  outError 
)

Replaces one user'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.

Returns
false if no active assignment set is selected.
bool DtRoleAssignmentStore::deleteAssignmentSet ( const std::string &  assignmentId,
std::string &  outError 
)

Deletes a saved assignment set by stable assignmentId.

Returns
false if assignmentId is not found or delete fails.
bool DtRoleAssignmentStore::saveActiveAssignmentSet ( const std::map< std::string, std::vector< std::string >> &  assignments,
std::string &  outError 
)

Saves (overwrites) the active assignment set's username -> roleNames map.

Returns
false if no assignment set is active or write fails.
void DtRoleAssignmentStore::clearActiveAssignment ( )

Activates the reserved "default" assignment set and cached mapping.

This is used when role-definition context changes and there should be no previously selected named assignment. The default assignment remains editable in memory but direct Save is intentionally disabled.

std::string DtRoleAssignmentStore::activeAssignmentSetId ( ) const

Returns the stable assignmentId of the currently active set, or empty string if none.

std::string DtRoleAssignmentStore::activeAssignmentSetName ( ) const

Returns the name of the currently active assignment set, or an empty string if none.

std::string DtRoleAssignmentStore::activeAssignmentSetDescription ( ) const

Returns the description of the currently active assignment set, or empty string.

std::string DtRoleAssignmentStore::activeAssignmentDefinitionId ( ) const

Returns the definitionId bound to the currently active assignment set, or empty string.

std::vector<std::string> DtRoleAssignmentStore::savedAssignments ( const std::string &  username) const

Returns the role names saved for the given username in the active assignment set. Returns an empty vector if no set is active or the username is not in the set.

std::map<std::string, std::vector<std::string> > DtRoleAssignmentStore::allSavedAssignments ( ) const

Returns a copy of the complete username -> roleNames map for the active set. Returns an empty map if no set is active.

uint64_t DtRoleAssignmentStore::assignmentGeneration ( ) const

Monotonically increasing counter incremented whenever assignment metadata or active-assignment state changes.

static std::vector<std::string> DtRoleAssignmentStore::scanDirectory ( const std::string &  dir)
staticprivate

Returns full file paths for every *.json file found directly in dir.

static std::string DtRoleAssignmentStore::generateUuid ( )
staticprivate

Generates a random UUID in 8-4-4-4-12 lowercase hex format.

static bool DtRoleAssignmentStore::readAssignmentFile ( const std::string &  filePath,
Json::Value &  outRoot,
std::string &  outError 
)
staticprivate

Reads one assignment file from disk.

static bool DtRoleAssignmentStore::writeAssignmentFile ( const std::string &  filePath,
const Json::Value &  root,
std::string &  outError 
)
staticprivate

Writes one assignment file to disk.

Member Data Documentation

tbb::spin_rw_mutex DtRoleAssignmentStore::myMutex
mutableprivate
std::string DtRoleAssignmentStore::myAssignmentsDir
private
std::map<std::string, std::string> DtRoleAssignmentStore::myIdToFilePath
private

assignmentId -> absolute file path

std::map<std::string, std::string> DtRoleAssignmentStore::myNameToId
private

name -> assignmentId

std::map<std::string, DtAssignmentSetSummary> DtRoleAssignmentStore::myIndex
private

assignmentId -> summary

std::string DtRoleAssignmentStore::myActiveSetId
private
std::string DtRoleAssignmentStore::myActiveSetName
private
std::string DtRoleAssignmentStore::myActiveSetDescription
private
std::string DtRoleAssignmentStore::myActiveDefinitionId
private
std::map<std::string, std::vector<std::string> > DtRoleAssignmentStore::myActiveAssignments
private

username -> roleNames

std::atomic<uint64_t> DtRoleAssignmentStore::myAssignmentGeneration {0}
private

The documentation for this class was generated from the following file:

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)