ManaPlus
Public Member Functions
anonymous_namespace{playerrelations.cpp}::PlayerConfSerialiser Class Reference
Inheritance diagram for anonymous_namespace{playerrelations.cpp}::PlayerConfSerialiser:
ConfigurationListManager< std::pair< std::string, PlayerRelation * >, std::map< std::string, PlayerRelation * > * >

Public Member Functions

 PlayerConfSerialiser ()
 
ConfigurationObjectwriteConfigItem (const std::pair< std::string, PlayerRelation * > &value, ConfigurationObject *const cobj) const
 
std::map< std::string, PlayerRelation * > * readConfigItem (const ConfigurationObject *const cobj, std::map< std::string, PlayerRelation * > *const container) const
 
- Public Member Functions inherited from ConfigurationListManager< std::pair< std::string, PlayerRelation * >, std::map< std::string, PlayerRelation * > * >
 ConfigurationListManager ()
 
virtual ~ConfigurationListManager ()
 

Detailed Description

Definition at line 83 of file playerrelations.cpp.

Constructor & Destructor Documentation

◆ PlayerConfSerialiser()

anonymous_namespace{playerrelations.cpp}::PlayerConfSerialiser::PlayerConfSerialiser ( )
inline

Definition at line 88 of file playerrelations.cpp.

89  { }

Member Function Documentation

◆ readConfigItem()

std::map<std::string, PlayerRelation *>* anonymous_namespace{playerrelations.cpp}::PlayerConfSerialiser::readConfigItem ( const ConfigurationObject *const  obj,
std::map< std::string, PlayerRelation * > *const  container 
) const
inlinevirtual

Reads a value from a configuration object

Parameters
objThe configuration object to read from
containerThe container to insert the object to

Implements ConfigurationListManager< std::pair< std::string, PlayerRelation * >, std::map< std::string, PlayerRelation * > * >.

Definition at line 110 of file playerrelations.cpp.

113  {
114  if (cobj == nullptr ||
115  container == nullptr)
116  {
117  return container;
118  }
119  const std::string name = cobj->getValue(NAME, "");
120  if (name.empty())
121  return container;
122 
123  if ((*container)[name] == nullptr)
124  {
125  const int v = cobj->getValueInt(RELATION,
127 
128  (*container)[name] = new PlayerRelation(
129  static_cast<RelationT>(v));
130  }
131  // otherwise ignore the duplicate entry
132 
133  return container;
134  }
#define CAST_S32
Definition: cast.h:30
@ NEUTRAL
Definition: relation.h:31
static const char *const RELATION
static const char *const NAME
Relation ::T RelationT
Definition: relation.h:39

References CAST_S32, NAME, Relation::NEUTRAL, and RELATION.

◆ writeConfigItem()

ConfigurationObject* anonymous_namespace{playerrelations.cpp}::PlayerConfSerialiser::writeConfigItem ( const std::pair< std::string, PlayerRelation * > &  value,
ConfigurationObject *const  obj 
) const
inlinevirtual

Writes a value into a configuration object

Parameters
valueThe value to write out
objThe configuation object to write to
Returns
obj, or otherwise NULL to indicate that this option should be skipped

Implements ConfigurationListManager< std::pair< std::string, PlayerRelation * >, std::map< std::string, PlayerRelation * > * >.

Definition at line 93 of file playerrelations.cpp.

96  {
97  if (cobj == nullptr ||
98  value.second == nullptr)
99  {
100  return nullptr;
101  }
102  cobj->setValue(NAME, value.first);
103  cobj->setValue(RELATION, toString(
104  CAST_S32(value.second->mRelation)));
105 
106  return cobj;
107  }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References CAST_S32, NAME, RELATION, and Catch::toString().


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