Colobot
CBotVarClass.h
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 
20 #pragma once
21 
22 #include "CBot/CBotVar/CBotVar.h"
23 
24 #include <set>
25 
26 namespace CBot
27 {
28 
34 class CBotVarClass : public CBotVar
35 {
36 public:
40  CBotVarClass(const CBotToken& name, const CBotTypResult& type);
44  ~CBotVarClass();
45 
46  void Copy(CBotVar* pSrc, bool bName = true) override;
47 
48  void SetClass(CBotClass* pClass) override;
49  CBotClass* GetClass() override;
50 
51  CBotVar* GetItem(const std::string& name) override;
52  CBotVar* GetItemRef(int nIdent) override;
53  CBotVar* GetItem(int n, bool bExtend) override;
54  CBotVar* GetItemList() override;
55  std::string GetValString() override;
56 
57  bool Save1State(FILE* pf) override;
58 
59  void Update(void* pUser) override;
60 
62 
63 
67  void IncrementUse();
68 
72  void DecrementUse();
73 
75 
76  CBotVarClass* GetPointer() override;
77 
79 
80 
81  void SetIdent(long n) override;
82 
88  static CBotVarClass* Find(long id);
89 
91 
92  bool Eq(CBotVar* left, CBotVar* right) override;
93  bool Ne(CBotVar* left, CBotVar* right) override;
94 
95  void ConstructorSet() override;
96 
97 private:
99  static std::set<CBotVarClass*> m_instances;
101  CBotClass* m_pClass;
103  CBotVarClass* m_pParent;
105  CBotVar* m_pVar;
107  int m_CptUse;
109  long m_ItemIdent;
111  bool m_bConstructor;
112 
113  friend class CBotVar;
114  friend class CBotVarPointer;
115 };
116 
117 } // namespace CBot
void IncrementUse()
Increment reference counter.
Definition: CBotVarClass.cpp:368
CBotVar * GetItem(const std::string &name) override
Returns class member by name.
Definition: CBotVarClass.cpp:243
CBotVar * GetItemList() override
Return all elements of this variable as a linked list. Works for both classes and arrays...
Definition: CBotVarClass.cpp:304
void SetClass(CBotClass *pClass) override
Set class this variable is instance of.
Definition: CBotVarClass.cpp:155
void Update(void *pUser) override
Call the class update function.
Definition: CBotVarClass.cpp:231
void SetIdent(long n) override
Associates an unique identifier to class instance.
Definition: CBotVarClass.cpp:149
A CBot class definition.
Definition: CBotClass.h:105
~CBotVarClass()
Destructor. Do not call directly, use CBotVar::Destroy()
Definition: CBotVarClass.cpp:84
A CBot variable.
Definition: CBotVar.h:42
bool Ne(CBotVar *left, CBotVar *right) override
left != right
Definition: CBotVarClass.cpp:451
void DecrementUse()
Decrement reference counter.
Definition: CBotVarClass.cpp:374
static CBotVarClass * Find(long id)
Finds a class instance by unique identifier.
Definition: CBotVarClass.cpp:423
bool Save1State(FILE *pf) override
Save variable data.
Definition: CBotVarClass.cpp:468
CBotClass * GetClass() override
Return class this variable is instance of.
Definition: CBotVarClass.cpp:225
CBotVar subclass for managing pointers to classes (CBotTypPointer)
Definition: CBotVarPointer.h:30
CBotVarClass * GetPointer() override
Get value for pointer types.
Definition: CBotVarClass.cpp:417
CBotVar * GetItemRef(int nIdent) override
Returns class member by unique ID.
Definition: CBotVarClass.cpp:258
std::string GetValString() override
Get value as string.
Definition: CBotVarClass.cpp:310
void ConstructorSet() override
Called after constructor has been called.
Definition: CBotVarClass.cpp:99
void Copy(CBotVar *pSrc, bool bName=true) override
Copy from another variable.
Definition: CBotVarClass.cpp:105
Class to define the complete type of a variable.
Definition: CBotTypResult.h:47
CBot engine.
Definition: CBotCallMethode.cpp:28
bool Eq(CBotVar *left, CBotVar *right) override
left == right
Definition: CBotVarClass.cpp:434
CBotVarClass(const CBotToken &name, const CBotTypResult &type)
Constructor. Do not call directly, use CBotVar::Create()
Definition: CBotVarClass.cpp:39
CBotVar subclass for managing classes (CBotTypClass, CBotTypIntrinsic)
Definition: CBotVarClass.h:34
Class representing one token of a program.
Definition: CBotToken.h:80