-
Notifications
You must be signed in to change notification settings - Fork 3
/
Object.cc
72 lines (62 loc) · 1.35 KB
/
Object.cc
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
//
// Copyright 2009-2017 M. Shulhan (ms@kilabit.info). All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "Object.hh"
namespace vos {
const char* Object::__CNAME = "Object";
/**
* Method CMP is a static function to compare two object `x` and `y` using
* value of `chars()` function. It will return,
*
* - `-1` if `x` is less than `y`, or `x` is nil and `y` is not nil.
* - `1` if `x` is greater than `y`, or `x` is not nil while `y` is nil.
* - `0` if `x` and `y` is equal or both are nil.
*/
int Object::CMP(Object* x, Object* y)
{
if (!x && !y) {
return 0;
}
if (!x) {
return -1;
}
if (!y) {
return 1;
}
return strcmp(x->chars(), y->chars());
}
/**
* Method `Object()` will create empty object.
*/
Object::Object()
: __str(NULL)
{}
/**
* Method `~Object()` will release object from memory.
*/
Object::~Object()
{
if (__str != NULL) {
free(__str);
__str = NULL;
}
}
/**
* Method `cmp(that)` will compare current object with `that` object using
* object's string representation with case sensitive comparison.
*/
int Object::cmp(Object* that)
{
return this->CMP(this, that);
}
/**
* Method `chars()` will return string representation of current object.
*/
const char* Object::chars()
{
return __str;
}
} // namespace vos
// vi: ts=8 sw=8 tw=80: