Array.h

Go to the documentation of this file.
00001 #ifndef JAVA_LANG_OBJECT_H
00002 #include <java_lang/Object.h>
00003 #endif /* JAVA_LANG_OBJECT_H */
00004 // All header files that are included in JObject.h should move its includes to top
00005 
00006 #ifndef JAVA_LANG_ARRAY_H
00007 #define JAVA_LANG_ARRAY_H 1
00008 
00009 namespace java {
00010   namespace lang {
00011 
00018     template <class Type>
00019       class 
00020       Array : public Object {
00021 
00022     public:
00023 
00024       /*
00025        * Array constructor.
00026        * @param sz the initial size of the array
00027        *  if sz < 0 then the array's size is -sz.
00028        *  it will reference the src and won't release memory automatically. 
00029        *  Any assignment to the array element will change the original array.
00030        *  Any operation that change the capacity will force the
00031        *  array to allocate and copy the values.
00032        *  if src is 0 Array will allocated normally without 
00033        *  initial values. 
00034        * @param src the initial source value array 
00035        */
00036       Array(jint sz = 0);
00037       Array(jint sz, const Type* src);
00038       Array(const Array& src);
00039       virtual ~Array();
00040       Array& operator=(const Type&);
00041       Array& operator=(const Array&);
00042       Array& operator+=(const Type&);
00043       Array& operator+=(const Array&);
00044       Array operator+(const Type& src) const { return (*this)+=src;}
00045       Array operator+(const Array& src) const { return (*this)+=src;}
00046       operator Type*() const { return value;}
00047       Type& operator[](jint index) const { return value[index];}
00048 
00056       jint length() const { return size;}
00057 
00064       void setLength(jint newLength);
00065 
00069       void trimToLength(jint newLength = -1);
00070 
00078       jint capacity() const { return cap;}
00079 
00087       void ensureCapacity(jint minimumCapacity);
00088 
00096       static void arraycopy(Type* dest, const Type* sorc, jint len);
00097 
00106       void copy(jint dofs, const Array& sorc, jint sofs = 0, jint len = -1);
00107 
00119       virtual jboolean equals(const Object& a) const;
00120 
00132       virtual jboolean equals(const Array& a) const;
00133 
00167       virtual jint hashCode() const;
00168 
00190       virtual String toString() const;
00191 
00208       void fill(const Type& v, jint fromIndex = 0, jint toIndex = -1);
00209 
00220       void insert(const Type& v, jint index = -1);
00221 
00232       void insert(const Array& v, jint index = -1);
00233 
00244       void remove(jint index, jint toIndex = 0);
00245 
00254       void swap(jint index1, jint index2);
00255 
00266       jint find(const Type& key, jint fromIndex=0, jint toIndex=-1) const;
00267 
00297       jint binarySearch(const Type& key, jint fromIndex=0, jint toIndex=-1) const;
00298 
00312       void sort(jint fromIndex = 0, jint toIndex = -1);
00313 
00314       /*
00315        * Copy the data from provided source array.
00316        * @param src the array to copy from.
00317        */
00318       void copyFrom(const Array<ObjectRef>& src);
00319 
00320       /*
00321        * Copy the data into provided destination array.
00322        * @param dst the array to copy into.
00323        */
00324       void copyInto(Array<ObjectRef>& dst) const;
00325 
00326     protected:
00327 
00328       void init(const Type*, jint _cap);
00329       Type *value;
00330       jint size;
00331       jint cap;
00332   
00333     private:
00334 
00335       REGISTER_MEMBERS;
00336 
00337     };
00338 
00339   } // namespace lang
00340 } // namespace java
00341 
00342 #endif /* JAVA_LANG_ARRAY_H */

Generated on Fri May 16 11:54:42 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3