ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::user_action::UserProfile Class Reference

Represent an application user profile, allowing to configure basic informations like the action bindings. More...

#include <UserProfile.hpp>

Collaboration diagram for ecstasy::integration::user_action::UserProfile:

Public Types

using Id = size_t
 User identifier type.
 

Public Member Functions

 UserProfile (Id id=0) noexcept
 Construct a new user profile with an associated id.
 
constexpr ActionBindingsgetActionBindings () noexcept
 Get the Action Bindings.
 
constexpr const ActionBindingsgetActionBindings () const noexcept
 Get the Action Bindings.
 
constexpr Id getId () const noexcept
 Get the Id of the profile.
 
constexpr void setId (Id id) noexcept
 Change the user ID.
 
toml::table dump () const noexcept
 Dump the user profile informations as a toml table.
 
bool load (const toml::table &infos) noexcept
 Load a given toml table representing a user profile.
 

Static Public Attributes

static constexpr Id All = static_cast<Id>(-1)
 Constant id matching any user ID.
 

Private Attributes

Id _id
 
ActionBindings _actionBindings
 

Detailed Description

Represent an application user profile, allowing to configure basic informations like the action bindings.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-25)

Definition at line 27 of file UserProfile.hpp.

Member Typedef Documentation

◆ Id

User identifier type.

Definition at line 30 of file UserProfile.hpp.

Constructor & Destructor Documentation

◆ UserProfile()

ecstasy::integration::user_action::UserProfile::UserProfile ( Id  id = 0)
inlinenoexcept

Construct a new user profile with an associated id.

Parameters
[in]idUser identifier.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-25)

Definition at line 43 of file UserProfile.hpp.

Member Function Documentation

◆ dump()

toml::table ecstasy::integration::user_action::UserProfile::dump ( ) const
noexcept

Dump the user profile informations as a toml table.

Returns
toml::table Toml representation of the user profile.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-29)

Definition at line 16 of file UserProfile.cpp.

17 {
18 toml::table table;
19
20 table.emplace("id", static_cast<long long int>(_id));
21 table.emplace("bindings", _actionBindings.dump());
22 return table;
23 }
toml::table dump() const noexcept
Dump the bindings as a toml table.
std::pair< iterator, bool > emplace(KeyType &&key, ValueArgs &&... args)

◆ getActionBindings() [1/2]

constexpr const ActionBindings & ecstasy::integration::user_action::UserProfile::getActionBindings ( ) const
inlineconstexprnoexcept

Get the Action Bindings.

Returns
const ActionBindings& A reference to the ActionBindings object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-25)

Definition at line 68 of file UserProfile.hpp.

69 {
70 return _actionBindings;
71 }

◆ getActionBindings() [2/2]

constexpr ActionBindings & ecstasy::integration::user_action::UserProfile::getActionBindings ( )
inlineconstexprnoexcept

Get the Action Bindings.

Returns
ActionBinding& A reference to the ActionBindings object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-25)

Definition at line 55 of file UserProfile.hpp.

56 {
57 return _actionBindings;
58 }

◆ getId()

constexpr Id ecstasy::integration::user_action::UserProfile::getId ( ) const
inlineconstexprnoexcept

Get the Id of the profile.

Note
Starts at 0.
Returns
Id Profile id.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-02)

Definition at line 83 of file UserProfile.hpp.

84 {
85 return _id;
86 }

◆ load()

bool ecstasy::integration::user_action::UserProfile::load ( const toml::table infos)
noexcept

Load a given toml table representing a user profile.

See the format of dump().

Warning
This method clear the internal data.
Parameters
[in]infosUser profile dump.
Returns
bool Whether the load succeed or not.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-30)

User Id

User bindings

Definition at line 25 of file UserProfile.cpp.

26 {
28 auto id = infos.get("id");
29 if (id && id->is_integer())
30 _id = static_cast<UserProfile::Id>(id->as_integer()->get());
31
33 auto bindings = infos.get("bindings");
34 if (bindings && bindings->is_table())
35 _actionBindings.load(*bindings->as_table());
36 return true;
37 }
bool load(const toml::table &bindings) noexcept
Load a given toml table representing a list of bindings.
node * get(std::string_view key) noexcept

◆ setId()

constexpr void ecstasy::integration::user_action::UserProfile::setId ( Id  id)
inlineconstexprnoexcept

Change the user ID.

Parameters
[in]idnew id.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-05)

Definition at line 96 of file UserProfile.hpp.

97 {
98 _id = id;
99 }

Member Data Documentation

◆ _actionBindings

ActionBindings ecstasy::integration::user_action::UserProfile::_actionBindings
private

Definition at line 129 of file UserProfile.hpp.

◆ _id

Id ecstasy::integration::user_action::UserProfile::_id
private

Definition at line 127 of file UserProfile.hpp.

◆ All

constexpr Id ecstasy::integration::user_action::UserProfile::All = static_cast<Id>(-1)
staticconstexpr

Constant id matching any user ID.

Definition at line 33 of file UserProfile.hpp.


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