Yoba Perl
Scalar

Scalar reference More...

Inherits Variable.

Public Member Functions

 Scalar (Perl &perl, SV *sv, bool increase_refcount)
 Constructor. More...
 
Modify/convert value
ScalarsetValue (const std::string &value)
 Replace scalar value by string. More...
 
ScalarsetValue (const char *value)
 
ScalarsetValue (IV value)
 Replace scalar value by integer. More...
 
ScalarsetValue (int value)
 
ScalarsetValue (UV value)
 Replace scalar value by unsigned integer. More...
 
ScalarsetValue (unsigned value)
 
ScalarsetValue (NV value)
 Replace scalar value by float number. More...
 
ScalarsetValue (float value)
 
ScalarsetValue (bool value)
 Replace scalar value by boolean. More...
 
std::string toString () const
 Convert scalar value to C++ string. More...
 
IV toIV () const
 Convert scalar value to integer. More...
 
UV toUV () const
 Convert scalar value to unsigned integer. More...
 
NV toNV () const
 Convert scalar value to float number. More...
 
bool toBool () const
 Convert scalar value to boolean. More...
 
Scalar unrefScalar () const
 Dereference scalar. More...
 
Array unrefArray () const
 Dereference array. More...
 
Hash unrefHash () const
 Dereference hash. More...
 
Code unrefCode () const
 Dereference code (without call) More...
 
Misc
I32 getLength () const
 Value length. More...
 
Scalar makeCopy () const
 Create copy. More...
 
Scalar makeRef () const
 Take reference. More...
 
bool isRef () const
 Check if scalar is a reference. More...
 
bool isScalarRef () const
 Check if scalar is a scalar reference. More...
 
bool isArrayRef () const
 Check if scalar is an array reference. More...
 
bool isHashRef () const
 Check if scalar is a hash reference. More...
 
bool isCodeRef () const
 Check if scalar is a subroutine reference. More...
 
bool isObject () const
 Check if scalar is a object. More...
 
bool isObjectOf (const std::string &class_name) const
 Check if scalar is a class object. More...
 
bool isValidNumber () const
 Check if scalar is a valid number. More...
 
Operators
template<typename ValueT >
Scalaroperator= (const ValueT &value)
 Alias to setValue() More...
 
 operator bool () const
 Check if scalar not empty. More...
 
- Public Member Functions inherited from Variable
 Variable (Perl &perl, SV *sv, bool increase_refcount)
 Constructor.
 
 Variable (const Variable &to_copy)
 Copy constructor. More...
 
 Variable (Variable &&to_move)
 Move constructor. More...
 
virtual ~Variable ()
 Destructor. More...
 
void setReadOnly (bool state)
 Add/remove readonly flag.
 
bool isReadOnly () const
 Check if SV has readonly flag.
 
PerlgetPerl () const
 Get Perl instance.
 
SV * getSV () const
 Get raw scalar.
 
SV * detachSV ()
 Nullify object and return SV. More...
 
SV * detachMortalSV ()
 Nullify object and return mortalized SV. More...
 
U32 getRefcount () const
 Get SV reference count.
 
void increaseRefcount ()
 Increase SV reference count.
 
void decreaseRefcount ()
 Decrease SV reference count.
 
void dump () const
 Dump SV data to stderr.
 
bool operator== (const Variable &other)
 Compare SV pointers.
 
bool operator!= (const Variable &other)
 

Detailed Description

Scalar reference

Example
Scalar scalar = perl.newScalar("str"); // (my) $scalar = "str"
scalar.setValue(14); // $scalar = 14
Scalar copy = scalar.makeCopy(); // $copy = $scalar
Scalar ref = scalar.makeRef(); // $ref = \$scalar

Definition at line 24 of file scalar.hpp.

Constructor & Destructor Documentation

Scalar ( Perl perl,
SV *  sv,
bool  increase_refcount 
)

Constructor.

Use Perl::newScalar() instead

Definition at line 11 of file scalar.cpp.

Member Function Documentation

Scalar & setValue ( const std::string &  value)

Replace scalar value by string.

Perl equivalent
$scalar = "string"

Definition at line 18 of file scalar.cpp.

