Phasor 3.3.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 noexcept
 Get the type of the value.
bool isNull () const noexcept
 Check if the value is null.
bool isBool () const noexcept
bool isInt () const noexcept
bool isFloat () const noexcept
bool isString () const noexcept
bool isNumber () const noexcept
bool isArray () const noexcept
 Check if the value is an array.
bool asBool () const noexcept
 Get the value as a boolean.
int64_t asInt () const noexcept
 Get the value as an integer.
double asFloat () const noexcept
 Get the value as a double.
std::string asString () const noexcept
 Get the value as a string.
std::shared_ptr< ArrayInstanceasArray ()
 Get the value as an array.
std::shared_ptr< const ArrayInstanceasArray () const noexcept
 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.
Valueoperator-- ()
Valueoperator++ ()
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 noexcept
 Logical negation.
Value logicalAnd (const Value &other) const noexcept
 Logical AND.
Value logicalOr (const Value &other) const noexcept
 Logical OR.
bool isTruthy () const noexcept
 Helper to determine truthiness.
bool operator== (const Value &other) const noexcept
 Comparison operations.
bool operator!= (const Value &other) const noexcept
 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 noexcept
 Less than or equal to comparison.
bool operator>= (const Value &other) const noexcept
 Greater than or equal to comparison.
std::string toString () const noexcept
 Convert to string for printing.
const char * c_str () const
 Convert to C Style String.
bool isStruct () const
std::shared_ptr< StructInstanceasStruct ()
std::shared_ptr< const StructInstanceasStruct () const noexcept
Value getField (const std::string &name) const
void setField (const std::string &name, Value value)
bool hasField (const std::string &name) const noexcept

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 57 of file Value.hpp.

Member Typedef Documentation

◆ ArrayInstance

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

Definition at line 65 of file Value.hpp.

◆ DataType

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

Definition at line 68 of file Value.hpp.

Constructor & Destructor Documentation

◆ Value() [1/9]

Phasor::Value::Value ( )
inline

Default constructor.

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

◆ Value() [3/9]

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

Integer constructor.

Definition at line 84 of file Value.hpp.

◆ Value() [4/9]

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

Integer constructor.

Definition at line 88 of file Value.hpp.

◆ Value() [5/9]

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

Double constructor.

Definition at line 92 of file Value.hpp.

◆ Value() [6/9]

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

String constructor.

Definition at line 96 of file Value.hpp.

◆ Value() [7/9]

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

String constructor.

Definition at line 100 of file Value.hpp.

◆ Value() [8/9]

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

Struct constructor.

Definition at line 104 of file Value.hpp.

◆ Value() [9/9]

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

Array constructor.

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

Here is the caller graph for this function:

◆ asArray() [2/2]

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

Get the value as an array (const).

Definition at line 200 of file Value.hpp.

◆ asBool()

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

Get the value as a boolean.

Definition at line 154 of file Value.hpp.

Here is the caller graph for this function:

◆ asFloat()

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

Get the value as a double.

Definition at line 172 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
inlinenodiscardnoexcept

Get the value as an integer.

Definition at line 159 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
inlinenodiscardnoexcept

Get the value as a string.

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

Here is the caller graph for this function:

◆ asStruct() [2/2]

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

Definition at line 522 of file Value.hpp.

◆ c_str()

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

Convert to C Style String.

Definition at line 496 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 532 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 527 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
inlinenodiscard

Definition at line 537 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
inlinenodiscardnoexcept

Get the type of the value.

Definition at line 113 of file Value.hpp.

Here is the caller graph for this function:

◆ hasField()

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

Definition at line 562 of file Value.hpp.

◆ isArray()

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

Check if the value is an array.

Definition at line 148 of file Value.hpp.

Here is the caller graph for this function:

◆ isBool()

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

Definition at line 142 of file Value.hpp.

Here is the caller graph for this function:

◆ isFloat()

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

Definition at line 144 of file Value.hpp.

Here is the caller graph for this function:

◆ isInt()

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

Definition at line 143 of file Value.hpp.

Here is the caller graph for this function:

◆ isNull()

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

Check if the value is null.

Definition at line 141 of file Value.hpp.

Here is the caller graph for this function:

◆ isNumber()

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

Definition at line 146 of file Value.hpp.

Here is the caller graph for this function:

◆ isString()

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

Definition at line 145 of file Value.hpp.

Here is the caller graph for this function:

◆ isStruct()

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

Definition at line 512 of file Value.hpp.

◆ isTruthy()

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

Helper to determine truthiness.

Definition at line 336 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
inlinenodiscardnoexcept

Logical AND.

Definition at line 324 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
inlinenodiscardnoexcept

Logical OR.

Definition at line 330 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
inlinenoexcept

Logical negation.

Definition at line 318 of file Value.hpp.

Here is the call graph for this function:

◆ operator!=()

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

Inequality comparison.

Definition at line 402 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 304 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 268 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 206 of file Value.hpp.

Here is the call graph for this function:

◆ operator++()

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

Definition at line 252 of file Value.hpp.

Here is the call graph for this function:

◆ operator-()

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

Subtract two values.

Definition at line 224 of file Value.hpp.

Here is the call graph for this function:

◆ operator--()

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

Definition at line 237 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 282 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 408 of file Value.hpp.

Here is the call graph for this function:

◆ operator<=()

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

Less than or equal to comparison.

Definition at line 444 of file Value.hpp.

Here is the call graph for this function:

◆ operator==()

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

Comparison operations.

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

Here is the call graph for this function:

◆ operator>=()

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

Greater than or equal to comparison.

Definition at line 449 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 552 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
inlinenodiscardnoexcept

Convert to string for printing.

Definition at line 455 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 117 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 506 of file Value.hpp.

Member Data Documentation

◆ data

DataType Phasor::Value::data
private

Definition at line 72 of file Value.hpp.


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