MAGE  v0.171.0
Matthias Advanced Game Engine
mage::VariableScript Class Reference

#include <variable_script.hpp>

Inheritance diagram for mage::VariableScript:
mage::Resource< VariableScript >

Public Member Functions

 VariableScript (std::wstring fname, bool import=true)
 
 VariableScript (const VariableScript &variable_script)=delete
 
 VariableScript (VariableScript &&variable_script) noexcept
 
virtual ~VariableScript ()
 
VariableScriptoperator= (const VariableScript &variable_script)=delete
 
VariableScriptoperator= (VariableScript &&variable_script) noexcept
 
void ImportScript ()
 
void ImportScript (const std::filesystem::path &path)
 
void ExportScript () const
 
void ExportScript (const std::filesystem::path &path) const
 
bool empty () const noexcept
 
std::size_t size () const noexcept
 
template<typename T = void>
bool Contains (std::string_view name) const noexcept
 
template<typename T >
void Add (std::string name, T value)
 
void Remove (std::string_view name)
 
void RemoveAll () noexcept
 
template<typename T >
const T * GetValue (std::string_view name) const
 
template<typename T >
void SetValue (std::string_view name, T value)
 
- Public Member Functions inherited from mage::Resource< VariableScript >
 Resource (std::wstring guid) noexcept
 
 Resource (const Resource &resource)=delete
 
 Resource (Resource &&resource) noexcept
 
virtual ~Resource ()
 
Resourceoperator= (const Resource &resource)=delete
 
Resourceoperator= (Resource &&resource) noexcept
 
const std::wstring_view GetGuid () const noexcept
 
bool IsFileResource () const
 
const std::filesystem::path GetPath () const
 

Private Attributes

ValueMap m_variables
 

Detailed Description

A class of variable scripts.

Constructor & Destructor Documentation

◆ VariableScript() [1/3]

mage::VariableScript::VariableScript ( std::wstring  fname,
bool  import = true 
)
explicit

Constructs a variable script.

Parameters
[in]fnameThe filename (the globally unique identifier).
[in]importFlag indicating whether the variables of the variable script need to be imported.
Exceptions
ExceptionFailed to import the variable script from file (only possible if import is equal to true).

◆ VariableScript() [2/3]

mage::VariableScript::VariableScript ( const VariableScript variable_script)
delete

Constructs a variable script from the given variable script.

Parameters
[in]variable_scriptA reference to the variable script to copy.

◆ VariableScript() [3/3]

mage::VariableScript::VariableScript ( VariableScript &&  variable_script)
noexcept

Constructs a variable script by moving the given variable script.

Parameters
[in]variable_scriptA reference to the variable script to move.

◆ ~VariableScript()

mage::VariableScript::~VariableScript ( )
virtualdefault

Destruct this variable script.

Member Function Documentation

◆ Add()

template<typename T >
void mage::VariableScript::Add ( std::string  name,
value 
)

Adds the given variable to this variable script.

Template Parameters
TThe type of the variable.
Parameters
[in]nameThe name of the variable.
[in]valueThe value of the variable.

◆ Contains()

template<typename T = void>
bool mage::VariableScript::Contains ( std::string_view  name) const
noexcept

Checks whether this variable script contains a variable with the given name and type (if specified).

Template Parameters
TThe type of the variable.
Parameters
[in]nameThe name of the variable.
Returns
true if this variable script has a variable with the given name. false otherwise.

◆ empty()

bool mage::VariableScript::empty ( ) const
noexcept

Checks whether this variable script is empty.

Returns
true if this variable script is empty. false otherwise.

◆ ExportScript() [1/2]

void mage::VariableScript::ExportScript ( ) const

Exports this variable script to the file of this variable script.

Exceptions
ExceptionFailed to export the variable script to file.

◆ ExportScript() [2/2]

void mage::VariableScript::ExportScript ( const std::filesystem::path &  path) const

Exports this variable script to the file associated with the given path.

Parameters
[in]pathA reference to the path.
Exceptions
ExceptionFailed to export the variable script to file.

◆ GetValue()

template<typename T >
const T* mage::VariableScript::GetValue ( std::string_view  name) const

Returns the value of the given variable of this variable script.

Template Parameters
TThe type of the variable.
Parameters
[in]nameThe name of the variable.
Returns
nullptr if this variable script does not contain a variable corresponding to the given name.
A pointer to the value of the variable.
Exceptions
std::bad_variant_accessThe variable corresponding to the given name has a different type.

◆ ImportScript() [1/2]

void mage::VariableScript::ImportScript ( )

Imports this variable script from the file of this variable script.

Exceptions
ExceptionFailed to import the variable script from file.

◆ ImportScript() [2/2]

void mage::VariableScript::ImportScript ( const std::filesystem::path &  path)

Imports this variable script from the file associated with the given path.

Parameters
[in]pathA reference to the path.
Exceptions
ExceptionFailed to import the variable script from file.

◆ operator=() [1/2]

VariableScript& mage::VariableScript::operator= ( const VariableScript variable_script)
delete

Copies the given variable script to this variable script.

Parameters
[in]variable_scriptA reference to the variable script to copy.
Returns
A reference to the copy of the given variable script (i.e. this variable script).

◆ operator=() [2/2]

VariableScript & mage::VariableScript::operator= ( VariableScript &&  variable_script)
noexcept

Moves the given variable script to this variable script.

Parameters
[in]variable_scriptA reference to the variable script to move.
Returns
A reference to the moved variable script (i.e. this variable script).

◆ Remove()

void mage::VariableScript::Remove ( std::string_view  name)

Removes the given variable from this variable script.

Parameters
[in]nameThe name of the variable.

◆ RemoveAll()

void mage::VariableScript::RemoveAll ( )
noexcept

Removes all variables from this variable script.

◆ SetValue()

template<typename T >
void mage::VariableScript::SetValue ( std::string_view  name,
value 
)

Sets the value of the given variable in this variable script.

Template Parameters
TThe type of the variable.
Parameters
[in]nameThe name of the variable.
[in]valueThe value of the variable.
Note
Nothing happens if this variable script does not contain a variable corresponding to the given name.

◆ size()

std::size_t mage::VariableScript::size ( ) const
noexcept

Returns the number of variables in this variable script.

Returns
The number of variables in this variable script.

Member Data Documentation

◆ m_variables

ValueMap mage::VariableScript::m_variables
private

A map containing the variables of this variable script.