//---------------------------------------------------------------------------- // EDGE Platform Interface Utility //---------------------------------------------------------------------------- // // Copyright (c) 2004-2005 The EDGE Team. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // //---------------------------------------------------------------------------- #include "utility.h" #include #define STRBOX_ALIGN(x) x = ((x + 4) & ~3) namespace epi { // ---> strbox_c // // strbox_c Constructor // strbox_c::strbox_c() { strs = NULL; numstrs = 0; data = NULL; datasize = 0; } // // strbox_c Copy constructor // strbox_c::strbox_c(strbox_c &rhs) { Copy(rhs); } // // strbox_c Destructor // strbox_c::~strbox_c() { Clear(); } // // strbox_c::Clear() // void strbox_c::Clear() { if (strs) delete [] strs; if (data) delete [] data; strs = NULL; numstrs = 0; data = NULL; } // // strbox_c::Copy() // void strbox_c::Copy(strbox_c &src) { Clear(); // Allocate new data data = new char[src.datasize]; strs = new char*[src.numstrs]; // Set appropriate sizes datasize = src.datasize; numstrs = src.numstrs; // Copy the data from source memcpy(data, src.data, sizeof(char)*datasize); memcpy(strs, src.strs, sizeof(char*)*numstrs); // Reset the pointers in the table to look at new data int i; int offset = data - src.data; for (i=0; i strent_c // // strent_c::Set() // void strent_c::Set(const char *s) { Clear(); if (s) { data = new char[strlen(s)+1]; strcpy(data, s); } } // // strent_c::Set() // void strent_c::Set(const char *s, int max) { Clear(); if (s) { const char *s2; int len; len = 0; s2 = s; while(*s2 && len strlist_c // // strlist_c Constructor // strlist_c::strlist_c() : array_c(sizeof(char*)) { } // // strlist_c Copy constructor // strlist_c::strlist_c(strlist_c &rhs) : array_c(rhs.array_objsize) { Copy(rhs); } // // strlist Destructor // strlist_c::~strlist_c() { Clear(); } // // strlist_c::CleanupObject() // void strlist_c::CleanupObject(void *obj) { char *s = *(char**)obj; if (s) delete [] s; } // // strlist_c::Copy() // void strlist_c::Copy(strlist_c &src) { // Enlarge to required size Size(src.array_entries); // Copy contents array_iterator_c it; for (it = src.GetBaseIterator(); it.IsValid(); it++) Insert(ITERATOR_TO_TYPE(it, char*)); Trim(); } // // int strlist_c::Find() // int strlist_c::Find(const char* refname) { array_iterator_c it; char *s; for (it = GetBaseIterator(); it.IsValid(); it++) { s = ITERATOR_TO_TYPE(it, char*); if (s && strcmp(s, refname) == 0) return it.GetPos(); } return -1; } // // int strlist_c::Insert() // int strlist_c::Insert(const char *s) { char *copy_of_s; if (s) { copy_of_s = new char[strlen(s)+1]; strcpy(copy_of_s, s); } else { copy_of_s = NULL; } return InsertObject((void*)©_of_s); } // // strlist_c::Set() // // Reads in data from a strbox_c object // void strlist_c::Set(strbox_c &src) { Clear(); // Check we haven't something to do if (!src.GetSize()) return; // // Lets not fragment memory when we don't need to - allocate // the correct size of array now // Size(src.GetSize()); int i; for (i=0; i String Table // // strtable_c Copy constructor // strtable_c::strtable_c(strtable_c &rhs) { Copy(rhs); } // // strtable_c::Clear() // // Not use on destruction, just here if you want a blank table // void strtable_c::Clear() { refs.Clear(); values.Clear(); } // // strtable_c::Copy() // void strtable_c::Copy(strtable_c &src) { refs = src.refs; values = src.values; } // // strtable_c::Set() // void strtable_c::Set(strbox_c &_refs, strbox_c &_values) { if (_refs.GetSize() != _values.GetSize()) return; // FIXME!! Throw an error refs = _refs; values = _values; } // // strtable_c assignment operator // strtable_c& strtable_c::operator=(strtable_c &rhs) { if (&rhs != this) Copy(rhs); return *this; } };