Skip to content

Commit

Permalink
operator pre -- and decrement in Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed Oct 27, 2011
1 parent a2bb508 commit 5e6ce74
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions t/base/features.t
Expand Up @@ -324,6 +324,10 @@ function main [main] (args)
test.is(vi1, 43, "var preincrement");
i = ++vi1;
test.is(i, 44, "var preincrement with assignment");
--vi1;
test.is(vi1, 43, "var peedecrement");
i = --vi1;
test.is(i, 42, "var predecrement with assignment");
string s = "abc";
test.is_string(s * 3, "abcabcabc", "repeat string");
Expand Down
15 changes: 15 additions & 0 deletions winxedxx_classes.cxx
Expand Up @@ -97,6 +97,11 @@ void WxxNull::increment()
nullaccess("increment");
}

void WxxNull::decrement()
{
nullaccess("decrement");
}

std::string WxxNull::get_string_keyed(int i)
{
nullaccess("get_pmc_keyed");
Expand Down Expand Up @@ -284,6 +289,11 @@ void WxxDefault::increment()
notimplemented("increment");
}

void WxxDefault::decrement()
{
notimplemented("decrement");
}

std::string WxxDefault::get_string_keyed(int i)
{
return get_pmc_keyed(i);
Expand Down Expand Up @@ -425,6 +435,11 @@ void WxxInteger::increment()
++i;
}

void WxxInteger::decrement()
{
--i;
}

void WxxInteger::print() { std::cout << i; }

//*************************************************************
Expand Down
1 change: 1 addition & 0 deletions winxedxx_default.h
Expand Up @@ -30,6 +30,7 @@ class WxxDefault : public WxxObject
WxxObject & set(const char *s);
WxxObject & set(const std::string &s);
void increment();
void decrement();
std::string get_string_keyed(int i);
WxxObjectPtr get_pmc_keyed(int i);
WxxObjectPtr get_pmc_keyed(const std::string &s);
Expand Down
1 change: 1 addition & 0 deletions winxedxx_integer.h
Expand Up @@ -32,6 +32,7 @@ class WxxInteger : public WxxDefault
WxxObject & set(int value);
WxxObject & set(double value);
void increment();
void decrement();
void print();
private:
int i;
Expand Down
1 change: 1 addition & 0 deletions winxedxx_null.h
Expand Up @@ -25,6 +25,7 @@ class WxxNull : public WxxObject
WxxObject & set(const char *s);
WxxObject & set(const std::string &s);
void increment();
void decrement();
std::string get_string_keyed(int i);
WxxObjectPtr get_pmc_keyed(int i);
WxxObjectPtr get_pmc_keyed(const std::string &s);
Expand Down
1 change: 1 addition & 0 deletions winxedxx_object.h
Expand Up @@ -24,6 +24,7 @@ class WxxObject
virtual WxxObject & set(const char *s) = 0;
virtual WxxObject & set(const std::string &s) = 0;
virtual void increment() = 0;
virtual void decrement() = 0;
virtual std::string get_string_keyed(int i) = 0;
virtual WxxObjectPtr get_pmc_keyed(int i) = 0;
virtual WxxObjectPtr get_pmc_keyed(const std::string &s) = 0;
Expand Down
6 changes: 6 additions & 0 deletions winxedxx_objectptr.cxx
Expand Up @@ -170,6 +170,12 @@ WxxObjectPtr & WxxObjectPtr::operator++()
return *this;
}

WxxObjectPtr & WxxObjectPtr::operator--()
{
object->decrement();
return *this;
}

int WxxObjectPtr::is_null() const
{
return object->is_null();
Expand Down
1 change: 1 addition & 0 deletions winxedxx_types.h
Expand Up @@ -60,6 +60,7 @@ class WxxObjectPtr
operator double() const;
operator std::string() const;
WxxObjectPtr & operator++();
WxxObjectPtr & operator--();
int is_null() const;
int instanceof(const std::string &type);
std::string get_string() const;
Expand Down

0 comments on commit 5e6ce74

Please sign in to comment.