Adding C++ wrapper
[Procustean.git] / src / ecl_fixnum.cpp
blobc9153ac1716a477479165d68b3128e97b6f9aafa
2 namespace Ecl
5 class Fixnum {
7 private:
8 cl_fixnum the_fixnum;
10 Fixnum();
11 public:
13 Fixnum(int i) : the_fixnum( MAKE_FIXNUM(i) )
17 Fixnum(long l) : the_fixnum( MAKE_FIXNUM(i) )
21 Fixnum(const cl_object& obj) :
23 the_fixnum = other.the_finxum;
26 inline operator int() const
28 #ifdef NDEBUG
29 return fix(the_fixnum);
30 #else
31 return fixint(the_fixnum);
32 #endif
35 inline operator long() const
37 #ifdef NDEBUG
38 return fix(the_fixnum);
39 #else
40 return fixint(the_fixnum);
41 #endif
47 class SingleFloat
49 private:
50 cl_object my_float;
52 SingleFloat();
54 public:
55 SingleFloat(float f) : my_float(ecl_make_singlefloat(f))
59 SingleFloat(const SingleFloat& other)
61 my_float = other.my_float;
64 inline operator float() const {
65 ecl_to_float(my_float);
68 inline operator cl_object() const {
69 return my_float;
74 class String
76 private:
77 cl_string the_string;
78 public:
79 String(std::string s) : my_string(s)
81 the_string = make_simple_string(s.c_str());
84 String(const String& other)
86 my_string = other.my_string();
87 the_string = make_simple_string(s.c_str());
90 inline operator std::string() const
92 return std::string(the_string->self);
95 inline operator cl_string()
97 return the_string;
102 // to do -- maybe a template class specialised on differen types
103 class Vector()
105 private:
106 cl_object my_array;
108 public:
110 Vector(std::size_t size, cl_eltype type)
112 my_array = si_make_vector(ecl_elttype_to_symbol(type), MAKE_FIXNUM(dim), Cnil, MAKE_FIXNUM(0), Cnil, MAKE_FIXNUM(0));
115 inline std::size_t size() const
117 return my_array->dim;
120 inline cl_eltype elements() const
122 return array_elttype(my_array);
125 inline cl_object operator[](cl_index index) const
127 return aref1(my_array, index);
130 // gratituous abuse of operator overloadin
131 inline cl_object operator()(cl_index index, cl_object value)
133 return aset1(my_array, index, value);
136 inline operator cl_object() const
138 return my_array;