Mania++
 All Classes Functions Variables Pages
Map.h
1 #ifndef MAP_H_
2 #define MAP_H_
3 
4 #include <map>
5 #include <boost/any.hpp>
6 
7 #include "../GbxRemote/Response/GbxResponse.h"
8 #include "../Utils/Parameter.h"
9 
10 //* Map
14 struct Map
15 {
16  // === Mania++ information ===
17  int Id = 0;
19  // === Basic information ===
20  std::string UId;
21  std::string Name;
22  std::string FileName;
23  std::string Environment;
24  std::string Author;
26  int GoldTime;
29  std::string MapType;
30  std::string MapStyle;
32  // === Detailed information ===
33  std::string Mood;
34  int BronzeTime;
35  int SilverTime;
36  int AuthorTime;
38  bool LapRace;
39  int NbLaps;
42  std::map<std::string, boost::any> Additionals;
47  Map()
48  {
49 
50  }
51 
57  Map(std::map<std::string, GbxResponseParameter> serverStruct)
58  {
59  if(serverStruct.find("UId") != serverStruct.end())
60  {
61  setBasicInfo(serverStruct);
62  }
63  }
64 
70  void MapDetailed(std::map<std::string, GbxResponseParameter> serverStruct)
71  {
72  if(serverStruct.find("Mood") != serverStruct.end())
73  {
74  setDetailedInfo(serverStruct);
75  }
76  }
77 
83  void CopyDetailedMap(Map map)
84  {
85  if(!map.Mood.empty())
86  {
87  Mood = map.Mood;
88  BronzeTime = map.BronzeTime;
89  SilverTime = map.SilverTime;
90  AuthorTime = map.AuthorTime;
91 
92  LapRace = map.LapRace;
93  NbLaps = map.NbLaps;
95  }
96  }
97 
103  void SetId(int id)
104  {
105  Id = id;
106  }
107 
114  void UpdateAdditional(std::string key, boost::any value)
115  {
116  if(Additionals.find(key) != Additionals.end())
117  {
118  Additionals[key] = value;
119  }
120  else
121  {
122  Additionals.insert(std::pair<std::string, boost::any>(key, value));
123  }
124  }
125 
126 private:
132  void setBasicInfo(std::map<std::string, GbxResponseParameter> serverStruct)
133  {
134  UId = serverStruct.find("UId")->second.GetString();
135  Name = serverStruct.find("Name")->second.GetString();
136  FileName = serverStruct.find("FileName")->second.GetString();
137  Environment = serverStruct.find("Environnement")->second.GetString();
138  Author = serverStruct.find("Author")->second.GetString();
139 
140  GoldTime = atoi(serverStruct.find("GoldTime")->second.GetString().c_str());
141  CopperPrice = atoi(serverStruct.find("CopperPrice")->second.GetString().c_str());
142 
143  MapType = serverStruct.find("MapType")->second.GetString();
144  MapStyle = serverStruct.find("MapStyle")->second.GetString();
145  }
146 
152  void setDetailedInfo(std::map<std::string, GbxResponseParameter> serverStruct)
153  {
154  setBasicInfo(serverStruct);
155 
156  Mood = serverStruct.find("Mood")->second.GetString();
157  BronzeTime = atoi(serverStruct.find("BronzeTime")->second.GetString().c_str());
158  SilverTime = atoi(serverStruct.find("SilverTime")->second.GetString().c_str());
159  AuthorTime = atoi(serverStruct.find("AuthorTime")->second.GetString().c_str());
160 
161  std::istringstream(serverStruct.find("LapRace")->second.GetString()) >> LapRace;
162  NbLaps = atoi(serverStruct.find("NbLaps")->second.GetString().c_str());
163  NbCheckpoints = atoi(serverStruct.find("NbCheckpoints")->second.GetString().c_str());
164  }
165 };
166 
167 #endif // MAP_H_
void setBasicInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the basic map information from the struct.
Definition: Map.h:132
Map()
Constructs a Map object without input.
Definition: Map.h:47
std::string Mood
Map mood (setting).
Definition: Map.h:33
bool LapRace
Map is multi-lap.
Definition: Map.h:38
std::map< std::string, boost::any > Additionals
Additional parameters.
Definition: Map.h:42
std::string FileName
File name.
Definition: Map.h:22
int NbCheckpoints
Number of checkpoints.
Definition: Map.h:40
int NbLaps
Number of laps.
Definition: Map.h:39
std::string MapStyle
Map style (self-entered).
Definition: Map.h:30
int CopperPrice
Copper price.
Definition: Map.h:27
Map(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Map.h:57
Contains all information about a map in easy-to-use format.
Definition: Map.h:14
void CopyDetailedMap(Map map)
Copies information from map object.
Definition: Map.h:83
int GoldTime
Time of the gold medal.
Definition: Map.h:26
std::string Author
Login of the author.
Definition: Map.h:24
std::string MapType
Type of the map.
Definition: Map.h:29
std::string UId
Unique map identifier.
Definition: Map.h:20
int BronzeTime
Time of the bronze medal.
Definition: Map.h:34
void MapDetailed(std::map< std::string, GbxResponseParameter > serverStruct)
Formats a server response into a usable form.
Definition: Map.h:70
int SilverTime
Time of the silver medal.
Definition: Map.h:35
std::string Name
Map name.
Definition: Map.h:21
void SetId(int id)
Set database identifier value.
Definition: Map.h:103
std::string Environment
Game environment.
Definition: Map.h:23
void UpdateAdditional(std::string key, boost::any value)
Updates (or inserts) key with value.
Definition: Map.h:114
int AuthorTime
Time set by the author.
Definition: Map.h:36
void setDetailedInfo(std::map< std::string, GbxResponseParameter > serverStruct)
Sets the detailed map information from the struct.
Definition: Map.h:152
int Id
Map identifier (on database).
Definition: Map.h:17