Permalink
Browse files

more reorganization

  • Loading branch information...
1 parent 0d193c2 commit 21f52beb1ebddeb8d0b8090c279811366ecbce8f @NotFound committed May 21, 2011
Showing with 142 additions and 293 deletions.
  1. +0 −292 winxedxx.h
  2. +112 −0 winxedxx_classes.cxx
  3. +12 −0 winxedxx_integer.h
  4. +5 −1 winxedxx_object.h
  5. +13 −0 winxedxx_util.cxx
View
292 winxedxx.h
@@ -90,18 +90,6 @@ class WxxStringArray : public WxxArrayBase
std::vector<std::string> arr;
};
-class WxxArrayIterator : public WxxDefault
-{
-public:
- WxxArrayIterator(WxxObject *container);
- ~WxxArrayIterator();
- int get_bool();
- WxxObjectPtr shift_pmc();
-private:
- WxxObject *cnt;
- int current;
-};
-
class WxxHash : public WxxDefault
{
public:
@@ -115,24 +103,6 @@ class WxxHash : public WxxDefault
std::map<std::string, WxxObjectPtr> hsh;
};
-/*
-class WxxFileHandle : public WxxDefault
-{
-public:
- WxxFileHandle(int predef = 0);
- ~WxxFileHandle();
- WxxObject *open(WxxObjectPtr name);
- WxxObject *open(WxxObjectPtr name, WxxObjectPtr mode);
- WxxObjectPtr close();
- void print(WxxObjectPtr obj);
- WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args);
-private:
- FILE *f;
- WxxObjectPtr read(int n);
- WxxObjectPtr readline();
-};
-*/
-
class WxxNCI : public WxxDefault
{
public:
@@ -155,93 +125,6 @@ class WxxNCIcall : public WxxNCI
//*************************************************************
-WxxArrayBase::WxxArrayBase(const std::string &name) :
- WxxDefault(name)
-{
-}
-
-int WxxArrayBase::get_integer()
-{
- return elements();
-}
-
-WxxObjectPtr WxxArrayBase::get_iter()
-{
- return WxxObjectPtr(new WxxArrayIterator(this));
-}
-
-//*************************************************************
-
-WxxObjectArray::WxxObjectArray() :
- WxxArrayBase("ResizablePMCArray")
-{
-}
-
-WxxObjectArray::~WxxObjectArray()
-{
- for (unsigned int i = 0; i < arr.size(); ++i)
- delete arr[i];
-}
-
-int WxxObjectArray::elements()
-{
- return arr.size();
-}
-
-WxxObjectPtr WxxObjectArray::get_pmc_keyed(int i)
-{
- return this->operator[](i);
-}
-
-WxxObjectPtr WxxObjectArray::operator[](int i) const
-{
- int size = arr.size();
- if (i < 0)
- i += size;
- if (i < 0)
- throw wxx_error(getname() + ": index out of bounds!");
- if (i >= size)
- return winxedxxnull;
- return WxxObjectPtr(*(arr[i]));
-}
-
-WxxObjectArray& WxxObjectArray::push(WxxObjectPtr obj)
-{
- arr.push_back(new WxxObjectPtr(obj));
- return *this;
-}
-
-WxxObjectArray& WxxObjectArray::push(int i)
-{
- arr.push_back(new WxxObjectPtr(i));
- return *this;
-}
-
-WxxObjectArray& WxxObjectArray::push(double value)
-{
- arr.push_back(new WxxObjectPtr(value));
- return *this;
-}
-
-WxxObjectArray& WxxObjectArray::push(const char *str)
-{
- arr.push_back(new WxxObjectPtr(str));
- return *this;
-}
-
-WxxObjectArray& WxxObjectArray::push(const std::string &str)
-{
- arr.push_back(new WxxObjectPtr(str));
- return *this;
-}
-
-void WxxObjectArray::set_pmc_keyed(int i, const WxxObjectPtr &value)
-{
- arr[i] = new WxxObjectPtr(value);
-}
-
-//*************************************************************
-
WxxIntegerArray::WxxIntegerArray() :
WxxArrayBase("ResizableIntegerArray")
{
@@ -459,31 +342,6 @@ void WxxStringArray::set_pmc_keyed(int i, const WxxObjectPtr &value)
//*************************************************************
-WxxArrayIterator::WxxArrayIterator(WxxObject *container) :
- WxxDefault("ArrayIterator"),
- cnt(container),
- current(0)
-{
- cnt->incref();
-}
-
-WxxArrayIterator::~WxxArrayIterator()
-{
- cnt->decref();
-}
-
-int WxxArrayIterator::get_bool()
-{
- return current < cnt->elements();
-}
-
-WxxObjectPtr WxxArrayIterator::shift_pmc()
-{
- return cnt->get_pmc_keyed(current++);
-}
-
-//*************************************************************
-
WxxHash::WxxHash() : WxxDefault("Hash")
{
}
@@ -512,143 +370,6 @@ WxxObjectPtr & WxxHash::set_pmc_keyed(const std::string &s, const WxxObjectPtr &
//*************************************************************
-#if 0
-
-WxxFileHandle::WxxFileHandle(int predef) : WxxDefault("FileHandle")
-{
- switch (predef) {
- case 1:
- f = stdin;
- break;
- case 2:
- f = stdout;
- break;
- case 3:
- f = stderr;
- break;
- default:
- f = 0;
- }
-}
-
-WxxFileHandle::~WxxFileHandle()
-{
- //std::cerr << "~WxxFileHandle\n";
- if (f && f != stdin && f != stdout && f != stderr)
- fclose(f);
-}
-
-WxxObject *WxxFileHandle::open(WxxObjectPtr name)
-{
- std::string strname = name.get_string();
- f = fopen(strname.c_str(), "r");
- return this;
-}
-
-WxxObject *WxxFileHandle::open(WxxObjectPtr name, WxxObjectPtr mode)
-{
- if (f)
- throw wxx_error("FileHandle is already open");
- std::string strname = name.get_string();
- std::string strmode = mode.get_string();
- for (size_t i = 0; i < strmode.length(); ++i) {
- switch (strmode[i]) {
- case 'r':
- case 'w':
- case 'a':
- case 'b':
- break;
- default:
- throw wxx_error("Invalid mode in open");
- }
- }
- f = fopen(strname.c_str(), strmode.c_str());
- return this;
-}
-
-WxxObjectPtr WxxFileHandle::close()
-{
- int r;
- if (f) {
- r = fclose(f);
- f = 0;
- }
- else
- r = -1;
- return r;
-}
-
-void WxxFileHandle::print(WxxObjectPtr obj)
-{
- if (! f)
- throw wxx_error("FileHandle is closed");
- fputs(obj.get_string().c_str(), f);
-}
-
-WxxObjectPtr WxxFileHandle::read(int n)
-{
- if (! f)
- throw wxx_error("FileHandle is closed");
- char *buf = (char *)malloc(n);
- *buf = '\0';
- size_t r = fread(buf, 1, n, f);
- //std::cerr << "\nread " << r << "\n";
- std::string result = r > 0 ? std::string(buf, r) : std::string();
- free(buf);
- return WxxObjectPtr(result);
-}
-
-WxxObjectPtr WxxFileHandle::readline()
-{
- if (! f)
- throw wxx_error("FileHandle is closed");
- char buffer[1024];
- const char *r = fgets(buffer, 1024, f);
- if (! r)
- r = "";
- return WxxObjectPtr(std::string(r));
-}
-
-WxxObjectPtr WxxFileHandle::call_method(const std::string &methname, WxxObjectArray &args)
-{
- if (methname == "readline") {
- if (args.elements() > 0)
- throw wxx_error("too many positional arguments in readline");
- return readline();
- }
- if (methname == "read") {
- if (args.elements() != 1)
- throw wxx_error("wrong number of positional arguments in read");
- return read(args.get_pmc_keyed(0));
- }
- if (methname == "open") {
- switch (args.elements()) {
- case 1:
- return open(args.get_pmc_keyed(0));
- case 2:
- return open(args.get_pmc_keyed(0), args.get_pmc_keyed(1));
- default:
- throw wxx_error("too many positional arguments in close");
- }
- }
- if (methname == "close") {
- if (args.elements() > 0)
- throw wxx_error("too many positional arguments in close");
- return close();
- }
- if (methname == "eof") {
- if (args.elements() > 0)
- throw wxx_error("too many positional arguments in close");
- return feof(f);
- }
- else
- return WxxDefault::call_method(methname, args);
-}
-
-#endif
-
-//*************************************************************
-
WxxNCI::WxxNCI(const std::string &funcname) :
WxxDefault("NCI"),
name(funcname)
@@ -793,19 +514,6 @@ WxxObjectPtr WxxInstance::call_method(const std::string &methname, WxxObjectArra
//*************************************************************
-WxxObjectPtr wxx_getstdin()
-{
- return WxxObjectPtr(new WxxFileHandle(1));
-}
-WxxObjectPtr wxx_getstdout()
-{
- return WxxObjectPtr(new WxxFileHandle(2));
-}
-WxxObjectPtr wxx_getstderr()
-{
- return WxxObjectPtr(new WxxFileHandle(3));
-}
-
WxxObjectPtr wxx_new(std::string name)
{
//std::cerr << "wxx_new " << name << '\n';
View
112 winxedxx_classes.cxx
@@ -421,6 +421,118 @@ void WxxString::print() { std::cout << str; }
//*************************************************************
+WxxArrayBase::WxxArrayBase(const std::string &name) :
+ WxxDefault(name)
+{
+}
+
+int WxxArrayBase::get_integer()
+{
+ return elements();
+}
+
+WxxObjectPtr WxxArrayBase::get_iter()
+{
+ return WxxObjectPtr(new WxxArrayIterator(this));
+}
+
+//*************************************************************
+
+WxxArrayIterator::WxxArrayIterator(WxxObject *container) :
+ WxxDefault("ArrayIterator"),
+ cnt(container),
+ current(0)
+{
+ cnt->incref();
+}
+
+WxxArrayIterator::~WxxArrayIterator()
+{
+ cnt->decref();
+}
+
+int WxxArrayIterator::get_bool()
+{
+ return current < cnt->elements();
+}
+
+WxxObjectPtr WxxArrayIterator::shift_pmc()
+{
+ return cnt->get_pmc_keyed(current++);
+}
+
+//*************************************************************
+
+WxxObjectArray::WxxObjectArray() :
+ WxxArrayBase("ResizablePMCArray")
+{
+}
+
+WxxObjectArray::~WxxObjectArray()
+{
+ for (unsigned int i = 0; i < arr.size(); ++i)
+ delete arr[i];
+}
+
+int WxxObjectArray::elements()
+{
+ return arr.size();
+}
+
+WxxObjectPtr WxxObjectArray::get_pmc_keyed(int i)
+{
+ return this->operator[](i);
+}
+
+WxxObjectPtr WxxObjectArray::operator[](int i) const
+{
+ int size = arr.size();
+ if (i < 0)
+ i += size;
+ if (i < 0)
+ throw wxx_error(getname() + ": index out of bounds!");
+ if (i >= size)
+ return winxedxxnull;
+ return WxxObjectPtr(*(arr[i]));
+}
+
+WxxObjectArray& WxxObjectArray::push(WxxObjectPtr obj)
+{
+ arr.push_back(new WxxObjectPtr(obj));
+ return *this;
+}
+
+WxxObjectArray& WxxObjectArray::push(int i)
+{
+ arr.push_back(new WxxObjectPtr(i));
+ return *this;
+}
+
+WxxObjectArray& WxxObjectArray::push(double value)
+{
+ arr.push_back(new WxxObjectPtr(value));
+ return *this;
+}
+
+WxxObjectArray& WxxObjectArray::push(const char *str)
+{
+ arr.push_back(new WxxObjectPtr(str));
+ return *this;
+}
+
+WxxObjectArray& WxxObjectArray::push(const std::string &str)
+{
+ arr.push_back(new WxxObjectPtr(str));
+ return *this;
+}
+
+void WxxObjectArray::set_pmc_keyed(int i, const WxxObjectPtr &value)
+{
+ arr[i] = new WxxObjectPtr(value);
+}
+
+//*************************************************************
+
WxxLibrary::WxxLibrary(void *dl_handle) :
WxxDefault("ParrotLibrary"),
dl_h(dl_handle)
View
12 winxedxx_integer.h
@@ -83,6 +83,18 @@ class WxxObjectArray : public WxxArrayBase
std::vector<WxxObjectPtr *> arr;
};
+class WxxArrayIterator : public WxxDefault
+{
+public:
+ WxxArrayIterator(WxxObject *container);
+ ~WxxArrayIterator();
+ int get_bool();
+ WxxObjectPtr shift_pmc();
+private:
+ WxxObject *cnt;
+ int current;
+};
+
class WxxLibrary : public WxxDefault
{
public:
View
6 winxedxx_object.h
@@ -2,7 +2,7 @@
#define INCLUDE_WINXEDXX_OBJECT_H
// winxedxx_object.h
-// Revision 10-may-2011
+// (C) 2011 Julián Albo "NotFound"
namespace WinxedXX
{
@@ -52,6 +52,10 @@ class WxxObject
virtual ~WxxObject() { }
};
+WxxObjectPtr wxx_getstdin();
+WxxObjectPtr wxx_getstdout();
+WxxObjectPtr wxx_getstderr();
+
} // namespace WinxedXX
#endif
View
13 winxedxx_util.cxx
@@ -5,6 +5,7 @@
#include "winxedxx_object.h"
#include "winxedxx_default.h"
#include "winxedxx_integer.h"
+#include "winxedxx_handle.h"
#include <sstream>
@@ -72,6 +73,18 @@ WxxObjectPtr wxx_error(const std::string &message, int severity, int type)
return WxxObjectPtr((WxxObject *)new WxxException(message, severity, type));
}
+WxxObjectPtr wxx_getstdin()
+{
+ return WxxObjectPtr(new WxxFileHandle(1));
+}
+WxxObjectPtr wxx_getstdout()
+{
+ return WxxObjectPtr(new WxxFileHandle(2));
+}
+WxxObjectPtr wxx_getstderr()
+{
+ return WxxObjectPtr(new WxxFileHandle(3));
+}
WxxObjectPtr wxx_loadlib(const std::string &libname)
{

0 comments on commit 21f52be

Please sign in to comment.