RplASString RplASString::m_instance;
RplASBoolean RplASBoolean::m_instance;
RplASVoid RplASVoid::m_instance;
+RplASFormula RplASFormula::m_instance;
/** @class RplSymbolSpace rplastree.hpp "rplexpr/rplastree.hpp"
*
m_classes[RplASList::m_instance.name()] = &RplASList::m_instance;
m_classes[RplASMap::m_instance.name()] = &RplASMap::m_instance;
m_classes[RplASVoid::m_instance.name()] = &RplASVoid::m_instance;
+ m_classes[RplASFormula::m_instance.name()] = &RplASFormula::m_instance;
}
}
*/
void* RplASList::newValueInstance(void* source) const
{
- ListValueType* rc = new ListValueType();
+ ListOfVariants* rc = new ListOfVariants();
if (source != NULL){
- ListValueType* source2 = (ListValueType*) source;
+ ListOfVariants* source2 = (ListOfVariants*) source;
rc->reserve(source2->size());
- ListValueType::iterator it;
+ ListOfVariants::iterator it;
for (it = source2->begin();
it != source2->end();
it++){
*/
void RplASList::destroyValueInstance(void* object) const
{
- delete static_cast<ListValueType*>(object);
+ delete static_cast<ListOfVariants*>(object);
}
/**
{
bool rc = false;
if (object != NULL){
- ListValueType* list = static_cast<ListValueType*>(object);
+ ListOfVariants* list = static_cast<ListOfVariants*>(object);
if (list == NULL)
throw RplException("RplASList.boolValueOf(): not a list");
rc = ! list->empty();
QString rc;
rc.reserve(maxLength);
rc += "[";
- ListValueType* list = reinterpret_cast<ListValueType*>(object);
- ListValueType::iterator it;
+ ListOfVariants* list = reinterpret_cast<ListOfVariants*>(object);
+ ListOfVariants::iterator it;
bool first = true;
for(it = list->begin(); it != list->end(); it++){
if (first)
{
return QString("");
}
+
+/** @class RplASFormula rplastree.hpp "rplexpr/rplastree.hpp"
+ *
+ * @brief Implements a data type representing a calculated value.
+ */
+
+RplASFormula::RplASFormula() :
+ RplASClass("Formula")
+{
+}
+
+/**
+ * @brief Instantiates a new object.
+ *
+ * In this case we do nothing.
+ *
+ * @param source ignored
+ * @return
+ */
+void*RplASFormula::newValueInstance(void*) const
+{
+ return NULL;
+}
+
+/**
+ * @brief Destroys an object created by newValueInstance.
+ *
+ * In this case we do nothing.
+ *
+ * @param object not used
+ */
+void RplASFormula::destroyValueInstance(void*) const
+{
+}
+
+/**
+ * @brief Returns the bool value of the given object
+ * @param object ignored
+ * @return false
+ */
+bool RplASFormula::boolValueOf(void*) const
+{
+ return false;
+}
+
+/**
+ * @brief Converts the object into a string.
+ *
+ * @param object ignored
+ * @param maxLength ignored
+ * @return the empty string
+ */
+QString RplASFormula::toString(void*, int) const
+{
+ return QString("");
+}
*
*/
RplASVariant::RplASVariant() :
- m_dataType(DT_UNDEF),
+ m_variantType(VT_UNDEF),
m_flags(VF_UNDEF),
// m_value(),
m_class(NULL)
RplASVariant::~RplASVariant()
{
destroyValue();
- m_dataType = DT_UNDEF;
+ m_variantType = VT_UNDEF;
}
/**
* @param source the source to copy
*/
RplASVariant::RplASVariant(const RplASVariant& source):
- m_dataType(source.m_dataType),
+ m_variantType(source.m_variantType),
m_flags(source.m_flags),
// m_value
m_class(source.m_class)
RplASVariant&RplASVariant::operator=(const RplASVariant& source)
{
destroyValue();
- m_dataType = source.m_dataType;
+ m_variantType = source.m_variantType;
m_flags = source.m_flags;
m_class = source.m_class;
copyValue(source);
*/
void RplASVariant::copyValue(const RplASVariant& source)
{
- switch(source.m_dataType)
+ switch(source.m_variantType)
{
- case DT_BOOL:
+ case VT_BOOL:
m_value.m_bool = source.m_value.m_bool;
break;
- case DT_FLOAT:
+ case VT_FLOAT:
m_value.m_float = source.m_value.m_float;
break;
- case DT_INTEGER:
+ case VT_INTEGER:
m_value.m_int = source.m_value.m_int;
break;
- case DT_UNDEF:
+ case VT_UNDEF:
break;
default:
m_value.m_object = m_class->newValueInstance(source.m_value.m_object);
*/
void RplASVariant::destroyValue()
{
- switch(m_dataType)
+ switch(m_variantType)
{
- case DT_BOOL:
- case DT_FLOAT:
- case DT_INTEGER:
- case DT_UNDEF:
+ case VT_BOOL:
+ case VT_FLOAT:
+ case VT_INTEGER:
+ case VT_UNDEF:
break;
default:
if ((m_flags & VF_IS_COPY) == 0)
break;
}
}
+/**
+ * @brief Returns the variantType of the instance.
+ *
+ * @return the variant type
+ */
+RplASVariant::VariantType RplASVariant::variantType() const
+{
+ return m_variantType;
+}
+
+/**
+ * @brief Returns the class (data type) of the instance.
+ *
+ * @return the variant type
+ */
+RplASClass* RplASVariant::getClass() const
+{
+ return m_class;
+}
+
/**
* @brief Returns the numeric value.
*/
qreal RplASVariant::asFloat() const
{
- if (m_dataType != DT_FLOAT)
+ if (m_variantType != VT_FLOAT)
throw RplException("RplASVariant::asNumber: not a number: %d",
- m_dataType);
+ m_variantType);
return m_value.m_float;
}
/**
*/
int RplASVariant::asInt() const
{
- if (m_dataType != DT_INTEGER)
+ if (m_variantType != VT_INTEGER)
throw RplException("RplASVariant::asInt: not an integer: %d",
- m_dataType);
+ m_variantType);
return m_value.m_int;
}
*/
bool RplASVariant::asBool() const
{
- if (m_dataType != DT_BOOL)
+ if (m_variantType != VT_BOOL)
throw RplException("RplASVariant::asBool: not a boolean: %d",
- m_dataType);
+ m_variantType);
return m_value.m_bool;
}
*/
void* RplASVariant::asObject(const RplASClass** clazz) const
{
- if (m_dataType != DT_OBJECT)
+ if (m_variantType != VT_OBJECT)
throw RplException("RplASVariant::asObject: not an object: %d",
- m_dataType);
+ m_variantType);
if (clazz != NULL)
*clazz = m_class;
return m_value.m_object;
void RplASVariant::setFloat(qreal number)
{
destroyValue();
- m_dataType = DT_FLOAT;
+ m_variantType = VT_FLOAT;
m_value.m_float = number;
m_class = &RplASFloat::m_instance;
}
void RplASVariant::setInt(int integer)
{
destroyValue();
- m_dataType = DT_INTEGER;
+ m_variantType = VT_INTEGER;
m_value.m_int = integer;
m_class = &RplASInteger::m_instance;
}
void RplASVariant::setBool(bool value)
{
destroyValue();
- m_dataType = DT_BOOL;
+ m_variantType = VT_BOOL;
m_value.m_bool = value;
m_class = &RplASBoolean::m_instance;
}
QString RplASVariant::toString(int maxLength) const
{
QString rc;
- switch(m_dataType)
+ switch(m_variantType)
{
- case DT_BOOL:
+ case VT_BOOL:
rc = m_value.m_bool ? "True" : "False";
break;
- case DT_FLOAT:
+ case VT_FLOAT:
rc.sprintf("%f", m_value.m_float);
break;
- case DT_INTEGER:
+ case VT_INTEGER:
rc.sprintf("%d", m_value.m_int);
break;
- case DT_OBJECT:
+ case VT_OBJECT:
rc = m_class->toString(m_value.m_object, maxLength);
break;
default:
- case DT_UNDEF:
+ case VT_UNDEF:
rc = "None";
break;
}
void RplASVariant::setObject(void* object, const RplASClass* clazz)
{
destroyValue();
- m_dataType = DT_OBJECT;
+ m_variantType = VT_OBJECT;
m_value.m_object = object;
m_class = clazz;
}
return m_value;
}
+/** @class RplASListConstant rplastree.hpp "rplexpr/rplastree.hpp"
+ *
+ * @brief Implements a container for constant list entries.
+ *
+ */
+
+/**
+ * @brief Constructor.
+ */
+RplASListConstant::RplASListConstant() :
+ RplASNode1(AST_LIST_CONSTANT),
+ RplASCalculable()
+{
+}
+
+/**
+ * @brief Calculates the expression.
+ *
+ * @param value OUT: the calculated value
+ */
+void RplASListConstant::calc(RplASVariant& value)
+{
+ value = m_value;
+}
+
+/**
+ * @brief Writes the internals into a file.
+ *
+ * @param fp target file
+ * @param indent nesting level
+ */
+void RplASListConstant::dump(FILE* fp, int indent)
+{
+ DEFINE_TABS(indent);
+ char buffer[256];
+ fprintf(fp, "%slistConst id: %d %s\n", tabs, m_id,
+ positionStr(buffer, sizeof buffer));
+
+ RplASList::ListOfVariants* list = (RplASList::ListOfVariants*)
+ m_value.asObject();
+ QString sValue = m_value.toString(8092);
+ fprintf(fp, "%s\t%s\n", tabs, sValue.toUtf8().constData());
+}
+
+/**
+ * @brief Returns the value of the constant.
+ *
+ * This method will be used to set the value of the constant:
+ * <pre><code>RplASConstant constant;
+ * constant.value().setString("Jonny");
+ *</code></pre>
+ *
+ * @return the internal value
+ */
+RplASVariant& RplASListConstant::value()
+{
+ return m_value;
+}
+
+
/** @class RplASNamedValue rplastree.hpp "rplexpr/rplastree.hpp"
*
* @brief Implements a named values, a constant or a variable
bool rc = false;
RplASVariant value;
calc(value);
- switch(value.m_dataType){
- case RplASVariant::DT_FLOAT:
+ switch(value.m_variantType){
+ case RplASVariant::VT_FLOAT:
rc = value.m_value.m_float == 0;
break;
- case RplASVariant::DT_BOOL:
+ case RplASVariant::VT_BOOL:
rc = value.m_value.m_bool;
break;
- case RplASVariant::DT_OBJECT:
+ case RplASVariant::VT_OBJECT:
rc = value.m_class->boolValueOf(value.m_value.m_object);
break;
default:
RplASNode2(AST_ARGUMENT)
{
}
-
-
-