ScummVM API documentation
qd_condition_data.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef QDENGINE_QDCORE_QD_CONDITION_DATA_H
23 #define QDENGINE_QDCORE_QD_CONDITION_DATA_H
24 
25 #include "common/std/vector.h"
26 
27 #include "qdengine/parser/xml_fwd.h"
28 
29 namespace QDEngine {
30 
32 public:
33  enum data_t {
34  DATA_INT,
35  DATA_FLOAT,
36  DATA_STRING
37  };
38 
40  qdConditionData(data_t data_type, int data_size = 0);
41  qdConditionData(const qdConditionData &data);
42  ~qdConditionData();
43 
44  qdConditionData &operator = (const qdConditionData &data);
45 
46  data_t type() const {
47  return _type;
48  }
49  void set_type(data_t tp) {
50  _type = tp;
51  }
52 
53  int get_int(int index = 0) const {
54  return reinterpret_cast<const int32 *>(&*_data.begin())[index];
55  }
56  bool put_int(int value, int index = 0) {
57  if (static_cast<int>(_data.size()) >= static_cast<int>((index - 1) * sizeof(int32))) {
58  reinterpret_cast<int32 *>(&*_data.begin())[index] = value;
59  return true;
60  }
61 
62  return false;
63  }
64 
65  float get_float(int index = 0) const {
66  return reinterpret_cast<const float *>(&*_data.begin())[index];
67  }
68  bool put_float(float value, int index = 0) {
69  if (static_cast<int>(_data.size()) >=
70  static_cast<int>((index - 1) * sizeof(float))) {
71  reinterpret_cast<float *>(&*_data.begin())[index] = value;
72  return true;
73  }
74 
75  return false;
76  }
77 
78  const char *get_string() const {
79  if (!_data.empty())
80  return &*_data.begin();
81  else
82  return NULL;
83  }
84 
85  bool put_string(const char *str) {
86  if (alloc_data(strlen(str) + 1)) {
87  Common::strlcpy(&*_data.begin(), str, _data.size());
88  return true;
89  }
90 
91  return false;
92  }
93 
94  bool load_script(const xml::tag *p);
95  bool save_script(Common::WriteStream &fh, int indent = 0) const;
96 
97  bool alloc_data(int size);
98 
99 private:
100 
101  data_t _type;
102  Std::vector<char> _data;
103 };
104 
105 } // namespace QDEngine
106 
107 #endif // QDENGINE_QDCORE_QD_CONDITION_DATA_H
Definition: stream.h:77
size_t strlcpy(char *dst, const char *src, size_t size)
iterator begin()
Definition: array.h:374
bool empty() const
Definition: array.h:351
XML тег.
Definition: xml_tag.h:33
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: qd_condition_data.h:31
size_type size() const
Definition: array.h:315