![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Generic Element Handling * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXElement.h,v 1.28 2009/01/06 13:07:23 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXELEMENT_H 00024 #define FXELEMENT_H 00025 00026 namespace FX { 00027 00028 /**************************** D e f i n i t i o n ****************************/ 00029 00030 // Generic implementations for generic objects 00031 00032 00033 /// Construct some elements at a location 00034 template<class EType> 00035 inline void constructElms(EType* ptr,unsigned long n){ 00036 while(n--){ ::new ((void*)ptr) EType; ptr++; } 00037 } 00038 00039 00040 /// Destruct some elements at a location 00041 template<class EType> 00042 inline void destructElms(EType* ptr,unsigned long n){ 00043 while(n--){ ptr->~EType(); ptr++; } 00044 } 00045 00046 00047 /// Copy some elements from one place to another 00048 template<class EType> 00049 inline void copyElms(EType* dst,const EType* src,unsigned long n){ 00050 while(n--){ *dst++ = *src++; } 00051 } 00052 00053 00054 /// Move some elements from overlapping place to another 00055 template<class EType> 00056 inline void moveElms(EType* dst,const EType* src,unsigned long n){ 00057 if(src>dst){ 00058 while(n--){ *dst++ = *src++; } 00059 } 00060 else if(dst>src){ 00061 dst+=n; 00062 src+=n; 00063 while(n--){ *--dst = *--src; } 00064 } 00065 } 00066 00067 00068 /// Fill array of elements with given element 00069 template<class EType> 00070 inline void fillElms(EType* dst,const EType& src,unsigned long n){ 00071 while(n--){ *dst++ = src; } 00072 } 00073 00074 00075 /// Zero out array of elements 00076 template<class EType> 00077 inline void clearElms(EType* dst,unsigned long n){ 00078 memset(dst,0,sizeof(EType)*n); 00079 } 00080 00081 00082 /// Allocate array of elements, uninitialized 00083 template<class EType> 00084 inline FXbool allocElms(EType*& ptr,unsigned long n){ 00085 return fxmalloc((void**)&ptr,sizeof(EType)*n); 00086 } 00087 00088 00089 /// Allocate array of elements, initialized with zero 00090 template<class EType> 00091 inline FXbool callocElms(EType*& ptr,unsigned long n){ 00092 return fxcalloc((void**)&ptr,sizeof(EType)*n); 00093 } 00094 00095 00096 /// Allocate array of elements, initialized with bit-wise copy of src array 00097 template<class EType> 00098 inline FXbool dupElms(EType*& ptr,const EType* src,unsigned long n){ 00099 return fxmemdup((void**)&ptr,src,sizeof(EType)*n); 00100 } 00101 00102 00103 /// Resize array of elements, without constructor or destructor 00104 template<class EType> 00105 inline FXbool resizeElms(EType*& ptr,unsigned long n){ 00106 return fxresize((void**)&ptr,sizeof(EType)*n); 00107 } 00108 00109 00110 /// Free array of elements, without destruction 00111 template<class EType> 00112 inline void freeElms(EType*& ptr){ 00113 fxfree((void**)&ptr); 00114 } 00115 00116 00117 /********************** I m p l e m e n t a t i o n ************************/ 00118 00119 // Specific implementations for built-in types 00120 00121 00122 // No-op constructors for array of basic type 00123 inline void constructElms(FXuchar*,unsigned long){ } 00124 inline void constructElms(FXchar*,unsigned long){ } 00125 inline void constructElms(FXushort*,unsigned long){ } 00126 inline void constructElms(FXshort*,unsigned long){ } 00127 inline void constructElms(FXuint*,unsigned long){ } 00128 inline void constructElms(FXint*,unsigned long){ } 00129 inline void constructElms(FXfloat*,unsigned long){ } 00130 inline void constructElms(FXdouble*,unsigned long){ } 00131 00132 // No-op destructors for array of basic type 00133 inline void destructElms(FXuchar*,unsigned long){ } 00134 inline void destructElms(FXchar*,unsigned long){ } 00135 inline void destructElms(FXushort*,unsigned long){ } 00136 inline void destructElms(FXshort*,unsigned long){ } 00137 inline void destructElms(FXuint*,unsigned long){ } 00138 inline void destructElms(FXint*,unsigned long){ } 00139 inline void destructElms(FXfloat*,unsigned long){ } 00140 inline void destructElms(FXdouble*,unsigned long){ } 00141 00142 // Simple bit-wise copy for array of basic type 00143 inline void copyElms(FXuchar* dst,const FXuchar* src,unsigned long n){ memcpy(dst,src,n); } 00144 inline void copyElms(FXchar* dst,const FXchar* src,unsigned long n){ memcpy(dst,src,n); } 00145 inline void copyElms(FXushort* dst,const FXushort* src,unsigned long n){ memcpy(dst,src,n<<1); } 00146 inline void copyElms(FXshort* dst,const FXshort* src,unsigned long n){ memcpy(dst,src,n<<1); } 00147 inline void copyElms(FXuint* dst,const FXuint* src,unsigned long n){ memcpy(dst,src,n<<2); } 00148 inline void copyElms(FXint* dst,const FXint* src,unsigned long n){ memcpy(dst,src,n<<2); } 00149 inline void copyElms(FXfloat* dst,const FXfloat* src,unsigned long n){ memcpy(dst,src,n<<2); } 00150 inline void copyElms(FXdouble* dst,const FXdouble* src,unsigned long n){ memcpy(dst,src,n<<3); } 00151 00152 // Simple bit-wise copy for array of pointers to any type 00153 template<class EType> inline void copyElms(EType** dst,const EType** src,unsigned long n){ memcpy(dst,src,n*sizeof(void*)); } 00154 00155 // Simple bit-wise move for array of basic type 00156 inline void moveElms(FXuchar* dst,const FXuchar* src,unsigned long n){ memmove(dst,src,n); } 00157 inline void moveElms(FXchar* dst,const FXchar* src,unsigned long n){ memmove(dst,src,n); } 00158 inline void moveElms(FXushort* dst,const FXushort* src,unsigned long n){ memmove(dst,src,n<<1); } 00159 inline void moveElms(FXshort* dst,const FXshort* src,unsigned long n){ memmove(dst,src,n<<1); } 00160 inline void moveElms(FXuint* dst,const FXuint* src,unsigned long n){ memmove(dst,src,n<<2); } 00161 inline void moveElms(FXint* dst,const FXint* src,unsigned long n){ memmove(dst,src,n<<2); } 00162 inline void moveElms(FXfloat* dst,const FXfloat* src,unsigned long n){ memmove(dst,src,n<<2); } 00163 inline void moveElms(FXdouble* dst,const FXdouble* src,unsigned long n){ memmove(dst,src,n<<3); } 00164 00165 // Simple bit-wise move for array of pointers to any type 00166 template<class EType> inline void moveElms(EType** dst,const EType** src,unsigned long n){ memmove(dst,src,n*sizeof(void*)); } 00167 00168 // Fill byte arrays with constant 00169 inline void fillElms(FXuchar* dst,const FXuchar& src,unsigned long n){ memset(dst,src,n); } 00170 inline void fillElms(FXchar* dst,const FXchar& src,unsigned long n){ memset(dst,src,n); } 00171 00172 } 00173 00174 #endif
![]() |