File indexing completed on 2024-04-28 07:33:16

0001 /*
0002     SPDX-FileCopyrightText: 2003-2006 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #ifndef _VALUE_H_
0009 #define _VALUE_H_
0010 
0011 #include <QString>
0012 
0013 
0014 
0015 // maybe this class has to be split-up/sub-classed into (several) Constant's and a Variable class
0016 // which is a lot of work for little gain :)
0017 
0018 /**
0019  * @short An object for the dynamic variable value in the KTurtle language.
0020  *
0021  * This object represents a variable in the KTurtle programming language.
0022  * It can have 4 types: Empty (NULL), Bool (boolean), Number (double) and
0023  * String (QString).
0024  * It can easily be switched between types.
0025  *
0026  * By default a Value is Empty.
0027  *
0028  * @TODO a way to easily generate ErrorMessages from this class
0029  *
0030  * @author Cies Breijs
0031  */
0032 class Value
0033 {
0034     public:
0035         enum Type
0036         {
0037             Empty,
0038             Bool,
0039             Number,
0040             String
0041         };
0042 
0043         Value();
0044         Value(Value*);
0045 
0046         Value(bool b)           { setBool(b); }
0047         Value(double d)         { setNumber(d); }
0048         Value(const QString& s) { setString(s); }
0049         ~Value() {}
0050     
0051         int      type() const { return m_type; }
0052         void     setType(int);
0053 
0054         void     setNull()    { init(); }
0055 
0056         bool     boolean() const;
0057         void     setBool(bool);
0058     
0059         double   number() const;
0060         void     setNumber(double);
0061         bool     setNumber(const QString&);
0062     
0063         QString  string() const;
0064         void     setString(double);
0065         void     setString(const QString&);
0066     
0067         Value&   operator=(Value*);
0068         Value&   operator=(const QString&);
0069         Value&   operator=(double);
0070     
0071         Value&   operator+(Value*);
0072         Value&   operator-(Value*);
0073         Value&   operator*(Value*);
0074         Value&   operator/(Value*);
0075     
0076         bool     operator==(Value*) const;
0077         bool     operator!=(Value*) const;
0078         bool     operator< (Value*) const;
0079         bool     operator<=(Value*) const;
0080         bool     operator> (Value*) const;
0081         bool     operator>=(Value*) const;
0082         
0083         
0084     private:
0085         void     init();
0086         
0087         int      m_type;
0088         bool     m_bool;
0089         double   m_double;
0090         QString  m_string;
0091 };
0092 
0093 #endif  // _VALUE_H_