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

ByteArray.h

Go to the documentation of this file.
00001 /*
00002  * ByteArray.h
00003  *
00004  * Smalltalk like class library for C++
00005  * Array of bytes. Header.
00006  *
00007  * Copyright (c) 2003 Jan Vrany
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 #ifndef __BYTEARRAY_H
00025 #define __BYTEARRAY_H
00026 
00027 #include <stlib/SequenceableCollection.h>
00028 #include <stlib/String.h>
00029 
00030 namespace Core {
00031 
00032 class Integer;
00033 class InternalEncodedStreamFactory;
00034         
00035 class ByteArray : public SequenceableCollection
00036 {
00037   protected:
00039     unsigned char * bytes;
00040 
00042     long tally;
00043 
00044   public:
00048     ByteArray(int size = 0);
00049 
00051     ByteArray(const ByteArray &origin);
00052 
00062     ByteArray(const char * buffer, int size);
00063     ~ByteArray(void);
00064 
00065     virtual String* className(void) const
00066     { return new String("ByteArray"); }
00067 
00068     /* Instance creation protocol */
00069     static ByteArray *fromStringEncoding(const String *string, String *encoding);
00070 
00071     /* Accessing protocol */
00073     virtual long int size() const
00074     { return tally; }
00075 
00086     virtual Object* at(int index) const;
00087 
00097     virtual void put(int index, Object* obj);
00098 
00099     virtual void replace(long start, long stop,
00100                          const SequenceableCollection *collection)
00101     { SequenceableCollection::replace(start, stop, collection); }
00102     virtual void replace(long start, long stop, unsigned char *collection);
00103     virtual void replace(long start, long stop,
00104                          const SequenceableCollection *collection, long startIndex)
00105     { SequenceableCollection::replace(start, stop, collection, startIndex); }
00106     virtual void replace(long start, long stop,
00107                          unsigned char *collection, long startIndex);
00108 
00118     virtual void changeSize(long newSize);
00119 
00123     virtual void add(Object* obj);
00124 
00130     virtual Object *copy(void);
00131     virtual Object *copy(long from, long to)
00132       { return SequenceableCollection::copy(from, to); }
00133 
00135     virtual Object *copyEmpty(long int size);
00136 
00144     virtual unsigned char *rawBytes(void) const;
00145 
00155     virtual const unsigned char *rawBytesReadOnly(void) const;
00156 
00157     /* Comparing protocol */
00158     virtual long hash(void) const;
00159     virtual bool isEqual(const Object *object) const;
00160     virtual bool isEqual(const Object &object) const
00161       { return SequenceableCollection::isEqual(object); }
00162     virtual bool isEqual(const char *array, int size) const;
00163     virtual bool isEqualToByteArray(const Object *array) const;
00164 
00165     /* Converting protocol */
00166     virtual ByteArray *asByteArray(void);
00167 
00169     virtual char *asCString(void);
00170     virtual String *asString(void);
00171     virtual String *asStringWithEncoding(String *encoding);
00172     virtual String *asStringWithEncoding(const char *encoding);
00173     virtual unsigned long asInteger(void);
00174     virtual unsigned long asNumberWithRadix(int radix);
00175 
00176     /* Stream construction protocol */
00177     virtual InternalEncodedStreamFactory *withEncoding(String *encoding);
00178     virtual InternalEncodedStreamFactory *withEncoding(const char *encoding);
00179 
00180     /* Testing protocol */
00181     virtual bool isByteArray(void);
00182 
00183   private:
00188     virtual void checkObject(Object *obj, const char *sel);
00189 };
00190 
00191 };
00192 
00193 #endif /* __BYTEARRAY_H */

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