1 #include "yobaperl/scalar.hpp" 2 #include "yobaperl/array.hpp" 3 #include "yobaperl/hash.hpp" 4 #include "yobaperl/code.hpp" 5 #include "yobaperl/perl.hpp" 12 :
Variable(perl, sv, increase_refcount)
20 sv_setpvn(
getSV(), value.c_str(), value.length());
26 sv_setiv(
getSV(), value);
32 sv_setuv(
getSV(), value);
38 sv_setnv(
getSV(), value);
44 sv_setiv(
getSV(), value ? 1 : 0);
77 const char * ptr = SvPVx(const_cast<SV *>(
getSV()), len);
79 return std::string(ptr, len);
84 return SvIVx(
getSV());
89 return SvUVx(
getSV());
94 return SvNVx(
getSV());
99 return SvTRUEx(
getSV());
110 std::string error =
"Not a scalar reference (" +
toString().substr(0, 10) +
")";
112 if(_perl.isExceptionsEnabled())
115 if(_perl.isWarningsEnabled())
116 warn(
"%s", error.c_str());
126 return Array(_perl, MUTABLE_AV(SvRVx(
getSV())),
true);
130 std::string error =
"Not an array reference (" +
toString().substr(0, 10) +
")";
132 if(_perl.isExceptionsEnabled())
135 if(_perl.isWarningsEnabled())
136 warn(
"%s", error.c_str());
146 return Hash(_perl, MUTABLE_HV(SvRVx(
getSV())),
true);
150 std::string error =
"Not a hash reference (" +
toString().substr(0, 10) +
")";
152 if(_perl.isExceptionsEnabled())
155 if(_perl.isWarningsEnabled())
156 warn(
"%s", error.c_str());
166 return Code(_perl, MUTABLE_CV(SvRVx(
getSV())),
true);
170 std::string error =
"Not a code reference (" +
toString().substr(0, 10) +
")";
184 return sv_len(
getSV());
189 return Scalar(_perl, newSVsv(_sv),
false);
199 return SvROK(
getSV());
204 return SvTYPE(SvRVx(
getSV())) < SVt_PVAV;
209 return SvTYPE(SvRVx(
getSV())) == SVt_PVAV;
214 return SvTYPE(SvRVx(
getSV())) == SVt_PVHV;
219 return SvTYPE(SvRVx(
getSV())) == SVt_PVCV;
224 return sv_isobject(
getSV());
229 return sv_isa(
getSV(), class_name.c_str());
234 return looks_like_number(
getSV());
239 yoba::Scalar::operator bool()
const
SV * getSV() const
Get raw scalar.
bool isObjectOf(const std::string &class_name) const
Check if scalar is a class object.
bool isRef() const
Check if scalar is a reference.
Scalar unrefScalar() const
Dereference scalar.
std::string toString() const
Convert scalar value to C++ string.
Scalar(Perl &perl, SV *sv, bool increase_refcount)
Constructor.
Hash unrefHash() const
Dereference hash.
NV toNV() const
Convert scalar value to float number.
Scalar makeRef() const
Take reference.
bool isObject() const
Check if scalar is a object.
bool isValidNumber() const
Check if scalar is a valid number.
bool isCodeRef() const
Check if scalar is a subroutine reference.
I32 getLength() const
Value length.
Scalar makeCopy() const
Create copy.
IV toIV() const
Convert scalar value to integer.
Array newArray()
Create anonymous empty array.
Base class for perl variables.
Scalar newScalar()
Create anonymous empty scalar.
UV toUV() const
Convert scalar value to unsigned integer.
Scalar & setValue(const std::string &value)
Replace scalar value by string.
int getId() const
Perl object id.
bool isScalarRef() const
Check if scalar is a scalar reference.
bool isHashRef() const
Check if scalar is a hash reference.
Code unrefCode() const
Dereference code (without call)
bool toBool() const
Convert scalar value to boolean.
bool isArrayRef() const
Check if scalar is an array reference.
Array unrefArray() const
Dereference array.
Hash newHash()
Create anonymous empty hash.