Loading...
Searching...
No Matches
CBot::CBotVarClass Class Reference

CBotVar subclass for managing classes (::CBotTypClass, ::CBotTypIntrinsic). More...

`#include <src/CBot/CBotVar/CBotVarClass.h>`

Inheritance diagram for CBot::CBotVarClass:
[legend]

## Public Member Functions

| CBotVarClass (const CBotToken &name, const CBotTypResult &type)
| Constructor. Do not call directly, use CBotVar::Create().
| ~CBotVarClass ()
| Destructor. Do not call directly, use CBotVar::Destroy().
void | Copy (CBotVar *pSrc, bool bName=true) override
| Copy from another variable.
void | SetClass (CBotClass *pClass) override
| Set class this variable is instance of.
CBotClass * | GetClass () override
| Return class this variable is instance of.
CBotVar * | GetItem (const std::string &name) override
| Returns class member by name.
CBotVar * | GetItemRef (int nIdent) override
| Returns class member by unique ID.
CBotVar * | GetItem (int n, bool bExtend) override
| Returns element of the array by index.
CBotVar * | GetItemList () override
| Return all elements of this variable as a linked list. Works for both classes and arrays.
std::string | GetValString () const override
| Get value as string.
bool | Save1State (std::ostream &ostr) override
| Save variable data.
void | Update (void *pUser) override
| Call the class update function.
const std::string & | GetName ()
| Returns the name of the variable.
void | SetName (const std::string &name)
| SetName Changes the name of the variable.
CBotToken * | GetToken ()
| Returns the CBotToken this variable is associated with.
CBotType | GetType (GetTypeMode mode=GetTypeMode::NORMAL) const
| GetType Returns the base type of the variable (::CBotType).
CBotTypResult | GetTypResult (GetTypeMode mode=GetTypeMode::NORMAL)
| Returns the complete type of the variable (CBotTypResult).
void | SetType (CBotTypResult &type)
| Change type of this variable.
void | SetInit (InitType initType)
| Changes variable init status.
InitType | GetInit () const
| Returns the current init state of the variable.
bool | IsUndefined () const
| Checks if the variable is currently "undefined".
bool | IsDefined () const
| Checks if the variable is currently "defined".
void | SetStatic (bool bStatic)
| Marks the variable as "static".
bool | IsStatic ()
| Checks if the variable is static.
void | SetPrivate (ProtectionLevel mPrivate)
| Sets variable protection level.
bool | IsPrivate (ProtectionLevel level=ProtectionLevel::Protected)
| Checks if the variable is accessible at the given protection level.
ProtectionLevel | GetPrivate ()
| Get variable protection level.
bool | IsElemOfClass (const std::string &name)
| Check if a variable belongs to a class with a given name.
CBotVar * | GetStaticVar ()
| If this is a static class variable, return the static var from the class.
void | SetUniqNum (long n)
| Set unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem.
long | GetUniqNum ()
| Return unique identifier of this variable Note: For classes, this is unique within the class only - see CBotClass:AddItem.
virtual bool | Save0State (std::ostream &ostr)
| Save common variable header (name, type, etc.).
| CBotVar ()
| Constructor. Do not call directly, use CBotVar::Create().
| CBotVar (const CBotToken &name)
| Constructor. Do not call directly, use CBotVar::Create().
virtual | ~CBotVar ()
| Destructor. Do not call directly, use CBotVar::Destroy().
void | SetUserPtr (void *pUser)
| Set a custom pointer associated with this variable.
void * | GetUserPtr ()
| Returns the custom pointer associated with this variable.
| operator bool ()
| Set the value.
| operator signed char ()
| Set the value.
| operator short ()
| Set the value.
| operator uint32_t ()
| Set the value.
| operator int ()
| Set the value.
| operator long ()
| Set the value.
| operator float ()
| Set the value.
| operator double ()
| Set the value.
| operator std::string ()
| Set the value.
void | operator= (const CBotVar &var)
| Set the value.
void | operator= (signed char x)
| Set the value.
void | operator= (short x)
| Set the value.
void | operator= (uint32_t x)
| Set the value.
void | operator= (int x)
| Set the value.
void | operator= (long x)
| Set the value.
void | operator= (float x)
| Set the value.
void | operator= (double x)
| Set the value.
void | operator= (const std::string &x)
| Set the value.
void | SetVal (CBotVar *var)
| Set the value.
virtual void | SetValByte (signed char val)
| Set the value.
virtual void | SetValShort (short val)
| Set the value.
virtual void | SetValChar (uint32_t val)
| Set the value.
virtual void | SetValInt (int val, const std::string &name="")
| Set value as an integer.
virtual void | SetValLong (long val)
| Set the value.
virtual void | SetValFloat (float val)
| Set value as float.
virtual void | SetValDouble (double val)
| Set the value.
virtual void | SetValString (const std::string &val)
| Set value as string.
virtual signed char | GetValByte () const
| Set the value.
virtual short | GetValShort () const
| Set the value.
virtual uint32_t | GetValChar () const
| Set the value.
virtual int | GetValInt () const
| Get value as integer.
virtual long | GetValLong () const
| Set the value.
virtual float | GetValFloat () const
| Get value as float.
virtual double | GetValDouble () const
| Set the value.
virtual void | SetPointer (CBotVar *p)
| Set value for pointer types.
virtual void | Add (CBotVar *left, CBotVar *right)
| Addition.
virtual void | Sub (CBotVar *left, CBotVar *right)
| Subtraction.
virtual void | Mul (CBotVar *left, CBotVar *right)
| Multiplication.
virtual CBotError | Div (CBotVar *left, CBotVar *right)
| Division.
virtual CBotError | Modulo (CBotVar *left, CBotVar *right)
| Modulo (remainder of division).
virtual void | Power (CBotVar *left, CBotVar *right)
| Power.
virtual bool | Lo (CBotVar *left, CBotVar *right)
| left < right
virtual bool | Hi (CBotVar *left, CBotVar *right)
| left > right
virtual bool | Ls (CBotVar *left, CBotVar *right)
| left <= right
virtual bool | Hs (CBotVar *left, CBotVar *right)
| left >= right
virtual void | And (CBotVar *left, CBotVar *right)
| left && right or left & right
virtual void | Or (CBotVar *left, CBotVar *right)
| left || right or left | right
virtual void | XOr (CBotVar *left, CBotVar *right)
| left ^ right (also for boolean!)
virtual void | Not ()
| !this or ~this
virtual void | ASR (CBotVar *left, CBotVar *right)
| left >> right
virtual void | SR (CBotVar *left, CBotVar *right)
| left >>> right
virtual void | SL (CBotVar *left, CBotVar *right)
| left << right
virtual void | Neg ()
| -this
virtual void | Inc ()
| ++this
virtual void | Dec ()
| –this
Public Member Functions inherited from CBot::CBotLinkedList< CBotVar >
virtual | ~CBotLinkedList ()
| Destructor. Be careful, destroys the whole linked list!
CBotVar * | GetNext ()
| Returns the next variable in the linked list.
void | AddNext (CBotVar *elem)
| Appends a new element at the end of the linked list.

