Phasor 2.2.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
Phasor::Value Class Reference

A value in the Phasor VM. More...

#include <Value.hpp>

Classes

struct  StructInstance

Public Types

using ArrayInstance = std::vector<Value>

Public Member Functions

 Value ()
 Default constructor.
 Value (bool b)
 Boolean constructor.
 Value (int64_t i)
 Integer constructor.
 Value (int i)
 Integer constructor.
 Value (double d)
 Double constructor.
 Value (const std::string &s)
 String constructor.
 Value (const char *s)
 String constructor.
 Value (std::shared_ptr< StructInstance > s)
 Struct constructor.
 Value (std::shared_ptr< ArrayInstance > a)
 Array constructor.
ValueType getType () const
 Get the type of the value.
bool isNull () const
 Check if the value is null.
bool isBool () const
 Check if the value is a boolean.
bool isInt () const
 Check if the value is an integer.
bool isFloat () const
 Check if the value is a double.
bool isString () const
 Check if the value is a string.
bool isNumber () const
 Check if the value is a number.
bool isArray () const
 Check if the value is an array.
bool asBool () const
 Get the value as a boolean.
int64_t asInt () const
 Get the value as an integer.
double asFloat () const
 Get the value as a double.
std::string asString () const
 Get the value as a string.
std::shared_ptr< ArrayInstanceasArray ()
 Get the value as an array.
const std::shared_ptr< const ArrayInstanceasArray () const
 Get the value as an array (const).
Value operator+ (const Value &other) const
 Add two values.
Value operator- (const Value &other) const
 Subtract two values.
Value operator* (const Value &other) const
 Multiply two values.
Value operator/ (const Value &other) const
 Divide two values.
Value operator% (const Value &other) const
 Modulo two values.
Value operator- () const
 Unary negation.
Value operator! () const
 Logical negation.
Value logicalAnd (const Value &other) const
 Logical AND.
Value logicalOr (const Value &other) const
 Logical OR.
bool isTruthy () const
 Helper to determine truthiness.
bool operator== (const Value &other) const
 Comparison operations.
bool operator!= (const Value &other) const
 Inequality comparison.
bool operator< (const Value &other) const
 Less than comparison.
bool operator> (const Value &other) const
 Greater than comparison.
bool operator<= (const Value &other) const
 Less than or equal to comparison.
bool operator>= (const Value &other) const
 Greater than or equal to comparison.
std::string toString () const
 Convert to string for printing.
const char * c_str () const
 Convert to C Style String.
bool isStruct () const
std::shared_ptr< StructInstanceasStruct ()
const std::shared_ptr< const StructInstanceasStruct () const
Value getField (const std::string &name) const
void setField (const std::string &name, Value value)
bool hasField (const std::string &name) const

Static Public Member Functions

static Value createStruct (const std::string &name)
static Value createArray (std::vector< Value > elements={})

Private Types

using DataType

Private Attributes

DataType data

Friends

std::ostream & operator<< (std::ostream &os, const Value &v)
 Print to output stream.

Detailed Description

A value in the Phasor VM.

Uses std::variant for type-safe union

Definition at line 32 of file Value.hpp.

Member Typedef Documentation

◆ ArrayInstance

using Phasor::Value::ArrayInstance = std::vector<Value>

Definition at line 40 of file Value.hpp.

◆ DataType

using Phasor::Value::DataType
private
Initial value:
std::variant<std::monostate, bool, int64_t, double, std::string,
std::shared_ptr<StructInstance>, std::shared_ptr<ArrayInstance>>

Definition at line 43 of file Value.hpp.

Constructor & Destructor Documentation

◆ Value() [1/9]

Phasor::Value::Value ( )
inline

Default constructor.

Definition at line 50 of file Value.hpp.

Here is the caller graph for this function:

◆ Value() [2/9]

Phasor::Value::Value ( bool b)
inline

Boolean constructor.

Definition at line 54 of file Value.hpp.

◆ Value() [3/9]

Phasor::Value::Value ( int64_t i)
inline

Integer constructor.

Definition at line 58 of file Value.hpp.

◆ Value() [4/9]

Phasor::Value::Value ( int i)
inline

Integer constructor.

Definition at line 62 of file Value.hpp.

◆ Value() [5/9]

Phasor::Value::Value ( double d)
inline

Double constructor.

Definition at line 66 of file Value.hpp.

◆ Value() [6/9]

Phasor::Value::Value ( const std::string & s)
inline

String constructor.

Definition at line 70 of file Value.hpp.

◆ Value() [7/9]

Phasor::Value::Value ( const char * s)
inline

String constructor.

Definition at line 74 of file Value.hpp.

◆ Value() [8/9]

Phasor::Value::Value ( std::shared_ptr< StructInstance > s)
inline

Struct constructor.

Definition at line 78 of file Value.hpp.

◆ Value() [9/9]

Phasor::Value::Value ( std::shared_ptr< ArrayInstance > a)
inline

Array constructor.

Definition at line 82 of file Value.hpp.

Member Function Documentation

◆ asArray() [1/2]

std::shared_ptr< ArrayInstance > Phasor::Value::asArray ( )
inline

Get the value as an array.

Definition at line 173 of file Value.hpp.

Here is the caller graph for this function:

◆ asArray() [2/2]

const std::shared_ptr< const ArrayInstance > Phasor::Value::asArray ( ) const
inline

Get the value as an array (const).

Definition at line 179 of file Value.hpp.

◆ asBool()

bool Phasor::Value::asBool ( ) const
inline

Get the value as a boolean.

Definition at line 143 of file Value.hpp.

Here is the caller graph for this function:

◆ asFloat()

