Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CharacterArray.cc

Go to the documentation of this file.
00001 /*
00002  * CharacterArray.cc
00003  *
00004  * Smalltalk like class library for C++
00005  * String implementor using Array of Characters.
00006  *
00007  * Copyright (c) 2004 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #include <stlib/CharacterArray.h>
00025 #include <stlib/Array.h>
00026 #include <stlib/Character.h>
00027 #include <stlib/String.h>
00028 
00029 using namespace Core;
00030 
00031 CharacterArray::CharacterArray(int size)
00032 {
00033     content = new Array(size);
00034 }
00035 
00036 CharacterArray::~CharacterArray(void)
00037 {
00038     delete content;
00039 }
00040 
00041 /* Class-accessing protocol */
00042 String *CharacterArray::className(void) const
00043 {
00044     return new String("CharacterArray");
00045 }
00046 
00047 /* Accessing protocol */
00048 Character *CharacterArray::at(int index) const
00049 {
00050     return dynamic_cast<Character *>(content->at(index));
00051 }
00052 
00053 void CharacterArray::put(int index, Character *object)
00054 {
00055     content->put(index, object);
00056 }
00057 
00058 int CharacterArray::byteSize(void)
00059 {
00060     return 4;
00061 }
00062 
00063 long CharacterArray::size(void) const
00064 {
00065     return content->size();
00066 }
00067 
00068 /* Adding protocol */
00069 void CharacterArray::changeSize(long newSize)
00070 {
00071     content->changeSize(newSize);
00072 }
00073 
00074 /* Comparing protocol */
00075 bool CharacterArray::isEqual(StringImpl *string)
00076 {
00077     for (int i = 0; i < size(); i++) {
00078         if (!this->at(i)->isEqual(string->at(i)))
00079             return false;
00080     }
00081     return true;
00082 }
00083 
00084 bool CharacterArray::isEqualToBytes(unsigned char *string)
00085 {
00086     for (int i = 0; i < size(); i++) {
00087         if (this->at(i)->asInteger() != string[i])
00088             return false;
00089     }
00090     return true;
00091 }
00092 
00093 bool CharacterArray::isEqualToShorts(unsigned short *string)
00094 {
00095     for (int i = 0; i < size(); i++) {
00096         if (this->at(i)->asInteger() != string[i])
00097             return false;
00098     }
00099     return true;
00100 }
00101 
00102 /* Converting protocol */
00103 CharacterArray *CharacterArray::asCharacterArray(void)
00104 {
00105     return this;
00106 }
00107 
00108 /* Testing protocol */
00109 bool CharacterArray::isCharacterArray(void) const
00110 {
00111     return true;
00112 }

Generated on Mon Nov 27 09:47:54 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2