## Unique instance identifier

class | CBotVar
| List of all class instances - first.
class | CBotVarPointer
| List of all class instances - first.
void | SetIdent (long n) override
| List of all class instances - first.
bool | Eq (CBotVar *left, CBotVar *right) override
| List of all class instances - first.
bool | Ne (CBotVar *left, CBotVar *right) override
| List of all class instances - first.
void | ConstructorSet () override
| List of all class instances - first.
static CBotVarClass * | Find (long id)
| Finds a class instance by unique identifier.

## Reference counter

void | IncrementUse ()
| Increment reference counter.
void | DecrementUse ()
| Decrement reference counter.
CBotVarClass * | GetPointer () override
| Increment reference counter.

## Additional Inherited Members

enum class | GetTypeMode { NORMAL = 0 , CLASS_AS_POINTER = 1 , CLASS_AS_INTRINSIC = 2 }
| Mode for GetType() and GetTypResult(). More...
enum class | InitType : int { UNDEF = 0 , DEF = 1 , IS_POINTER = 2 }
| Variable initialization status. More...
enum class | ProtectionLevel { Public = 0 , ReadOnly = 1 , Protected = 2 , Private = 3 }
| Class member protection level (public/protected/private). More...
static long | NextUniqNum ()
| Generate next unique identifier.
static bool | RestoreState (std::istream &istr, CBotVar *&pVar)
| Restore variable.
static CBotVar * | Create (const std::string &name, CBotTypResult type)
| Creates a new variable from a type described by CBotTypResult.
static CBotVar * | Create (const std::string &name, CBotClass *pClass)
| Creates a new variable of a given class type.
static CBotVar * | Create (const CBotToken &name, CBotType type)
| Creates a new variable of a given type.
static CBotVar * | Create (const CBotToken &name, CBotTypResult type)
| Create a new variable of a given type described by CBotTypResult.
static CBotVar * | Create (const std::string &name, CBotType type, CBotClass *pClass)
| Create a new variable of a given type of given class instance.
static CBotVar * | Create (CBotVar *pVar)
| Create a new variable of the same type and name as another one.
static void | Destroy (CBotVar *var)
| Destroy a variable.
CBotToken *const | m_token
| The corresponding token, defines the variable name.
CBotTypResult | m_type
| Type of value.
InitType | m_binit
| Initialization status.
CBotVarClass * | m_pMyThis
| Corresponding this element (TODO: ?).
void * | m_pUserPtr
| User pointer if specified.
bool | m_bStatic
| true if the variable is static (for classes)
ProtectionLevel | m_mPrivate
| Element protection level - public, protected or private (for classes).
CBotInstr * | m_InitExpr
| Expression describing initial value.
CBotInstr * | m_LimExpr
| Expression describing array limit.
long | m_ident
| Identifier.
Protected Attributes inherited from CBot::CBotLinkedList< CBotVar >
CBotVar * | m_next
static long | m_identcpt = 0
| TODO: ?