Scalar & setValue ( IV  value)

Replace scalar value by integer.

Perl equivalent
$scalar = 123

Definition at line 24 of file scalar.cpp.

Scalar & setValue ( UV  value)

Replace scalar value by unsigned integer.

Perl equivalent
$scalar = 123

Definition at line 30 of file scalar.cpp.

Scalar & setValue ( NV  value)

Replace scalar value by float number.

Perl equivalent
$scalar = 12.34

Definition at line 36 of file scalar.cpp.

Scalar & setValue ( bool  value)

Replace scalar value by boolean.

Perl equivalent
$scalar = !0

Definition at line 42 of file scalar.cpp.

std::string toString ( ) const
virtual

Convert scalar value to C++ string.

Perl equivalent
"$scalar"

Implements Variable.

Definition at line 74 of file scalar.cpp.

IV toIV ( ) const

Convert scalar value to integer.

Perl equivalent
int $scalar

Definition at line 82 of file scalar.cpp.

UV toUV ( ) const

Convert scalar value to unsigned integer.

Perl equivalent
sprintf "%u", $scalar

Definition at line 87 of file scalar.cpp.

NV toNV ( ) const

Convert scalar value to float number.

Perl equivalent
sprintf "%f", $scalar

Definition at line 92 of file scalar.cpp.

bool toBool ( ) const

Convert scalar value to boolean.

Perl equivalent
!!$scalar

Definition at line 97 of file scalar.cpp.

Scalar unrefScalar ( ) const

Dereference scalar.

Perl equivalent
$$scalar

Definition at line 102 of file scalar.cpp.

Array unrefArray ( ) const

Dereference array.

Perl equivalent
@$scalar

Definition at line 122 of file scalar.cpp.

Hash unrefHash ( ) const

Dereference hash.

Perl equivalent
%$scalar

Definition at line 142 of file scalar.cpp.

Code unrefCode ( ) const

Dereference code (without call)

Perl equivalent
&$scalar

Definition at line 162 of file scalar.cpp.

I32 getLength ( ) const

Value length.

Perl equivalent
length $scalar

Definition at line 182 of file scalar.cpp.

Scalar makeCopy ( ) const

Create copy.

Perl equivalent
$copy = $scalar

Definition at line 187 of file scalar.cpp.

Scalar makeRef ( ) const

Take reference.

Perl equivalent
$ref = \$scalar

Definition at line 192 of file scalar.cpp.

bool isRef ( ) const

Check if scalar is a reference.

Perl equivalent
ref $scalar

Definition at line 197 of file scalar.cpp.

bool isScalarRef ( ) const

Check if scalar is a scalar reference.

Perl equivalent
ref $scalar eq "SCALAR"

Definition at line 202 of file scalar.cpp.

bool isArrayRef ( ) const

Check if scalar is an array reference.

Perl equivalent
ref $scalar eq "ARRAY"

Definition at line 207 of file scalar.cpp.

bool isHashRef ( ) const

Check if scalar is a hash reference.

Perl equivalent
ref $scalar eq "HASH"

Definition at line 212 of file scalar.cpp.

bool isCodeRef ( ) const

Check if scalar is a subroutine reference.

Perl equivalent
ref $scalar eq "CODE"

Definition at line 217 of file scalar.cpp.

bool isObject ( ) const

Check if scalar is a object.

Perl equivalent
Scalar::Util::blessed($scalar)

Definition at line 222 of file scalar.cpp.

bool isObjectOf ( const std::string &  class_name) const

Check if scalar is a class object.

Perl equivalent
ref $scalar eq "Classname"

Definition at line 227 of file scalar.cpp.

bool isValidNumber ( ) const

Check if scalar is a valid number.

Note
"Inf" and "Infinity"" are treated as numbers
Perl equivalent
Scalar::Util::looks_like_number($scalar)

Definition at line 232 of file scalar.cpp.

Scalar & operator= ( const ValueT &  value)

Alias to setValue()

Perl equivalent
$scalar = value

Definition at line 5 of file scalar.hpp.

operator bool ( ) const

Check if scalar not empty.

Perl equivalent
$scalar && length $scalar

Definition at line 239 of file scalar.cpp.


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