From 87abbc06c1146ff80457407150c4e212b4ed4916 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:12 +0000 Subject: Utilisateur : Fcolin Date : 30/01/01 Heure : 17:33 Créé (vss 1) --- Ivy/DataTypes.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Ivy/DataTypes.h (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h new file mode 100644 index 0000000..e69de29 -- cgit v1.1 From dc8fec9b2b2d00be9751afde91a14d2a841039f4 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:14 +0000 Subject: Utilisateur : Fcolin Date : 31/01/01 Heure : 11:18 Archivé dans $/Ivy (vss 2) --- Ivy/DataTypes.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index e69de29..53bef2b 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -0,0 +1,81 @@ +#pragma once + +#ifdef WIN32 +#ifdef IVY_EXPORTS +class _declspec(dllexport) string; +#else +#pragma comment(lib,"Ivy.LIB" ) +class _declspec(dllimport) string; +#endif +#endif + +class string { +public: + string(); + string( const char * s); + int length(); + bool empty(); + void erase(int start=0, int len = -1); + void append( const char *s , int len ); + void insert(int index, const char * s); + string substr( int start, int len = -1 ); + int find_first_of( const char* s ); + int rfind( char c ); + operator +=(string s); + string operator +(string s); + // Nondestructive typecast operator + operator const char*() const; + const char *c_str() const; // remove this ugly thing +}; + +template class Iterator { +public: + T & operator !=(Iterator i); + T & operator ++(); + operator const T*() const; + T & second; + +}; + + +template class list { +public: + void clear(); + bool empty(); + T front(); + pop_front(); + void push_back( T data ); + typedef Iterator iterator; + iterator begin(); + iterator end(); + void remove( T data ); +}; + +template class vector { +public: + void clear(); + int size(); + // Nondestructive typecast operator + operator const T*() const; + // Accesses indexed component of vector + T & operator [](int i); + // Accesses indexed component of vector + const T & operator [](int i) const; + void push_back( T data ); + void remove( T data ); + +}; + +template class map { +public: + void clear(); + int size(); + bool empty(); + find(I i ); + typedef Iterator iterator; + iterator begin(); + iterator end(); + void erase( I i ); + // Accesses indexed component of vector + const T & operator [](I i) const; +}; \ No newline at end of file -- cgit v1.1 From 5ee431e3130e11fd8450222ec95402cca01594fa Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:16 +0000 Subject: Utilisateur : Fcolin Date : 2/02/01 Heure : 18:30 Archivé dans $/Ivy Commentaire: win CE compile not finished (vss 3) --- Ivy/DataTypes.h | 321 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 268 insertions(+), 53 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 53bef2b..85be4d6 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -11,71 +11,286 @@ class _declspec(dllimport) string; class string { public: - string(); - string( const char * s); - int length(); - bool empty(); - void erase(int start=0, int len = -1); - void append( const char *s , int len ); - void insert(int index, const char * s); - string substr( int start, int len = -1 ); - int find_first_of( const char* s ); - int rfind( char c ); - operator +=(string s); - string operator +(string s); + string(size_t len = 0) + { ptr = allocBuffer( len ); }; + string ( const string& s ) + { ptr = 0; copy( s.ptr, s.size ); } + string( const char * s, int len = -1 ) + { + ptr = 0; + if ( len < 0 ) + len = strlen(s) ; + copy( s, len ); + } + + ~string() + { 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; + } + void erase(int start=0, int len = -1) + { + char *newptr; + size_t real_len; + real_len = len < 0 ? size - start : len; + if ( real_len > size ) real_len = size; + newptr = allocBuffer( size - real_len ); + strncpy( newptr, ptr , start ); + strncpy( &newptr[start], &ptr[start+real_len], size - start ); + delete ptr; + ptr = newptr; + } + void append( const char *s , int len = -1 ) + { + insert ( size, s , len ); + } + void insert(int index, const char * s, int len = -1) + { + char *newptr; + if ( len < 0 ) len = strlen(s) ; + newptr = allocBuffer( size + len ); + strncpy( newptr , ptr, index ); + strncpy( newptr+index , s, len ) ; + strncpy( newptr+index+len , &ptr[index], len ) ; + delete ptr; + ptr = newptr; + } + string substr( int start, int len = -1 ) + { return string ( &ptr[start], len ); } + int find_first_of( const char* strCharSet ) + { char *fnd = strpbrk( ptr, strCharSet ); if ( fnd ) return fnd - ptr; else return -1; } + int rfind( char c ) + { char *fnd = strrchr( ptr, c); if ( fnd ) return fnd - ptr; else return -1; } +// friend string operator + (const string& left, const char* right); +// friend string operator + (const char* left, const string& right); + friend string operator + (const string& left, const string& right) + { + string str( left.size + right.size ); + str.append( left.ptr, left.size); + str.append( right.ptr, right.size); + return str; + } + operator +=(string s) + { + append( s.ptr, s.size ); + } + operator +=(char c) + { append( &c, 1);} + string operator +(string s) const + { string str ( ptr, size ); str.append( s.ptr, s.size ); return str; } + string operator +(const char c) const + { string str ( ptr, size ); str.append( &c, 1); return str; } + string& operator=(const string& s) + { copy(s.ptr,s.size); return *this; } + string& operator=(const char* s) + { copy(s,strlen(s)); return *this; } // Nondestructive typecast operator - operator const char*() const; - const char *c_str() const; // remove this ugly thing + operator const char*() const + { return ptr; } + const char *c_str() const // remove this ugly thing + { return ptr; } +private: + char *ptr; + size_t size; + // always allocate one extra character for '\0' termination + char *allocBuffer(int len) + { + char *newptr; + size = len; + newptr = new char[len+1] ; + newptr[len] = '\0'; + return newptr; + } + }; -template class Iterator { -public: - T & operator !=(Iterator i); - T & operator ++(); - operator const T*() const; - T & second; -}; template class list { + +protected: + struct _Node; + friend struct _Node; + typedef struct _Node Node; + typedef Node* NodePtr; + struct _Node { + NodePtr next, prev; + T value; + }; + public: - void clear(); - bool empty(); - T front(); - pop_front(); - void push_back( T data ); - typedef Iterator iterator; - iterator begin(); - iterator end(); - void remove( T data ); + + friend class iterator; + class iterator { + public: + iterator() + {ptr = 0;} + iterator(NodePtr p) + {ptr = p;} + T& operator*() const + {return ptr->value; } + T* operator->() const + {return &(ptr->value); } + iterator& operator++() + {ptr = ptr->next; + return (*this); } + iterator operator++(int) + {iterator tmp = *this; + ++*this; + return (tmp); } + iterator& operator--() + {ptr = ptr.prev;); + return (*this); } + iterator operator--(int) + {iterator tmp = *this; + --*this; + return (tmp); } + bool operator==(const iterator& p) const + {return (ptr == p.ptr); } + bool operator!=(const iterator& p) const + {return (ptr != p.ptr); } + NodePtr next() const + {return ptr->next; }; + NodePtr prev() const + {return ptr->prev ; }; + NodePtr node() const + {return (ptr); } + protected: + NodePtr ptr; + }; + + list() + { head = 0; } + bool empty() + { return head == 0 ; } + T& front() + {return head->value; } + iterator erase(iterator n) + { + NodePtr p = n.prev(); + NodePtr s = (n++).node(); + delete p->next; + p->next = s; + s->prev = p; + return n; + } + void pop_front() + { + NodePtr newhead = head->next; + newhead->prev = head->prev; + head->prev->next = newhead; + delete head; + head = (head == newhead) ? 0 : newhead; + } + iterator erase(iterator first, iterator last) + { + while (first != last) + erase(first++); + return (first); + } + 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(); + for (iterator iter = begin(); iter != last; ) + if (*iter == data) + erase(iter++); + else + ++iter; + } + iterator begin() + {return (iterator(head)); } + iterator end() + { + if (head ) + return (iterator(head->prev)); + else return (iterator(head)); + } + protected: + NodePtr head; + }; template class vector { public: - void clear(); - int size(); - // Nondestructive typecast operator - operator const T*() const; - // Accesses indexed component of vector - T & operator [](int i); + + vector ( ) + { data = 0; len = 0; } + size_t size() + { return len; } + void reserve( size_t index ) + { + if ( index >= len ) + { + size_t i; + T* newdata = new T[index+1]; + for ( i = 0; i < len ; i ++ ) + newdata[i] = data[i]; + for ( i = len; i < index+1 ; i ++ ) + newdata[i] = 0; + if ( data ) delete [] data; + data = newdata; + len = index+1; + } + } // Accesses indexed component of vector - const T & operator [](int i) const; - void push_back( T data ); - void remove( T data ); - + T & operator [](size_t index ) + { + // reserve( index ); // TODO or NOT check range + return data[index] ; + } + T & operator [](size_t index ) const + { + return data[index] ; + } + void push_back( const T& value ) + { + T* newdata = new T[len+1]; + for ( unsigned int i = 0; i < len ; i ++ ) + newdata[i] = data[i]; + newdata[len++] = value; + if ( data ) delete [] data; + data = newdata; + } + void erase( int i ) + { + data[i] = 0; + } + void clear() + { + delete [] data; + data = 0; + len = 0; + } + +private: + T* data; + size_t len; }; -template class map { -public: - void clear(); - int size(); - bool empty(); - find(I i ); - typedef Iterator iterator; - iterator begin(); - iterator end(); - void erase( I i ); - // Accesses indexed component of vector - const T & operator [](I i) const; -}; \ No newline at end of file -- cgit v1.1 From 6faa30da0755977ed7dab2e6190519221f39915b Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:18 +0000 Subject: Utilisateur : Fcolin Date : 14/02/01 Heure : 18:47 Archivé dans $/Ivy (vss 4) --- Ivy/DataTypes.h | 117 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 52 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 85be4d6..99b6e05 100644 --- a/Ivy/DataTypes.h +++ b/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 + 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 -- cgit v1.1 From 4ab2c9cd41abe5f904272cb2f5260fa6caed2138 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:20 +0000 Subject: Utilisateur : Fcolin Date : 27/06/01 Heure : 14:24 Archivé dans $/Ivy (vss 5) --- Ivy/DataTypes.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 99b6e05..acc4aa0 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -260,6 +260,9 @@ public: void reserve( size_t index ) { if ( index >= len ) + resize( index ); + } + void resize( size_t index ) { size_t i; T* newdata = new T[index]; @@ -271,7 +274,6 @@ public: data = newdata; len = index; } - } // Accesses indexed component of vector T & operator [](size_t index ) { -- cgit v1.1 From fe66807c8cefa06f12c6af5798d2ed3e14aa953c Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:22 +0000 Subject: Utilisateur : Fcolin Date : 5/11/02 Heure : 9:57 Archivé dans $/Bus/Ivy Commentaire: (vss 6) --- Ivy/DataTypes.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index acc4aa0..2267de7 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -79,16 +79,18 @@ public: str.append( right.ptr, right.size); return str; } - operator +=(string s) + const string& operator +=(string s) { - append( s.ptr, s.size ); + return append( s.ptr, s.size ); } - operator +=(const char* s) + const string& operator +=(const char* s) { - append( s, strlen(s) ); + return append( s, strlen(s) ); + } + const string& operator +=(char c) + { + return append( &c, 1); } - operator +=(char c) - { append( &c, 1);} string operator +(string s) const { string str ( ptr, size ); str.append( s.ptr, s.size ); return str; } string operator +(const char c) const -- cgit v1.1 From 52382fb13d0312f26ba0f13da9ad3fb12a218e02 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:24 +0000 Subject: Utilisateur : Fcolin Date : 5/02/04 Heure : 18:32 Archivé dans $/Bus/Ivy Commentaire: (vss 7) --- Ivy/DataTypes.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 2267de7..daf9470 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -79,18 +79,21 @@ public: str.append( right.ptr, right.size); return str; } - const string& operator +=(string s) - { - return append( s.ptr, s.size ); - } - const string& operator +=(const char* s) + + void operator +=(string s) { - return append( s, strlen(s) ); + append( s.ptr, s.size ); } - const string& operator +=(char c) + + void operator +=(const char* s) { - return append( &c, 1); + append( s, strlen(s) ); } + + void operator +=(char c) + { append( &c, 1);} + + string operator +(string s) const { string str ( ptr, size ); str.append( s.ptr, s.size ); return str; } string operator +(const char c) const -- cgit v1.1 From 5d4fda6bd381bf67c37326c74abbcdd33b02f622 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:26 +0000 Subject: Utilisateur : Fcolin Date : 2/06/05 Heure : 18:42 Archivé dans $/Bus/Ivy Commentaire: Suppression de la STL et ajout d'un namespace pour les datatypes internes Ivy (vss 8) --- Ivy/DataTypes.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index daf9470..c98a812 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -11,6 +11,9 @@ #include +namespace ivy +{ + class string { public: string(size_t len = 0) @@ -314,3 +317,4 @@ private: size_t len; }; +} \ No newline at end of file -- cgit v1.1 From 8e052a7abf762456b5794468049457335d7a4be9 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:28 +0000 Subject: Utilisateur : Fcolin Date : 2/06/05 Heure : 18:45 Archivé dans $/Bus/Ivy Commentaire: (vss 9) --- Ivy/DataTypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index c98a812..ea17c37 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -142,7 +142,7 @@ protected: public: - friend class iterator; + //friend class iterator; class iterator { public: iterator() -- cgit v1.1 From 8d5a7b300f69298500e97762987ccd36174c288a Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:30 +0000 Subject: Utilisateur : Fcolin Date : 23/09/05 Heure : 15:27 Archivé dans $/Bus/Ivy Commentaire: (vss 10) --- Ivy/DataTypes.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index ea17c37..190a7a6 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -16,14 +16,15 @@ namespace ivy class string { public: + static const size_t npos = size_t(-1); string(size_t len = 0) { ptr = allocBuffer( len ); }; string ( const string& s ) { ptr = 0; copy( s.ptr, s.size ); } - string( const char * s, int len = -1 ) + string( const char * s, size_t len = npos ) { ptr = 0; - if ( len < 0 ) + if ( len == npos ) len = strlen(s) ; copy( s, len ); } @@ -34,17 +35,17 @@ public: { return size; } bool empty() const { return size==0; } - void copy( const char * s, int len ) + void copy( const char * s, size_t len ) { if ( ptr ) delete [] ptr; ptr = allocBuffer( len ); strncpy( ptr, s, len ); } - void erase(int start=0, int len = -1) + void erase(size_t start=0, size_t len = npos) { char *newptr; size_t real_len; - real_len = len < 0 ? size - start : len; + real_len = len == npos ? size - start : len; if ( real_len > size ) real_len = size; newptr = allocBuffer( size - real_len ); strncpy( newptr, ptr , start ); @@ -52,14 +53,14 @@ public: delete ptr; ptr = newptr; } - void append( const char *s , int len = -1 ) + void append( const char *s , size_t len = npos ) { insert ( size, s , len ); } - void insert(int index, const char * s, int len = -1) + void insert(size_t index, const char * s, size_t len = npos) { char *newptr; - if ( len < 0 ) len = strlen(s) ; + if ( len == npos ) len = strlen(s) ; newptr = allocBuffer( size + len ); strncpy( newptr , ptr, index ); strncpy( newptr+index , s, len ) ; @@ -67,12 +68,12 @@ public: delete ptr; ptr = newptr; } - string substr( int start, int len = -1 ) + string substr( size_t start, size_t len = npos ) { return string ( &ptr[start], len ); } - int find_first_of( const char* strCharSet ) - { char *fnd = strpbrk( ptr, strCharSet ); if ( fnd ) return fnd - ptr; else return -1; } - int rfind( char c ) - { char *fnd = strrchr( ptr, c); if ( fnd ) return fnd - ptr; else return -1; } + size_t find_first_of( const char* strCharSet ) + { char *fnd = strpbrk( ptr, strCharSet ); if ( fnd ) return (size_t)(fnd - ptr); else return npos; } + size_t rfind( char c ) + { char *fnd = strrchr( ptr, c); if ( fnd ) return (size_t)(fnd - ptr); else return npos; } // friend string operator + (const string& left, const char* right); // friend string operator + (const char* left, const string& right); friend string operator + (const string& left, const string& right) @@ -114,7 +115,7 @@ private: char *ptr; size_t size; // always allocate one extra character for '\0' termination - char *allocBuffer(int len) + char *allocBuffer(size_t len) { char *newptr; size = len; @@ -295,7 +296,7 @@ public: void push_back( const T& value ) { T* newdata = new T[len+1]; - for ( unsigned int i = 0; i < len ; i ++ ) + for ( size_t i = 0; i < len ; i ++ ) newdata[i] = data[i]; newdata[len++] = value; if ( data ) delete [] data; -- cgit v1.1 From e66ce001f6b6ff89fa0804d167d16e73f12a5d4b Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:32 +0000 Subject: Utilisateur : Fcolin Date : 16/11/05 Heure : 9:54 Archivé dans $/Bus/Ivy Commentaire: 64 bits ports (vss 11) --- Ivy/DataTypes.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 190a7a6..280c2de 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -10,7 +10,7 @@ #endif #include - +#include namespace ivy { @@ -39,17 +39,19 @@ public: { if ( ptr ) delete [] ptr; ptr = allocBuffer( len ); - strncpy( ptr, s, len ); + strncpy_s( ptr, len + 1, s, len ); } void erase(size_t start=0, size_t len = npos) { char *newptr; size_t real_len; + size_t buf_size; real_len = len == npos ? size - start : len; if ( real_len > size ) real_len = size; - newptr = allocBuffer( size - real_len ); - strncpy( newptr, ptr , start ); - strncpy( &newptr[start], &ptr[start+real_len], size - start ); + buf_size = size - real_len; + newptr = allocBuffer( buf_size ); + strncpy_s( newptr, buf_size +1, ptr , start ); + strncpy_s( &newptr[start], buf_size +1 - start, &ptr[start+real_len], size - start ); delete ptr; ptr = newptr; } @@ -61,10 +63,11 @@ public: { char *newptr; if ( len == npos ) len = strlen(s) ; - newptr = allocBuffer( size + len ); - strncpy( newptr , ptr, index ); - strncpy( newptr+index , s, len ) ; - strncpy( newptr+index+len , &ptr[index], size - (index+len) ) ; + size_t buf_len = size + len; + newptr = allocBuffer( buf_len ); + strncpy_s( newptr , buf_len +1, ptr, index ); + strncpy_s( newptr+index, buf_len + 1 - index, s, len ) ; + strncpy_s( newptr+index+len, buf_len + 1 - index -len, &ptr[index], size - (index+len) ) ; delete ptr; ptr = newptr; } -- cgit v1.1 From e69d66f4d8d2871c8643d27b5fc04732826f8459 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 12:54:34 +0000 Subject: Utilisateur : Fcolin Date : 17/11/05 Heure : 15:08 Archivé dans $/Bus/Ivy Commentaire: nice Bug in nextArg not reentrant routine due to static variable (vss 12) --- Ivy/DataTypes.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Ivy/DataTypes.h') diff --git a/Ivy/DataTypes.h b/Ivy/DataTypes.h index 280c2de..8afc4ce 100644 --- a/Ivy/DataTypes.h +++ b/Ivy/DataTypes.h @@ -1,19 +1,23 @@ #pragma once + +#include + +namespace ivy +{ #ifdef WIN32 #ifdef IVY_EXPORTS -//class _declspec(dllexport) string; +class _declspec(dllexport) string; +template class _declspec(dllexport) list; +template class _declspec(dllexport) vector; #else -//#pragma comment(lib,"Ivy.LIB" ) -//class _declspec(dllimport) string; +#pragma comment(lib,"Ivy.LIB" ) +class _declspec(dllimport) string; +template class _declspec(dllimport) list; +template class _declspec(dllimport) vector; #endif #endif -#include -#include -namespace ivy -{ - class string { public: static const size_t npos = size_t(-1); -- cgit v1.1