#ifndef GBI_H #define GBI_H #include "../gambas.h" #include "../gb_common.h" #include #include #include extern "C" GB_INTERFACE GB; namespace GBI { template class ObjectArray { public: ObjectArray(const char* className, unsigned int siz = 0) : array(0) { GB.Array.New(&array, GB.FindClass(className), siz); } ObjectArray(const char *className, std::vector &vect); ~ObjectArray(); T* at(unsigned int i) const; void push_back(T* value); void push_back(const ObjectArray *otherArray); void push_back(const std::vector *otherArray); unsigned int size() const{return GB.Array.Count(array);} unsigned int length() const{return GB.Array.Count(array);} unsigned int count() const{return GB.Array.Count(array);} GB_ARRAY array; }; template ObjectArray::ObjectArray(const char *className, std::vector &vect) : array(0) { GB.Array.New(&array, GB.FindClass(className), 0); for(unsigned int i = 0; i < vect.size(); i++) { push_back(vect.at(i)); } } template T* New(const std::string className, char* eventName = "", void* parent = 0) { return reinterpret_cast(GB.New(GB.FindClass(className.c_str()), eventName, parent)); } template void ObjectArray::push_back(T* value) { *(reinterpret_cast((GB.Array.Add(this->array)))) = value; GB.Ref(value); } template void ObjectArray::push_back(const ObjectArray *otherArray) { for(unsigned int i = 0; i < otherArray->length(); i++) { push_back(otherArray->at(i)); } } template void ObjectArray::push_back(const std::vector *otherArray) { for(unsigned int i = 0; i < otherArray->size(); i++) { push_back(otherArray->at(i)); } } template T* ObjectArray::at(unsigned int i) const { return *(reinterpret_cast(GB.Array.Get(this->array,i))); } template ObjectArray::~ObjectArray() { for(unsigned int i = 0; i < this->count(); i++) { //std::cout << "-1 tab "<< this->at(i) <<" (" << (this->at(i)->ref - 1) << ") "; GB.Unref(reinterpret_cast(GB.Array.Get(this->array,i))); } // GB.Unref(POINTER((void*)(&(this->array)))); } } #endif // GBI_H