blob: e9b743417eb7d6779be71c2f2233232d9d179568 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/**
*
*
* Classes_and_objects.h
*
*/
/**
* Set up namespace
*/
namespace TestBaseClass {
class MyCustomClass : public Php::Base, public Php::Countable
{
private:
int _x = 3;
public:
MyCustomClass()
{
std::cerr << "MyCustomClass::MyCustomClass()" << std::endl;
}
MyCustomClass(int value) : _x(value)
{
std::cerr << "MyCustomClass::MyCustomClass(" << value << ")" << std::endl;
}
MyCustomClass(const MyCustomClass &that)
{
//std::cerr << "MyCustomClass::MyCustomClass copy constructor" << std::endl;
}
virtual ~MyCustomClass()
{
std::cerr << "MyCustomClass::~MyCustomClass" << std::endl;
}
virtual long int count() override
{
return 33;
}
Php::Value myMethod(Php::Parameters ¶ms)
{
// check number of parameters
//if (params.size() != 1) throw Php::Exception("Invalid number of parameters supplied");
std::cout << "myMethod is called for object " << _x << std::endl;
return 5;
}
};
/**
* custom comparison operator
*/
class Comparable : public Php::Base
{
private:
/**
* Internal value of the class
* @var int
*/
static int count;
int _nom;
int _value;
public:
/**
* C++ constructor
*/
Comparable()
{
// start with random value
//_value = rand();
_nom = ++count;
_value = _nom%2+1;
}
/**
* C++ destructor
*/
virtual ~Comparable() {}
/**
* Cast the object to a string
* @return std::string
*/
std::string __toString()
{
return "Obj#" + std::to_string(_nom) + "(" + std::to_string(_value) + ")";
}
/**
* Compare with a different object
* @param that
* @return int
*/
int __compare(const Comparable &that) const
{
return _value - that._value;
}
};
int Comparable::count = 0;
/**
* End of namespace
*/
}
|