#ifndef __CArray_H #define __CArray_H //--------------------------------------------------------------------------- /* 배열 래퍼 템플릿 클래스. java, C# 처럼 배열과 그 배열의 크기를 지정한 클래스. 주의할 것은 배열크기는 처음에 지정하면 변화시키지 못한다. 변화 시키려면 인자로 썼던 모배열의 크기를 변화 시키고 다시 이 클래스에 대입하면 된다. 이 클래스는 배열에 대한 서비스형 래퍼클래스이기 때문이다. 하지만 CArray[n] = 데이타; 식으로 값일 직접 변경하는 것은 무방하다. Written by KTS. */ template class CArray { T *Array; public: int Length; public: CArray() { Array = NULL; Length = 0; } CArray(T *array, int length) { SetArray(array, length); } void SetArray(T *array, int length) { Array = array; Length = length; } T& operator [] (int idx) { if (idx < 0 || idx >= Length) throw new Exception("CArray[] : index is out of length"); return Array[idx]; } bool IsExists(T item) { return GetIndex(item) >= 0; } int GetIndex(T item) { for(int c = 0; c < Length; c++) { if (item == Array[c]) return c; } return -1; } }; typedef CArray CArrayInt; typedef CArray CArrayPChar; typedef CArray CArrayString; typedef CArray CArrayAnsiString; typedef CArray CArrayWideString; //typedef CArray CArrayUnicodeString; //--------------------------------------------------------------------------- #endif