Colobot
|
#include <CBotVar.h>
Public Member Functions | |
virtual void | SetIdent (long UniqId) |
Associates an unique identifier to class instance. More... | |
virtual void | ConstructorSet () |
Called after constructor has been called. More... | |
CBotVar * | GetStaticVar () |
If this is a static class variable, return the static var from the class. More... | |
virtual void | Update (void *pUser) |
Call the class update function. More... | |
void | SetUniqNum (long n) |
Set unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem. More... | |
long | GetUniqNum () |
Return unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem. More... | |
![]() | |
virtual | ~CBotLinkedList () |
Destructor. Be careful, destroys the whole linked list! More... | |
CBotVar * | GetNext () |
Returns the next variable in the linked list. More... | |
void | AddNext (CBotVar *elem) |
Appends a new element at the end of the linked list. More... | |
Static Public Member Functions | |
static long | NextUniqNum () |
Generate next unique identifier. More... | |
Protected Attributes | |
CBotToken * | m_token |
The corresponding token, defines the variable name. More... | |
CBotTypResult | m_type |
Type of value. More... | |
InitType | m_binit |
Initialization status. More... | |
CBotVarClass * | m_pMyThis |
Corresponding this element (TODO: ?) More... | |
void * | m_pUserPtr |
User pointer if specified. More... | |
bool | m_bStatic |
true if the variable is static (for classes) More... | |
ProtectionLevel | m_mPrivate |
Element protection level - public, protected or private (for classes) More... | |
CBotInstr * | m_InitExpr |
Expression describing initial value. More... | |
CBotInstr * | m_LimExpr |
Expression describing array limit. More... | |
long | m_ident |
Identifier. More... | |
![]() | |
CBotVar * | m_next |
Static Protected Attributes | |
static long | m_identcpt = 0 |
TODO: ? More... | |
Friends | |
class | CBotStack |
class | CBotCStack |
class | CBotInstrCall |
class | CBotProgram |
class | CBotClass |
class | CBotVarClass |
class | CBotVarPointer |
class | CBotVarArray |
Creation / destruction | |
CBotVar () | |
Constructor. Do not call directly, use CBotVar::Create() More... | |
virtual | ~CBotVar () |
Destructor. Do not call directly, use CBotVar::Destroy() More... | |
static CBotVar * | Create (const std::string &name, CBotTypResult type) |
Creates a new variable from a type described by CBotTypResult. More... | |
static CBotVar * | Create (const std::string &name, CBotClass *pClass) |
Creates a new variable of a given class type. More... | |
static CBotVar * | Create (const CBotToken &name, CBotType type) |
Creates a new variable of a given type. More... | |
static CBotVar * | Create (const CBotToken &name, CBotTypResult type) |
Create a new variable of a given type described by CBotTypResult. More... | |
static CBotVar * | Create (const std::string &name, CBotType type, CBotClass *pClass) |
Create a new variable of a given type of given class instance. More... | |
static CBotVar * | Create (CBotVar *pVar) |
Create a new variable of the same type and name as another one. More... | |
static void | Destroy (CBotVar *var) |
Destroy a variable. More... | |
User pointer | |
void | SetUserPtr (void *pUser) |
Set a custom pointer associated with this variable. More... | |
void * | GetUserPtr () |
Returns the custom pointer associated with this variable. More... | |
Variable name and type | |
enum | GetTypeMode { NORMAL = 0, CLASS_AS_POINTER = 1, CLASS_AS_INTRINSIC = 2 } |
Mode for GetType() and GetTypResult() More... | |
std::string | GetName () |
Returns the name of the variable. More... | |
void | SetName (const std::string &name) |
SetName Changes the name of the variable. More... | |
CBotToken * | GetToken () |
Returns the CBotToken this variable is associated with. More... | |
CBotType | GetType (GetTypeMode mode=GetTypeMode::NORMAL) |
GetType Returns the base type of the variable (CBotType) More... | |
CBotTypResult | GetTypResult (GetTypeMode mode=GetTypeMode::NORMAL) |
Returns the complete type of the variable (CBotTypResult) More... | |
void | SetType (CBotTypResult &type) |
Change type of this variable. More... | |
virtual void | SetClass (CBotClass *pClass) |
Set class this variable is instance of. More... | |
virtual CBotClass * | GetClass () |
Return class this variable is instance of. More... | |
Initialization status | |
enum | InitType : int { InitType::UNDEF = 0, InitType::DEF = 1, InitType::IS_POINTER = 2, InitType::IS_NAN = 999 } |
Variable initialization status. More... | |
void | SetInit (InitType initType) |
Changes variable init status. More... | |
InitType | GetInit () const |
Returns the current init state of the variable. More... | |
bool | IsUndefined () const |
Checks if the variable is currently "undefined". More... | |
bool | IsDefined () const |
Checks if the variable is currently "defined". More... | |
bool | IsNAN () const |
Checks if the variable is currently NAN. More... | |
Class member properties | |
enum | ProtectionLevel { ProtectionLevel::Public = 0, ProtectionLevel::ReadOnly = 1, ProtectionLevel::Protected = 2, ProtectionLevel::Private = 3 } |
Class member protection level (public/protected/private) More... | |
void | SetStatic (bool bStatic) |
Marks the variable as "static". More... | |
bool | IsStatic () |
Checks if the variable is static. More... | |
void | SetPrivate (ProtectionLevel mPrivate) |
Sets variable protection level. More... | |
bool | IsPrivate (ProtectionLevel level=ProtectionLevel::Protected) |
Checks if the variable is accessible at the given protection level. More... | |
ProtectionLevel | GetPrivate () |
Get variable protection level. More... | |
bool | IsElemOfClass (const std::string &name) |
Check if a variable belongs to a class with a given name. More... | |
Class / array member access | |
virtual CBotVar * | GetItem (const std::string &name) |
Returns class member by name. More... | |
virtual CBotVar * | GetItemRef (int nIdent) |
Returns class member by unique ID. More... | |
virtual CBotVar * | GetItem (int index, bool grow=false) |
Returns element of the array by index. More... | |
virtual CBotVar * | GetItemList () |
Return all elements of this variable as a linked list. Works for both classes and arrays. More... | |
Value management | |
Always make sure that the variable has correct type before calling these functions! Some variable types have multiple getters/setters and do automatic conversion. Using one that is not implemented will result in a failed assertion. | |
void | SetVal (CBotVar *var) |
Set the value. More... | |
virtual void | Copy (CBotVar *pSrc, bool bName=true) |
Copy from another variable. More... | |
virtual void | SetValInt (int val, const std::string &name="") |
Set value as an integer. More... | |
virtual void | SetValFloat (float val) |
Set value as float. More... | |
virtual void | SetValString (const std::string &val) |
Set value as string. More... | |
virtual int | GetValInt () |
Get value as integer. More... | |
virtual float | GetValFloat () |
Get value as float. More... | |
virtual std::string | GetValString () |
Get value as string. More... | |
virtual void | SetPointer (CBotVar *p) |
Set value for pointer types. More... | |
virtual CBotVarClass * | GetPointer () |
Get value for pointer types. More... | |
Math operations | |
All these functions operate on the "left" variable, taking "right" as the argument. The C++ equivalent would be the +=, -=, *=, /= etc. operations | |
virtual void | Add (CBotVar *left, CBotVar *right) |
Addition. More... | |
virtual void | Sub (CBotVar *left, CBotVar *right) |
Subtraction. More... | |
virtual void | Mul (CBotVar *left, CBotVar *right) |
Multiplication. More... | |
virtual CBotError | Div (CBotVar *left, CBotVar *right) |
Division. More... | |
virtual CBotError | Modulo (CBotVar *left, CBotVar *right) |
Modulo (remainder of division) More... | |
virtual void | Power (CBotVar *left, CBotVar *right) |
Power. More... | |
Comparation functions | |
virtual bool | Lo (CBotVar *left, CBotVar *right) |
left < right More... | |
virtual bool | Hi (CBotVar *left, CBotVar *right) |
left > right More... | |
virtual bool | Ls (CBotVar *left, CBotVar *right) |
left <= right More... | |
virtual bool | Hs (CBotVar *left, CBotVar *right) |
left >= right More... | |
virtual bool | Eq (CBotVar *left, CBotVar *right) |
left == right More... | |
virtual bool | Ne (CBotVar *left, CBotVar *right) |
left != right More... | |
Logical or bitwise functions | |
Can be either depending on variable type. For boolean, those are logical functions, for int they are bitwise. | |
virtual void | And (CBotVar *left, CBotVar *right) |
left && right or left & right More... | |
virtual void | Or (CBotVar *left, CBotVar *right) |
left || right or left | right More... | |
virtual void | XOr (CBotVar *left, CBotVar *right) |
left ^ right (also for boolean!) More... | |
virtual void | Not () |
!this or ~this More... | |
Bitwise shift | |
virtual void | ASR (CBotVar *left, CBotVar *right) |
left >> right More... | |
virtual void | SR (CBotVar *left, CBotVar *right) |
left >>> right More... | |
virtual void | SL (CBotVar *left, CBotVar *right) |
left << right More... | |
Negation / increment / decrement | |
virtual void | Neg () |
-this More... | |
virtual void | Inc () |
++this More... | |
virtual void | Dec () |
–this More... | |
Save / restore state | |
virtual bool | Save0State (FILE *pf) |
Save common variable header (name, type, etc.) More... | |
virtual bool | Save1State (FILE *pf) |
Save variable data. More... | |
static bool | RestoreState (FILE *pf, CBotVar *&pVar) |
Restore variable. More... | |
A CBot variable.
|
strong |
Mode for GetType() and GetTypResult()
|
strong |
Variable initialization status.
Enumerator | |
---|---|
UNDEF |
the variable value is currently not defined |
DEF |
the variable value is defined |
IS_POINTER |
the variable value is as a pointer |
IS_NAN |
the variable value is NAN |
|
strong |
Class member protection level (public/protected/private)
Enumerator | |
---|---|
Public |
public variable |
ReadOnly |
read only (can't be set from CBot, only from the engine) |
Protected |
protected |
Private |
private |
CBot::CBotVar::CBotVar | ( | ) |
Constructor. Do not call directly, use CBotVar::Create()
|
virtual |
Destructor. Do not call directly, use CBotVar::Destroy()
|
static |
Creates a new variable from a type described by CBotTypResult.
name | Variable name |
type | Variable type |
Creates a new variable of a given class type.
This is equivalent to:
name | Variable name |
pClass | Class type |
Creates a new variable of a given type.
This is equivalent to:
name | Variable name token |
type | Variable type |
|
static |
Create a new variable of a given type described by CBotTypResult.
name | Variable name token |
type | Variable type |
|
static |
Create a new variable of a given type of given class instance.
This is equivalent to:
name | Variable name |
type | Variable type |
pClass | Class |
Create a new variable of the same type and name as another one.
Contents of the variable are NOT copied.
pVar | other variable to take type and name from |
|
static |
Destroy a variable.
var | variable to be destroyed |
|
virtual |
Associates an unique identifier to class instance.
Used only by classes
UniqId | New unique identifier |
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
void CBot::CBotVar::SetUserPtr | ( | void * | pUser | ) |
Set a custom pointer associated with this variable.
pUser | custom pointer to set |
void * CBot::CBotVar::GetUserPtr | ( | ) |
Returns the custom pointer associated with this variable.
std::string CBot::CBotVar::GetName | ( | ) |
Returns the name of the variable.
void CBot::CBotVar::SetName | ( | const std::string & | name | ) |
SetName Changes the name of the variable.
name | New name |
CBotToken * CBot::CBotVar::GetToken | ( | ) |
Returns the CBotToken this variable is associated with.
This token is either passed in CBotVar::Create() or created from name string
CBotType CBot::CBotVar::GetType | ( | GetTypeMode | mode = GetTypeMode::NORMAL | ) |
GetType Returns the base type of the variable (CBotType)
mode | Mode, see GetTypeMode enum |
CBotTypResult CBot::CBotVar::GetTypResult | ( | GetTypeMode | mode = GetTypeMode::NORMAL | ) |
Returns the complete type of the variable (CBotTypResult)
mode | Mode, see GetTypeMode enum |
void CBot::CBotVar::SetType | ( | CBotTypResult & | type | ) |
Change type of this variable.
type | new type |
|
virtual |
Set class this variable is instance of.
Used by instance variables, NOT class members
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
|
virtual |
Return class this variable is instance of.
Used by instance variables, NOT class members
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
void CBot::CBotVar::SetInit | ( | CBotVar::InitType | initType | ) |
Changes variable init status.
initType | New init status |
CBotVar::InitType CBot::CBotVar::GetInit | ( | ) | const |
Returns the current init state of the variable.
|
inline |
Checks if the variable is currently "undefined".
|
inline |
Checks if the variable is currently "defined".
|
inline |
Checks if the variable is currently NAN.
void CBot::CBotVar::SetStatic | ( | bool | bStatic | ) |
Marks the variable as "static".
Useful only for class members
bStatic | static or not |
bool CBot::CBotVar::IsStatic | ( | ) |
Checks if the variable is static.
Useful only for class members
void CBot::CBotVar::SetPrivate | ( | ProtectionLevel | mPrivate | ) |
Sets variable protection level.
Useful only for class members
mPrivate | New protection level |
bool CBot::CBotVar::IsPrivate | ( | ProtectionLevel | level = ProtectionLevel::Protected | ) |
Checks if the variable is accessible at the given protection level.
This means that the variable protection level is greater or equal to given level
level | Protection level to check access at |
CBotVar::ProtectionLevel CBot::CBotVar::GetPrivate | ( | ) |
Get variable protection level.
bool CBot::CBotVar::IsElemOfClass | ( | const std::string & | name | ) |
Check if a variable belongs to a class with a given name.
Works correctly with inheritance.
name | Class name to check |
|
virtual |
Called after constructor has been called.
This is used internally by the engine to mark the constructor as called.
This allows the destructor to be called later.
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
CBotVar * CBot::CBotVar::GetStaticVar | ( | ) |
If this is a static class variable, return the static var from the class.
|
virtual |
Call the class update function.
pUser | User pointer to pass to the update function |
Reimplemented in CBot::CBotVarPointer, and CBot::CBotVarClass.
void CBot::CBotVar::SetUniqNum | ( | long | n | ) |
Set unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem.
n | New identifier |
long CBot::CBotVar::GetUniqNum | ( | ) |
Return unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem.
|
static |
Generate next unique identifier.
Used by both variables (CBotVar) and functions (CBotFunction)
|
virtual |
Returns class member by name.
name | Name of member to get |
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
|
virtual |
Returns class member by unique ID.
nIdent | Unique ID of the class member to return |
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarPointer.
|
virtual |
Returns element of the array by index.
TODO: Appears to be also implemented in CBotVarClass, but I'm not sure what is it used for there. Looks like CBotVarArray stores data internally in CBotVarClass or something like that. Needs futher investigation.
index | Index of the element to get |
grow | true to grow the array automatically if the index is out of range |
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarArray.
|
virtual |
Return all elements of this variable as a linked list. Works for both classes and arrays.
Reimplemented in CBot::CBotVarClass, CBot::CBotVarArray, and CBot::CBotVarPointer.
void CBot::CBotVar::SetVal | ( | CBotVar * | var | ) |
Set the value.
var | Another variable to copy value from |
|
virtual |
Copy from another variable.
pSrc | Variable to copy from |
bName | true if you want to also copy the name |
Reimplemented in CBot::CBotVarArray, CBot::CBotVarClass, CBot::CBotVarBoolean, CBot::CBotVarFloat, CBot::CBotVarInt, CBot::CBotVarPointer, and CBot::CBotVarString.
|
virtual |
Set value as an integer.
This one should be used for boolean values, too
val | New value |
name | Used when you assign a constant value - makes the value appear as "name" instead of number in the debugger |
Reimplemented in CBot::CBotVarBoolean, CBot::CBotVarFloat, and CBot::CBotVarInt.
|
virtual |
Set value as float.
val | New value |
Reimplemented in CBot::CBotVarBoolean, CBot::CBotVarFloat, and CBot::CBotVarInt.
|
virtual |
|
virtual |
Get value as integer.
Reimplemented in CBot::CBotVarBoolean, CBot::CBotVarFloat, and CBot::CBotVarInt.
|
virtual |
Get value as float.
Reimplemented in CBot::CBotVarBoolean, CBot::CBotVarFloat, and CBot::CBotVarInt.
|
virtual |
Get value as string.
This one is supported by most types of variables.
Automatically converts the value to string if needed.
Reimplemented in CBot::CBotVarClass, CBot::CBotVarArray, CBot::CBotVarPointer, CBot::CBotVarBoolean, CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
|
virtual |
Set value for pointer types.
p | Variable to point to |
Reimplemented in CBot::CBotVarPointer, and CBot::CBotVarArray.
|
virtual |
Get value for pointer types.
Reimplemented in CBot::CBotVarClass, CBot::CBotVarPointer, and CBot::CBotVarArray.
Addition.
Reimplemented in CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
Subtraction.
Reimplemented in CBot::CBotVarFloat, and CBot::CBotVarInt.
Multiplication.
Reimplemented in CBot::CBotVarFloat, and CBot::CBotVarInt.
Division.
Reimplemented in CBot::CBotVarFloat, and CBot::CBotVarInt.
Modulo (remainder of division)
Reimplemented in CBot::CBotVarFloat, and CBot::CBotVarInt.
Power.
Reimplemented in CBot::CBotVarFloat, and CBot::CBotVarInt.
left < right
Reimplemented in CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
left > right
Reimplemented in CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
left <= right
Reimplemented in CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
left >= right
Reimplemented in CBot::CBotVarFloat, CBot::CBotVarInt, and CBot::CBotVarString.
left == right
Reimplemented in CBot::CBotVarClass, CBot::CBotVarPointer, CBot::CBotVarFloat, CBot::CBotVarInt, CBot::CBotVarBoolean, and CBot::CBotVarString.
left != right
Reimplemented in CBot::CBotVarClass, CBot::CBotVarPointer, CBot::CBotVarFloat, CBot::CBotVarInt, CBot::CBotVarBoolean, and CBot::CBotVarString.
left && right or left & right
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarBoolean.
left || right or left | right
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarBoolean.
left ^ right (also for boolean!)
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarBoolean.
|
virtual |
!this or ~this
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarBoolean.
left >> right
Reimplemented in CBot::CBotVarInt.
left << right
Reimplemented in CBot::CBotVarInt.
|
virtual |
-this
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarFloat.
|
virtual |
++this
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarFloat.
|
virtual |
–this
Reimplemented in CBot::CBotVarInt, and CBot::CBotVarFloat.
|
virtual |
Save common variable header (name, type, etc.)
pf | file pointer |
Reimplemented in CBot::CBotVarInt.
|
virtual |
Save variable data.
Overriden in child classes
pf | file pointer |
Reimplemented in CBot::CBotVarInt, CBot::CBotVarFloat, CBot::CBotVarPointer, CBot::CBotVarClass, CBot::CBotVarArray, CBot::CBotVarBoolean, and CBot::CBotVarString.
|
static |
Restore variable.
pf | file pointer | |
[out] | pVar | Pointer to recieve the variable |
|
protected |
The corresponding token, defines the variable name.
|
protected |
Type of value.
|
protected |
Initialization status.
|
protected |
Corresponding this element (TODO: ?)
|
protected |
User pointer if specified.
|
protected |
true if the variable is static (for classes)
|
protected |
Element protection level - public, protected or private (for classes)
|
protected |
Expression describing initial value.
|
protected |
Expression describing array limit.
|
protected |
Identifier.
|
staticprotected |
TODO: ?