## Detailed Description

CBotVar subclass for managing classes (::CBotTypClass, ::CBotTypIntrinsic).

## Constructor & Destructor Documentation

## CBotVarClass()

CBot::CBotVarClass::CBotVarClass | ( | const CBotToken & | name,
|  | const CBotTypResult & | type )

Constructor. Do not call directly, use CBotVar::Create().

## ~CBotVarClass()

CBot::CBotVarClass::~CBotVarClass | ( |  | ) |

Destructor. Do not call directly, use CBotVar::Destroy().

## Member Function Documentation

## Copy()

void CBot::CBotVarClass::Copy | ( | CBotVar * | pSrc,
|  | bool | bName = true )

override virtual

Copy from another variable.

Parameters

  pSrc | Variable to copy from
  bName | true if you want to also copy the name

Reimplemented from CBot::CBotVar.

## SetClass()

void CBot::CBotVarClass::SetClass | ( | CBotClass * | pClass | ) |

override virtual

Set class this variable is instance of.

Used by instance variables, NOT class members

Reimplemented from CBot::CBotVar.

## GetClass()

CBotClass * CBot::CBotVarClass::GetClass | ( |  | ) |

override virtual

Return class this variable is instance of.

Used by instance variables, NOT class members

Reimplemented from CBot::CBotVar.

## GetItem() [1/2]

CBotVar * CBot::CBotVarClass::GetItem | ( | const std::string & | name | ) |

override virtual

Returns class member by name.

Parameters

  name | Name of member to get

Returns
  CBotVar representing the class member

Reimplemented from CBot::CBotVar.

## GetItemRef()

CBotVar * CBot::CBotVarClass::GetItemRef | ( | int | nIdent | ) |

override virtual

Returns class member by unique ID.

Parameters

  nIdent | Unique ID of the class member to return

Returns
  CBotVar representing the class member

See also
  GetUniqNum()

Reimplemented from CBot::CBotVar.

## GetItem() [2/2]

CBotVar * CBot::CBotVarClass::GetItem | ( | int | index,
|  | bool | grow )

override 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 from CBot::CBotVar.

## GetItemList()

CBotVar * CBot::CBotVarClass::GetItemList | ( |  | ) |

override virtual

Return all elements of this variable as a linked list. Works for both classes and arrays.

Returns
  CBotVar representing the first object in the linked list. Use CBotVar::GetNext() to access next ones.

Reimplemented from CBot::CBotVar.

## GetValString()

std::string CBot::CBotVarClass::GetValString | ( |  | ) | const

override 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 from CBot::CBotVar.

## Save1State()

bool CBot::CBotVarClass::Save1State | ( | std::ostream & | ostr | ) |

override virtual

Save variable data.

Overriden in child classes

Parameters

  ostr | Output stream

Returns
  false on write error

Reimplemented from CBot::CBotVar.

## Update()

void CBot::CBotVarClass::Update | ( | void * | pUser | ) |

override virtual

Call the class update function.

Parameters

  pUser | User pointer to pass to the update function

See also
  CBotClass::SetUpdateFunc()

Reimplemented from CBot::CBotVar.

## IncrementUse()

void CBot::CBotVarClass::IncrementUse | ( |  | ) |

Increment reference counter.

## DecrementUse()

void CBot::CBotVarClass::DecrementUse | ( |  | ) |

Decrement reference counter.

## GetPointer()

CBotVarClass * CBot::CBotVarClass::GetPointer | ( |  | ) |

override virtual

Increment reference counter.

Reimplemented from CBot::CBotVar.

## SetIdent()

void CBot::CBotVarClass::SetIdent | ( | long | n | ) |

override virtual

List of all class instances - first.

Reimplemented from CBot::CBotVar.

## Find()

CBotVarClass * CBot::CBotVarClass::Find | ( | long | id | ) |

static

Finds a class instance by unique identifier.

Parameters

  id | Identifier to find

Returns
  Found class instance

## Eq()

bool CBot::CBotVarClass::Eq | ( | CBotVar * | left,
|  | CBotVar * | right )

override virtual

List of all class instances - first.

Reimplemented from CBot::CBotVar.

## Ne()

bool CBot::CBotVarClass::Ne | ( | CBotVar * | left,
|  | CBotVar * | right )

override virtual

List of all class instances - first.

Reimplemented from CBot::CBotVar.

## ConstructorSet()

void CBot::CBotVarClass::ConstructorSet | ( |  | ) |

override virtual

List of all class instances - first.

Reimplemented from CBot::CBotVar.

## Friends And Related Symbol Documentation

## CBotVar

friend class CBotVar

friend

List of all class instances - first.

## CBotVarPointer

friend class CBotVarPointer

friend

List of all class instances - first.

The documentation for this class was generated from the following files:

- src/CBot/CBotVar/CBotVarClass.h
- src/CBot/CBotVar/CBotVarClass.cpp