summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Bus/Ivy/DataTypes.h117
1 files changed, 65 insertions, 52 deletions
diff --git a/Bus/Ivy/DataTypes.h b/Bus/Ivy/DataTypes.h
index 85be4d6..99b6e05 100644
--- a/Bus/Ivy/DataTypes.h
+++ b/Bus/Ivy/DataTypes.h
@@ -2,13 +2,15 @@
#ifdef WIN32
#ifdef IVY_EXPORTS
-class _declspec(dllexport) string;
+//class _declspec(dllexport) string;
#else
-#pragma comment(lib,"Ivy.LIB" )
-class _declspec(dllimport) string;
+//#pragma comment(lib,"Ivy.LIB" )
+//class _declspec(dllimport) string;
#endif
#endif
+#include <string.h>
+
class string {
public:
string(size_t len = 0)
@@ -24,17 +26,16 @@ public:
}
~string()
- { delete ptr; }
+ { delete [] ptr; }
size_t length()
{ return size; }
bool empty() const
{ return size==0; }
void copy( const char * s, int len )
{
- char *newptr = allocBuffer( len );
- strncpy( newptr, s, len );
if ( ptr ) delete [] ptr;
- ptr = newptr;
+ ptr = allocBuffer( len );
+ strncpy( ptr, s, len );
}
void erase(int start=0, int len = -1)
{
@@ -59,7 +60,7 @@ public:
newptr = allocBuffer( size + len );
strncpy( newptr , ptr, index );
strncpy( newptr+index , s, len ) ;
- strncpy( newptr+index+len , &ptr[index], len ) ;
+ strncpy( newptr+index+len , &ptr[index], size - (index+len) ) ;
delete ptr;
ptr = newptr;
}
@@ -82,6 +83,10 @@ public:
{
append( s.ptr, s.size );
}
+ operator +=(const char* s)
+ {
+ append( s, strlen(s) );
+ }
operator +=(char c)
{ append( &c, 1);}
string operator +(string s) const
@@ -138,8 +143,10 @@ public:
{ptr = p;}
T& operator*() const
{return ptr->value; }
- T* operator->() const
- {return &(ptr->value); }
+// T* operator->() const
+// {return &(ptr->value); }
+// T* operator->() const
+// {return (&**this); }
iterator& operator++()
{ptr = ptr->next;
return (*this); }
@@ -148,7 +155,7 @@ public:
++*this;
return (tmp); }
iterator& operator--()
- {ptr = ptr.prev;);
+ {ptr = ptr.prev;
return (*this); }
iterator operator--(int)
{iterator tmp = *this;
@@ -169,28 +176,53 @@ public:
};
list()
- { head = 0; }
+ {
+ head = new Node;
+ head->next = head->prev = head;
+ }
+ ~list()
+ {
+ clear();
+ delete head;
+ }
bool empty()
- { return head == 0 ; }
+ { return head->next == head ; }
T& front()
- {return head->value; }
- iterator erase(iterator n)
+ {return (*begin()); }
+ const T& front() const
+ {return (*begin()); }
+ T& back()
+ {return (*(--end())); }
+ const T& back() const
+ {return (*(--end())); }
+ iterator erase(iterator p)
{
- NodePtr p = n.prev();
- NodePtr s = (n++).node();
- delete p->next;
- p->next = s;
- s->prev = p;
- return n;
+ NodePtr s = (p++).node();
+ s->prev->next = s->next;
+ s->next->prev = s->prev;
+ delete s;
+ return (p);
}
- void pop_front()
+
+ iterator insert(iterator p, const T& v =T())
{
- NodePtr newhead = head->next;
- newhead->prev = head->prev;
- head->prev->next = newhead;
- delete head;
- head = (head == newhead) ? 0 : newhead;
+ NodePtr s = p.node();
+ NodePtr newnode = new Node;
+ newnode->value = v;
+ newnode->prev = s->prev;
+ newnode->next = s;
+ s->prev->next = newnode;
+ s->prev = newnode;
+ return (iterator(newnode));
}
+ void push_front(const T& v)
+ {insert(begin(), v); }
+ void pop_front()
+ {erase(begin()); }
+ void push_back(const T& v)
+ {insert(end(), v); }
+ void pop_back()
+ {erase(--end()); }
iterator erase(iterator first, iterator last)
{
while (first != last)
@@ -199,22 +231,7 @@ public:
}
void clear()
{erase(begin(), end()); }
- void push_back( T value )
- {
- NodePtr p = new Node;
- p->value = value;
- if ( head )
- {
- p->next = head;
- p->prev = head->prev;
- head->prev->next = p;
- head->prev = p;
- }
- else {
- head = p;
- p->next = p->prev = p;
- }
- }
+
void remove( const T& data )
{
iterator last = end();
@@ -225,13 +242,9 @@ public:
++iter;
}
iterator begin()
- {return (iterator(head)); }
+ {return (iterator(head->next)); }
iterator end()
- {
- if (head )
- return (iterator(head->prev));
- else return (iterator(head));
- }
+ {return (iterator(head));}
protected:
NodePtr head;
@@ -249,14 +262,14 @@ public:
if ( index >= len )
{
size_t i;
- T* newdata = new T[index+1];
+ T* newdata = new T[index];
for ( i = 0; i < len ; i ++ )
newdata[i] = data[i];
- for ( i = len; i < index+1 ; i ++ )
+ for ( i = len; i < index ; i ++ )
newdata[i] = 0;
if ( data ) delete [] data;
data = newdata;
- len = index+1;
+ len = index;
}
}
// Accesses indexed component of vector