summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Elements/SenchaObject.h
blob: 6b062a9a661d5365d4f9325423cc3ea3728f4730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * SenchaObject.h
 *
 *  Created on: Dec 5, 2012
 *      Author: attero
 */

#ifndef SENCHAOBJECT_H_
#define SENCHAOBJECT_H_
#include <string>
#include <iostream>
#include "../Utils/to_string.h"
#include "Element.h"


/**
 * SenchaObject stores values in SenchaLang. It handles operations on them, thanks to defined, overloaded operators.
 * Also provides representation of values.
 */
class SenchaObject : public Element {

public:
	/**
	 * Possible types of SenchaObject
	 */
	typedef enum {
		string_literal,
		integer_number,
		float_number,
		null,
		boolean,
		invalid
	} Type;

	Type type;

	/**
	 * repr() returns representation of value as a string
	 */
	virtual std::string repr();
	virtual std::string str();
	virtual bool is_true();

	std::string text;
	std::string name;
	bool truthy;
	int integer;
	double number;

	void set_value(std::string text);
	void set_new_string(std::string text);
	void set_null_value();
	void set_value(int integer);
	void set_value(double number);
	void set_value(bool logic);

	SenchaObject();
	SenchaObject(int integer) { set_value(integer); }
	SenchaObject(bool truthy) {set_value(truthy); }
	SenchaObject(double number) { set_value(number); }
	SenchaObject(std::string text) { set_value(text); }


	//Operators used in expressions
	virtual SenchaObject operator< (const SenchaObject& right)const;
	virtual SenchaObject operator> (const SenchaObject& right)const;
	virtual SenchaObject operator<= (const SenchaObject& right)const;
	virtual SenchaObject operator>= (const SenchaObject& right)const;
	virtual SenchaObject operator+(const SenchaObject& right)const;
	virtual SenchaObject operator-(const SenchaObject& right)const;
	virtual SenchaObject operator*(const SenchaObject& right)const;
	virtual SenchaObject operator/(const SenchaObject& right)const;
	virtual SenchaObject operator==(const SenchaObject& right)const;
	virtual SenchaObject operator!=(const SenchaObject& right)const;
	virtual SenchaObject operator-() const;
	virtual SenchaObject operator!() const;


	virtual ~SenchaObject();
};

#endif /* SENCHAOBJECT_H_ */