double Phasor::Value::asFloat ( ) const
inline

Get the value as a double.

Definition at line 157 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ asInt()

int64_t Phasor::Value::asInt ( ) const
inline

Get the value as an integer.

Definition at line 148 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ asString()

std::string Phasor::Value::asString ( ) const
inline

Get the value as a string.

Definition at line 166 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ asStruct() [1/2]

std::shared_ptr< StructInstance > Phasor::Value::asStruct ( )
inline

Definition at line 412 of file Value.hpp.

◆ asStruct() [2/2]

const std::shared_ptr< const StructInstance > Phasor::Value::asStruct ( ) const
inline

Definition at line 417 of file Value.hpp.

◆ c_str()

const char * Phasor::Value::c_str ( ) const
inline

Convert to C Style String.

Definition at line 393 of file Value.hpp.

Here is the call graph for this function:

◆ createArray()

Value Phasor::Value::createArray ( std::vector< Value > elements = {})
inlinestatic

Definition at line 427 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createStruct()

Value Phasor::Value::createStruct ( const std::string & name)
inlinestatic

Definition at line 422 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getField()

Value Phasor::Value::getField ( const std::string & name) const
inline

Definition at line 432 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getType()

ValueType Phasor::Value::getType ( ) const
inline

Get the type of the value.

Definition at line 87 of file Value.hpp.

Here is the caller graph for this function:

◆ hasField()

bool Phasor::Value::hasField ( const std::string & name) const
inline

Definition at line 451 of file Value.hpp.

◆ isArray()

bool Phasor::Value::isArray ( ) const
inline

Check if the value is an array.

Definition at line 137 of file Value.hpp.

Here is the caller graph for this function:

◆ isBool()

bool Phasor::Value::isBool ( ) const
inline

Check if the value is a boolean.

Definition at line 112 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isFloat()

bool Phasor::Value::isFloat ( ) const
inline

Check if the value is a double.

Definition at line 122 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInt()

bool Phasor::Value::isInt ( ) const
inline

Check if the value is an integer.

Definition at line 117 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNull()

bool Phasor::Value::isNull ( ) const
inline

Check if the value is null.

Definition at line 107 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNumber()

bool Phasor::Value::isNumber ( ) const
inline

Check if the value is a number.

Definition at line 132 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isString()

bool Phasor::Value::isString ( ) const
inline

Check if the value is a string.

Definition at line 127 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isStruct()

bool Phasor::Value::isStruct ( ) const
inline

Definition at line 407 of file Value.hpp.

◆ isTruthy()

bool Phasor::Value::isTruthy ( ) const
inline

Helper to determine truthiness.

Definition at line 275 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logicalAnd()

Value Phasor::Value::logicalAnd ( const Value & other) const
inline

Logical AND.

Definition at line 263 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logicalOr()

Value Phasor::Value::logicalOr ( const Value & other) const
inline

Logical OR.

Definition at line 269 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!()

Value Phasor::Value::operator! ( ) const
inline

Logical negation.

Definition at line 257 of file Value.hpp.

Here is the call graph for this function:

◆ operator!=()

bool Phasor::Value::operator!= ( const Value & other) const
inline

Inequality comparison.

Definition at line 321 of file Value.hpp.

Here is the call graph for this function:

◆ operator%()

Value Phasor::Value::operator% ( const Value & other) const
inline

Modulo two values.

Definition at line 235 of file Value.hpp.

Here is the call graph for this function:

◆ operator*()

Value Phasor::Value::operator* ( const Value & other) const
inline

Multiply two values.

Definition at line 207 of file Value.hpp.

Here is the call graph for this function:

◆ operator+()

Value Phasor::Value::operator+ ( const Value & other) const
inline

Add two values.

Definition at line 185 of file Value.hpp.

Here is the call graph for this function:

◆ operator-() [1/2]

Value Phasor::Value::operator- ( ) const
inline

Unary negation.

Definition at line 247 of file Value.hpp.

Here is the call graph for this function:

◆ operator-() [2/2]

Value Phasor::Value::operator- ( const Value & other) const
inline

Subtract two values.

Definition at line 197 of file Value.hpp.

Here is the call graph for this function:

◆ operator/()

Value Phasor::Value::operator/ ( const Value & other) const
inline

Divide two values.

Definition at line 217 of file Value.hpp.

Here is the call graph for this function:

◆ operator<()

bool Phasor::Value::operator< ( const Value & other) const
inline

Less than comparison.

Definition at line 327 of file Value.hpp.

Here is the call graph for this function:

◆ operator<=()

bool Phasor::Value::operator<= ( const Value & other) const
inline

Less than or equal to comparison.

Definition at line 351 of file Value.hpp.

Here is the call graph for this function:

◆ operator==()

bool Phasor::Value::operator== ( const Value & other) const
inline

Comparison operations.

Definition at line 296 of file Value.hpp.

Here is the call graph for this function:

◆ operator>()

bool Phasor::Value::operator> ( const Value & other) const
inline

Greater than comparison.

Definition at line 339 of file Value.hpp.

Here is the call graph for this function:

◆ operator>=()

bool Phasor::Value::operator>= ( const Value & other) const
inline

Greater than or equal to comparison.

Definition at line 356 of file Value.hpp.

Here is the call graph for this function:

◆ setField()

void Phasor::Value::setField ( const std::string & name,
Value value )
inline

Definition at line 443 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string Phasor::Value::toString ( ) const
inline

Convert to string for printing.

Definition at line 362 of file Value.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Value & v )
friend

Print to output stream.

Definition at line 401 of file Value.hpp.

Member Data Documentation

◆ data

DataType Phasor::Value::data
private

Definition at line 46 of file Value.hpp.


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