Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.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 <object/object.h>
28 #include <graphics/core/color.h>
29 #include <graphics/engine/water.h>
30 #include <graphics/engine/pyro.h>
31 #include <math/point.h>
32 
33 #include <string>
34 
35 class CLevelParserLine;
36 
38 {
39 public:
41 
42  CLevelParserParam(int value);
43  CLevelParserParam(float value);
44  CLevelParserParam(std::string value);
45  CLevelParserParam(bool value);
51  CLevelParserParam(const std::vector<CLevelParserParam*>& value);
53  CLevelParserParam(std::string name, std::string value);
56  CLevelParserParam(std::string name, bool empty);
57 
59 
61 
62  int AsInt();
63  float AsFloat();
64  std::string AsString();
65  bool AsBool();
66  std::string AsPath(const std::string defaultDir);
67  Gfx::Color AsColor();
68  Math::Vector AsPoint();
69  ObjectType AsObjectType();
70  DriveType AsDriveType();
71  ToolType AsToolType();
72  Gfx::WaterType AsWaterType();
73  Gfx::EngineObjectType AsTerrainType();
74  int AsBuildFlag();
75  int AsResearchFlag();
76  Gfx::PyroType AsPyroType();
77  Gfx::CameraType AsCameraType();
78  const std::vector<CLevelParserParam*>& AsArray();
80 
82 
83  int AsInt(int def);
84  float AsFloat(float def);
85  std::string AsString(std::string def);
86  bool AsBool(bool def);
87  std::string AsPath(const std::string defaultDir, std::string def);
88  Gfx::Color AsColor(Gfx::Color def);
89  Math::Vector AsPoint(Math::Vector def);
90  ObjectType AsObjectType(ObjectType def);
91  DriveType AsDriveType(DriveType def);
92  ToolType AsToolType(ToolType def);
93  Gfx::WaterType AsWaterType(Gfx::WaterType def);
95  int AsBuildFlag(int def);
96  int AsResearchFlag(int def);
97  Gfx::PyroType AsPyroType(Gfx::PyroType def);
98  Gfx::CameraType AsCameraType(Gfx::CameraType def);
100 
102  void SetLine(CLevelParserLine* line);
105 
106  std::string GetName();
107  std::string GetValue();
108  bool IsDefined();
109 
110 private:
111  void ParseArray();
112  void LoadArray();
113 
114  template<typename T> T Cast(std::string value, std::string requestedType);
115  template<typename T> T Cast(std::string requestedType);
116 
117  std::string ToPath(std::string path, const std::string defaultDir);
118  ObjectType ToObjectType(std::string value);
119  DriveType ToDriveType(std::string value);
120  ToolType ToToolType(std::string value);
121  Gfx::WaterType ToWaterType(std::string value);
122  Gfx::EngineObjectType ToTerrainType(std::string value);
123  int ToBuildFlag(std::string value);
124  int ToResearchFlag(std::string value);
125  Gfx::PyroType ToPyroType(std::string value);
126  Gfx::CameraType ToCameraType(std::string value);
127 
128  const std::string FromObjectType(ObjectType value);
129  const std::string FromCameraType(Gfx::CameraType value);
130 
131 private:
132  CLevelParserLine* m_line;
133  bool m_empty;
134  std::string m_name;
135  std::string m_value;
136  std::vector<CLevelParserParam*> m_array;
137 };
CameraType
Type of camera.
Definition: camera.h:45
EngineObjectType
Class of graphics engine object.
Definition: engine.h:168
WaterType
Mode of water display.
Definition: water.h:91
Point struct and related functions.
Fire effect rendering - CPyro class.
Definition: parserline.h:33
PyroType
Type of pyro effect.
Definition: pyro.h:55
Color structs and related functions.
Definition: parserparam.h:37
ObjectType
Type of game object.
Definition: object.h:51
void SetLine(CLevelParserLine *line)
Set line this param is part of.
Definition: parserparam.cpp:54
2D point
Definition: point.h:49
int AsInt()
Get value (throws exception if not found or unable to process)
Definition: parserparam.cpp:98
CObject - base class for all game objects.
CLevelParserParam(int value)
Create param with given value.
Definition: parserparam.cpp:939
3D (3x1) vector
Definition: vector.h:52
RGBA color.
Definition: color.h:38
Water rendering - CWater class.
CLevelParserLine * GetLine()
Get line this param is part of.
Definition: parserparam.cpp:59