Colobot
parserparam.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "graphics/core/color.h"
28 
29 #include "graphics/engine/camera.h"
30 #include "graphics/engine/planet_type.h"
32 #include "graphics/engine/water.h"
33 
34 #include "math/point.h"
35 
36 #include "object/drive_type.h"
37 #include "object/mission_type.h"
38 #include "object/object_type.h"
39 #include "object/tool_type.h"
40 
41 #include <string>
42 #include <vector>
43 #include <memory>
44 
45 class CLevelParserLine;
46 
47 class CLevelParserParam;
48 using CLevelParserParamUPtr = std::unique_ptr<CLevelParserParam>;
49 using CLevelParserParamVec = std::vector<CLevelParserParamUPtr>;
50 
52 {
53 public:
55 
56  CLevelParserParam(int value);
57  CLevelParserParam(float value);
58  CLevelParserParam(std::string value);
59  CLevelParserParam(bool value);
65  CLevelParserParam(CLevelParserParamVec&& array);
67  CLevelParserParam(std::string name, std::string value);
70  CLevelParserParam(std::string name, bool empty);
71 
73 
74  int AsInt();
75  float AsFloat();
76  std::string AsString();
77  bool AsBool();
78  std::string AsPath(const std::string defaultDir);
79  Gfx::Color AsColor();
80  Math::Vector AsPoint();
81  ObjectType AsObjectType();
82  DriveType AsDriveType();
83  ToolType AsToolType();
84  Gfx::WaterType AsWaterType();
85  Gfx::EngineObjectType AsTerrainType();
86  int AsBuildFlag();
87  int AsResearchFlag();
88  Gfx::PyroType AsPyroType();
89  Gfx::CameraType AsCameraType();
90  MissionType AsMissionType();
91  const CLevelParserParamVec& AsArray();
92  Gfx::PlanetType AsPlanetType();
94 
96 
97  int AsInt(int def);
98  float AsFloat(float def);
99  std::string AsString(std::string def);
100  bool AsBool(bool def);
101  std::string AsPath(const std::string defaultDir, std::string def);
102  Gfx::Color AsColor(Gfx::Color def);
103  Math::Vector AsPoint(Math::Vector def);
104  ObjectType AsObjectType(ObjectType def);
105  DriveType AsDriveType(DriveType def);
106  ToolType AsToolType(ToolType def);
107  Gfx::WaterType AsWaterType(Gfx::WaterType def);
108  Gfx::EngineObjectType AsTerrainType(Gfx::EngineObjectType def);
109  int AsBuildFlag(int def);
110  int AsResearchFlag(int def);
111  Gfx::PyroType AsPyroType(Gfx::PyroType def);
112  Gfx::CameraType AsCameraType(Gfx::CameraType def);
113  MissionType AsMissionType(MissionType def);
115 
117  void SetLine(CLevelParserLine* line);
120 
121  std::string GetName();
122  std::string GetValue();
123  bool IsDefined();
124 
125  static const std::string FromObjectType(ObjectType value);
126 
127 private:
128  void ParseArray();
129  void LoadArray();
130 
131  template<typename T> T Cast(std::string value, std::string requestedType);
132  template<typename T> T Cast(std::string requestedType);
133 
134  std::string ToPath(std::string path, const std::string defaultDir);
135  ObjectType ToObjectType(std::string value);
136  DriveType ToDriveType(std::string value);
137  ToolType ToToolType(std::string value);
138  Gfx::WaterType ToWaterType(std::string value);
139  Gfx::EngineObjectType ToTerrainType(std::string value);
140  int ToBuildFlag(std::string value);
141  int ToResearchFlag(std::string value);
142  Gfx::PyroType ToPyroType(std::string value);
143  Gfx::CameraType ToCameraType(std::string value);
144  MissionType ToMissionType(std::string value);
145 
146  const std::string FromCameraType(Gfx::CameraType value);
147 
148 private:
149  CLevelParserLine* m_line = nullptr;
150  bool m_empty = false;
151  std::string m_name;
152  std::string m_value;
153  CLevelParserParamVec m_array;
154 };
CameraType
Type of camera.
Definition: camera.h:44
Camera handling - CCamera class.
EngineObjectType
Class of graphics engine object.
Definition: engine.h:171
WaterType
Mode of water display.
Definition: water.h:45
Point struct and related functions.
ObjectType enum.
Definition: parserline.h:37
PyroType
Type of pyro effect.
Definition: pyro_type.h:34
Color structs and related functions.
Definition: parserparam.h:51
void SetLine(CLevelParserLine *line)
Set line this param is part of.
Definition: parserparam.cpp:108
2D point
Definition: point.h:50
int AsInt()
Get value (throws exception if not found or unable to process)
Definition: parserparam.cpp:153
PyroType enum.
ObjectType
Type of game object.
Definition: object_type.h:33
CLevelParserParam(int value)
Create param with given value.
Definition: parserparam.cpp:49
3D (3x1) vector
Definition: vector.h:53
RGBA color.
Definition: color.h:39
Water rendering - CWater class.
PlanetType
Type of planet which determines when it is displayed.
Definition: planet_type.h:29
CLevelParserLine * GetLine()
Get line this param is part of.
Definition: parserparam.cpp:113