Phasor 3.1.1
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 typeToString (const ValueType &type)
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 66 of file Value.hpp.

Member Typedef Documentation

◆ ArrayInstance

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

Definition at line 74 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 77 of file Value.hpp.

Constructor & Destructor Documentation

◆ Value() [1/9]

Phasor::Value::Value ( )
inline

Default constructor.

Definition at line 84 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 88 of file Value.hpp.

◆ Value() [3/9]

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

Integer constructor.

Definition at line 92 of file Value.hpp.

◆ Value() [4/9]

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

Integer constructor.

Definition at line 96 of file Value.hpp.

◆ Value() [5/9]

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

Double constructor.

Definition at line 100 of file Value.hpp.

◆ Value() [6/9]

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

String constructor.

Definition at line 104 of file Value.hpp.

◆ Value() [7/9]

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

String constructor.

Definition at line 108 of file Value.hpp.

◆ Value() [8/9]

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

Struct constructor.

Definition at line 112 of file Value.hpp.

◆ Value() [9/9]

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

Array constructor.

Definition at line 116 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 230 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 236 of file Value.hpp.

◆ asBool()

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

Get the value as a boolean.

Definition at line 200 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 214 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 205 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 223 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 465 of file Value.hpp.

Here is the caller graph for this function:

◆ asStruct() [2/2]

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

Definition at line 470 of file Value.hpp.

◆ c_str()

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

Convert to C Style String.

Definition at line 446 of file Value.hpp.

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

◆ createArray()

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

Definition at line 480 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 475 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 485 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 121 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 504 of file Value.hpp.

◆ isArray()

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

Check if the value is an array.

Definition at line 194 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 169 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 179 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 174 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 164 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 189 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 184 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 460 of file Value.hpp.

◆ isTruthy()

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

Helper to determine truthiness.

Definition at line 332 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 320 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 326 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 314 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 374 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 292 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 264 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 242 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 304 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 254 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 274 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 380 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 404 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 348 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 392 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 409 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 496 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 415 of file Value.hpp.

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

◆ typeToString()

Value Phasor::Value::typeToString ( const ValueType & type)
inlinestatic

Definition at line 140 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 454 of file Value.hpp.

Member Data Documentation

◆ data

DataType Phasor::Value::data
private

Definition at line 80 of file Value.hpp.


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