A CBot variable.
More...
#include <CBotVar.h>
|
class | CBotStack |
|
class | CBotCStack |
|
class | CBotInstrCall |
|
class | CBotProgram |
|
class | CBotClass |
|
class | CBotVarClass |
|
class | CBotVarPointer |
|
class | CBotVarArray |
|
|
void | SetUserPtr (void *pUser) |
| Set a custom pointer associated with this variable. More...
|
|
void * | GetUserPtr () |
| Returns the custom pointer associated with this variable. More...
|
|
|
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.
|
| operator int () |
|
| operator float () |
|
| operator std::string () |
|
void | operator= (const CBotVar &var) |
|
void | operator= (int x) |
|
void | operator= (float x) |
|
void | operator= (const std::string &x) |
|
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...
|
|
|
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...
|
|
|
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...
|
|
Variable initialization status.
- See also
- GetInit()
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
|
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 |
( |
| ) |
|
CBot::CBotVar::CBotVar |
( |
const CBotToken & |
name | ) |
|
CBot::CBotVar::~CBotVar |
( |
| ) |
|
|
virtual |
Creates a new variable from a type described by CBotTypResult.
- Parameters
-
name | Variable name |
type | Variable type |
CBotVar * CBot::CBotVar::Create |
( |
const std::string & |
name, |
|
|
CBotClass * |
pClass |
|
) |
| |
|
static |
Creates a new variable of a given class type.
This is equivalent to:
- Parameters
-
name | Variable name |
pClass | Class type |
Creates a new variable of a given type.
This is equivalent to:
- Parameters
-
name | Variable name token |
type | Variable type |
Create a new variable of a given type described by CBotTypResult.
- Parameters
-
name | Variable name token |
type | Variable type |
Create a new variable of a given type of given class instance.
This is equivalent to:
Create(name, CBotTypResult(type, pClass))
- Parameters
-
name | Variable name |
type | Variable type |
pClass | Class |
- Returns
Create a new variable of the same type and name as another one.
Contents of the variable are NOT copied.
- Parameters
-
pVar | other variable to take type and name from |
void CBot::CBotVar::Destroy |
( |
CBotVar * |
var | ) |
|
|
static |
Destroy a variable.
- Parameters
-
var | variable to be destroyed |
void CBot::CBotVar::SetIdent |
( |
long |
UniqId | ) |
|
|
virtual |
void CBot::CBotVar::SetUserPtr |
( |
void * |
pUser | ) |
|
Set a custom pointer associated with this variable.
- Parameters
-
pUser | custom pointer to set |
void * CBot::CBotVar::GetUserPtr |
( |
| ) |
|
Returns the custom pointer associated with this variable.
- Returns
- A pointer set with SetUserPtr()
std::string CBot::CBotVar::GetName |
( |
| ) |
|
Returns the name of the variable.
- Returns
- The name of the variable, empty string if unknown
void CBot::CBotVar::SetName |
( |
const std::string & |
name | ) |
|
SetName Changes the name of the variable.
- Parameters
-
Returns the CBotToken this variable is associated with.
This token is either passed in CBotVar::Create() or created from name string
GetType Returns the base type of the variable (CBotType)
- Parameters
-
mode | Mode, see GetTypeMode enum |
Returns the complete type of the variable (CBotTypResult)
- Parameters
-
mode | Mode, see GetTypeMode enum |
Change type of this variable.
- Parameters
-
void CBot::CBotVar::SetClass |
( |
CBotClass * |
pClass | ) |
|
|
virtual |
Changes variable init status.
- Parameters
-
Returns the current init state of the variable.
bool CBot::CBotVar::IsUndefined |
( |
| ) |
const |
|
inline |
bool CBot::CBotVar::IsDefined |
( |
| ) |
const |
|
inline |
Checks if the variable is currently "defined".
- See also
- InitType::DEF
bool CBot::CBotVar::IsNAN |
( |
| ) |
const |
|
inline |
Checks if the variable is currently NAN.
- Returns
- InitType::NAN
void CBot::CBotVar::SetStatic |
( |
bool |
bStatic | ) |
|
Marks the variable as "static".
Useful only for class members
- Parameters
-
bool CBot::CBotVar::IsStatic |
( |
| ) |
|
Checks if the variable is static.
Useful only for class members
- Returns
- true for static variables
Sets variable protection level.
Useful only for class members
- Parameters
-
mPrivate | New protection level |
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
- Parameters
-
level | Protection level to check access at |
Get variable protection level.
- Returns
- 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.
- Parameters
-
- Returns
- true if this variable name matches any member of given class or any of the parent classes
void CBot::CBotVar::ConstructorSet |
( |
| ) |
|
|
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.
- Returns
- Static variable from CBotClass instance if this variable is static, or this otherwise
void CBot::CBotVar::Update |
( |
void * |
pUser | ) |
|
|
virtual |
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.
- Parameters
-
long CBot::CBotVar::GetUniqNum |
( |
| ) |
|
Return unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem.
- Returns
- unique identifier
- See also
- SetUniqNum()
long CBot::CBotVar::NextUniqNum |
( |
| ) |
|
|
static |
CBotVar * CBot::CBotVar::GetItem |
( |
const std::string & |
name | ) |
|
|
virtual |
CBotVar * CBot::CBotVar::GetItemRef |
( |
int |
nIdent | ) |
|
|
virtual |
CBotVar * CBot::CBotVar::GetItem |
( |
int |
index, |
|
|
bool |
grow = false |
|
) |
| |
|
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.
- Parameters
-
index | Index of the element to get |
grow | true to grow the array automatically if the index is out of range |
- Returns
- CBotVar representing the array element, or nullptr on error (for example going out of range)
Reimplemented in CBot::CBotVarClass, and CBot::CBotVarArray.
CBotVar * CBot::CBotVar::GetItemList |
( |
| ) |
|
|
virtual |
void CBot::CBotVar::SetVal |
( |
CBotVar * |
var | ) |
|
Set the value.
- Parameters
-
var | Another variable to copy value from |
void CBot::CBotVar::Copy |
( |
CBotVar * |
pSrc, |
|
|
bool |
bName = true |
|
) |
| |
|
virtual |
Copy from another variable.
- Parameters
-
pSrc | Variable to copy from |
bName | true if you want to also copy the name |
Reimplemented in CBot::CBotVarValue< T, type >, CBot::CBotVarValue< std::string, CBotTypString >, CBot::CBotVarValue< bool, type >, CBot::CBotVarValue< float, type >, CBot::CBotVarValue< int, type >, CBot::CBotVarArray, CBot::CBotVarClass, CBot::CBotVarPointer, and CBot::CBotVarInt.
void CBot::CBotVar::SetValInt |
( |
int |
val, |
|
|
const std::string & |
name = "" |
|
) |
| |
|
virtual |
Set value as an integer.
This one should be used for boolean values, too
- Parameters
-
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::CBotVarNumberBase< T, type >, CBot::CBotVarNumberBase< bool, CBotTypBoolean >, CBot::CBotVarNumberBase< float, type >, CBot::CBotVarNumberBase< int, type >, CBot::CBotVarString, and CBot::CBotVarInt.
void CBot::CBotVar::SetValFloat |
( |
float |
val | ) |
|
|
virtual |
void CBot::CBotVar::SetValString |
( |
const std::string & |
val | ) |
|
|
virtual |
Set value as string.
- Parameters
-
Reimplemented in CBot::CBotVarValue< T, type >, CBot::CBotVarValue< std::string, CBotTypString >, CBot::CBotVarValue< bool, type >, CBot::CBotVarValue< float, type >, CBot::CBotVarValue< int, type >, and CBot::CBotVarString.
int CBot::CBotVar::GetValInt |
( |
| ) |
|
|
virtual |
float CBot::CBotVar::GetValFloat |
( |
| ) |
|
|
virtual |
std::string CBot::CBotVar::GetValString |
( |
| ) |
|
|
virtual |
Get value as string.
This one is supported by most types of variables.
Automatically converts the value to string if needed.
- Returns
- Current value
Reimplemented in CBot::CBotVarValue< T, type >, CBot::CBotVarValue< std::string, CBotTypString >, CBot::CBotVarValue< bool, type >, CBot::CBotVarValue< float, type >, CBot::CBotVarValue< int, type >, CBot::CBotVarClass, CBot::CBotVarArray, CBot::CBotVarPointer, and CBot::CBotVarInt.
void CBot::CBotVar::SetPointer |
( |
CBotVar * |
p | ) |
|
|
virtual |
left == right
Reimplemented in CBot::CBotVarNumberBase< T, type >, CBot::CBotVarNumberBase< bool, CBotTypBoolean >, CBot::CBotVarNumberBase< float, type >, CBot::CBotVarNumberBase< int, type >, CBot::CBotVarClass, CBot::CBotVarPointer, and CBot::CBotVarString.
left != right
Reimplemented in CBot::CBotVarNumberBase< T, type >, CBot::CBotVarNumberBase< bool, CBotTypBoolean >, CBot::CBotVarNumberBase< float, type >, CBot::CBotVarNumberBase< int, type >, CBot::CBotVarClass, CBot::CBotVarPointer, and CBot::CBotVarString.
void CBot::CBotVar::Not |
( |
| ) |
|
|
virtual |
left >>> right
This is unsigned shift to right
Reimplemented in CBot::CBotVarInt.
void CBot::CBotVar::Neg |
( |
| ) |
|
|
virtual |
void CBot::CBotVar::Inc |
( |
| ) |
|
|
virtual |
void CBot::CBotVar::Dec |
( |
| ) |
|
|
virtual |
bool CBot::CBotVar::Save0State |
( |
FILE * |
pf | ) |
|
|
virtual |
Save common variable header (name, type, etc.)
- Parameters
-
- Returns
- false on write error
Reimplemented in CBot::CBotVarInt.
bool CBot::CBotVar::Save1State |
( |
FILE * |
pf | ) |
|
|
virtual |
bool CBot::CBotVar::RestoreState |
( |
FILE * |
pf, |
|
|
CBotVar *& |
pVar |
|
) |
| |
|
static |
Restore variable.
- Parameters
-
| pf | file pointer |
[out] | pVar | Pointer to recieve the variable |
- Returns
- false on read error
The corresponding token, defines the variable name.
Corresponding this element (TODO: ?)
void* CBot::CBotVar::m_pUserPtr |
|
protected |
bool CBot::CBotVar::m_bStatic |
|
protected |
true if the variable is static (for classes)
Element protection level - public, protected or private (for classes)
Expression describing initial value.
Expression describing array limit.
long CBot::CBotVar::m_ident |
|
protected |
long CBot::CBotVar::m_identcpt = 0 |
|
staticprotected |
The documentation for this class was generated from the following files:
- /build/colobot-4LMcse/colobot-0.1.8/src/CBot/CBotVar/CBotVar.h
- /build/colobot-4LMcse/colobot-0.1.8/src/CBot/CBotStack.cpp
- /build/colobot-4LMcse/colobot-0.1.8/src/CBot/CBotVar/CBotVar.cpp