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 (i64 i)
 Integer constructor.
 Value (int i)
 Integer constructor.
 Value (f64 d)
 Double constructor.
 Value (const std::string &s)
 String constructor.
 Value (const PhsString &s)
 Small Strring 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.
i64 asInt () const noexcept
 Get the value as an integer.
f64 asFloat () const noexcept
 Get the value as a f64.
std::string string () const noexcept
 Get the value as a string.
PhsString asString () const noexcept
 Get the value as a Small 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 toRepr () const noexcept
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 PhsString &name) const
void setField (const PhsString &name, Value value)
bool hasField (const PhsString &name) const noexcept

Static Public Member Functions

static Value typeToString (const ValueType &type)
static Value createStruct (const PhsString &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 58 of file Value.hpp.

Member Typedef Documentation

◆ ArrayInstance

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

Definition at line 66 of file Value.hpp.

◆ DataType

using Phasor::Value::DataType
private
Initial value:
std::variant<std::monostate, bool, i64, f64, PhsString,
std::shared_ptr<StructInstance>,
std::shared_ptr<ArrayInstance>>
int64_t i64
Definition phsint.hpp:16
double f64
Definition phsint.hpp:7

Definition at line 69 of file Value.hpp.

Constructor & Destructor Documentation

◆ Value() [1/10]

Phasor::Value::Value ( )
inline

Default constructor.

Definition at line 77 of file Value.hpp.

Here is the caller graph for this function:

◆ Value() [2/10]

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

Boolean constructor.

Definition at line 81 of file Value.hpp.

◆ Value() [3/10]

Phasor::Value::Value ( i64 i)
inline

Integer constructor.

Definition at line 85 of file Value.hpp.

◆ Value() [4/10]

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

Integer constructor.

Definition at line 89 of file Value.hpp.

◆ Value() [5/10]

Phasor::Value::Value ( f64 d)
inline

Double constructor.

Definition at line 93 of file Value.hpp.

◆ Value() [6/10]

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

String constructor.

Definition at line 97 of file Value.hpp.

◆ Value() [7/10]

Phasor::Value::Value ( const PhsString & s)
inline

Small Strring constructor.

Definition at line 101 of file Value.hpp.

◆ Value() [8/10]

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

String constructor.

Definition at line 105 of file Value.hpp.

◆ Value() [9/10]

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

Struct constructor.

Definition at line 109 of file Value.hpp.

◆ Value() [10/10]

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

Array constructor.

Definition at line 113 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 208 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 214 of file Value.hpp.

◆ asBool()

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

Get the value as a boolean.

Definition at line 159 of file Value.hpp.

Here is the caller graph for this function:

◆ asFloat()

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

Get the value as a f64.

Definition at line 177 of file Value.hpp.

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

◆ asInt()

i64 Phasor::Value::asInt ( ) const
inlinenodiscardnoexcept

Get the value as an integer.

Definition at line 164 of file Value.hpp.

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

◆ asString()

PhsString Phasor::Value::asString ( ) const
inlinenodiscardnoexcept

Get the value as a Small String.

Definition at line 199 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 557 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 562 of file Value.hpp.

◆ c_str()

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

Convert to C Style String.

Definition at line 536 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 572 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 PhsString & name)
inlinestatic

Definition at line 567 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 PhsString & name) const
inlinenodiscard

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

Here is the caller graph for this function:

◆ hasField()

bool Phasor::Value::hasField ( const PhsString & name) const
inlinenodiscardnoexcept

Definition at line 602 of file Value.hpp.

◆ isArray()

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

Check if the value is an array.

Definition at line 153 of file Value.hpp.

Here is the caller graph for this function:

◆ isBool()

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

Definition at line 147 of file Value.hpp.

Here is the caller graph for this function:

◆ isFloat()

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

Definition at line 149 of file Value.hpp.

Here is the caller graph for this function:

◆ isInt()

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

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

Here is the caller graph for this function:

◆ isNumber()

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

Definition at line 151 of file Value.hpp.

Here is the caller graph for this function:

◆ isString()

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

Definition at line 150 of file Value.hpp.

Here is the caller graph for this function:

◆ isStruct()

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

Definition at line 552 of file Value.hpp.

Here is the caller graph for this function:

◆ isTruthy()

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

Helper to determine truthiness.

Definition at line 350 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 338 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 344 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 332 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 416 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 318 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 282 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 220 of file Value.hpp.

Here is the call graph for this function:

◆ operator++()

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

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

Here is the call graph for this function:

◆ operator--()

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

Definition at line 251 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 296 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 422 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 458 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 376 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 440 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 463 of file Value.hpp.

Here is the call graph for this function:

◆ setField()

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

Definition at line 592 of file Value.hpp.

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

◆ string()

std::string Phasor::Value::string ( ) const
inlinenodiscardnoexcept

Get the value as a string.

Definition at line 190 of file Value.hpp.

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

◆ toRepr()

std::string Phasor::Value::toRepr ( ) const
inlinenodiscardnoexcept

Definition at line 468 of file Value.hpp.

Here is the call graph for this function:

◆ toString()

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

Convert to string for printing.

Definition at line 478 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 122 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 546 of file Value.hpp.

Member Data Documentation

◆ data

DataType Phasor::Value::data
private

Definition at line 73 of file Value.hpp.


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