00001
00002 #ifndef __JBXL_CPP_EXTEND_GRAPHIC_DATA_H_
00003 #define __JBXL_CPP_EXTEND_GRAPHIC_DATA_H_
00004
00005
00013 #include "Gdata.h"
00014
00015
00016
00017 namespace jbxl {
00018
00019
00021
00022
00023
00080 template <typename T=uWord> class ExMSGraph : public MSGraph<T>
00081 {
00082 public:
00083
00084 int* refno;
00085
00086
00087 public:
00088 ExMSGraph(int x, int y=1, int z=1, T v=(T)0, T b=(T)0, double rz=1.0, int* rn=NULL) { set(x, y, z, v, b, rz, rn);}
00089 ExMSGraph(RBound<int> rb, T v=(T)0, T b=(T)0, double rz=1.0, int* rn=NULL){ set(rb, v, b, rz, rn);}
00090 ExMSGraph(int* rn=NULL) { MSGraph<T>::init(); setRefer(rn);}
00091 virtual ~ExMSGraph(void) {}
00092
00093 void set(int x, int y=1, int z=1, T v=(T)0, T b=(T)0, double rz=1.0, int*rn=NULL);
00094 void set(RBound<int> rb, T v=(T)0, T b=(T)0, double rz=1.0, int*rn=NULL);
00095 void mimicry(ExMSGraph<T> s) { set(s.xs, s.ys, s.zs, s.zero, s.base, s.RZxy, NULL);}
00096
00097 bool isNull(void);
00098 void free(void);
00099 void mfree(bool azero=false);
00100 void ffree(void);
00101 void setRefer(int* rn);
00102
00103 ExMSGraph<T> operator= (ExMSGraph<T>& s);
00104 ExMSGraph<T> operator= (MSGraph<T>& s);
00105 };
00106
00107
00108
00109
00110 template <typename T> void ExMSGraph<T>::set(RBound<int> rb, T v, T b, double rz, int* rn) {
00111 set(rb.xmax-rb.xmin+1, rb.ymax-rb.ymin+1, rb.zmax-rb.zmin+1, v, b, rz, rn);
00112 MSGraph<T>::rbound = rb;
00113 return;
00114 }
00115
00116
00117
00118
00119 template <typename T> void ExMSGraph<T>::set(int x, int y, int z, T v, T b, double rz, int* rn)
00120 {
00121 if (z<=0) z = 1;
00122
00123 MSGraph<T>::getm(x, y, z, v);
00124 if (MSGraph<T>::gp==NULL) return;
00125
00126 MSGraph<T>::base = b;
00127 if (rz==0.0) MSGraph<T>::RZxy = 1.0;
00128 else MSGraph<T>::RZxy = rz;
00129 MSGraph<T>::rbound.set(0, x-1, 0, y-1, 0, z-1);
00130
00131 if (rn!=NULL) setRefer(rn);
00132 else if (refno!=NULL) {
00133 if (MSGraph<T>::gp==NULL) *refno = -1;
00134 else *refno = 1;
00135 }
00136 return;
00137 }
00138
00139
00140
00141
00142 template <typename T> void ExMSGraph<T>::setRefer(int* rn)
00143 {
00144 refno = rn;
00145 if (refno!=NULL) {
00146 if (MSGraph<T>::gp==NULL) *refno = -1;
00147 else *refno = 1;
00148 }
00149 }
00150
00151
00152
00153
00154 template <typename T> bool ExMSGraph<T>::isNull(void)
00155 {
00156 if (MSGraph<T>::gp==NULL) return true;
00157
00158 #ifdef WIN32
00159 if (MSGraph<T>::gp==(T*)WIN_DD_NULL) return true;
00160 #endif
00161
00162 if (refno!=NULL) {
00163 if (*refno<0) return true;
00164 else return false;
00165 }
00166 return false;
00167 }
00168
00169
00170
00179 template <typename T> void ExMSGraph<T>::free(void)
00180 {
00181 if (refno==NULL) {
00182 if (!isNull()) {
00183 ::free(MSGraph<T>::gp);
00184 MSGraph<T>::init();
00185 }
00186 }
00187 else {
00188 mfree();
00189 }
00190 return;
00191 }
00192
00193
00194
00205 template <typename T> void ExMSGraph<T>::mfree(bool azero)
00206 {
00207 if (refno!=NULL) {
00208 (*refno)--;
00209 if (!azero && *refno==0) {
00210 ::free(MSGraph<T>::gp);
00211 *refno = -1;
00212 MSGraph<T>::init();
00213 }
00214 else if (*refno==-1) {
00215 DEBUG_MODE PRINT_MESG("ExMSGraph<T>::mfree: [警告] 通常ありえない参照数 0\n");
00216 }
00217 else if (*refno<-1) {
00218 *refno = -1;
00219 }
00220 }
00221
00222 return;
00223 }
00224
00225
00226
00232 template <typename T> void ExMSGraph<T>::ffree()
00233 {
00234 if (refno==NULL) {
00235 if (!isNull()) {
00236 ::free(MSGraph<T>::gp);
00237 }
00238 }
00239 else {
00240 if (*refno>=0) {
00241 ::free(MSGraph<T>::gp);
00242 *refno = -1;
00243 }
00244 }
00245 MSGraph<T>::init();
00246 return;
00247 }
00248
00249
00250
00251
00252
00253 template <typename T> ExMSGraph<T> ExMSGraph<T>::operator= (ExMSGraph<T>& s)
00254 {
00255 ExMSGraph<T> dm = *this;
00256
00257 MSGraph<T>::xs = s.xs;
00258 MSGraph<T>::ys = s.ys;
00259 MSGraph<T>::zs = s.zs;
00260 MSGraph<T>::gp = s.gp;
00261 MSGraph<T>::zero = s.zero;
00262 MSGraph<T>::base = s.base;
00263
00264 MSGraph<T>::max = s.max;
00265 MSGraph<T>::min = s.min;
00266 MSGraph<T>::color = s.color;
00267 MSGraph<T>::state = s.state;
00268 MSGraph<T>::rbound = s.rbound;
00269 MSGraph<T>::RZxy = s.RZxy;
00270 MSGraph<T>::norm = s.norm;
00271
00272 MSGraph<T>::wRateX = s.wRateX;
00273 MSGraph<T>::wRateY = s.wRateY;
00274 MSGraph<T>::wRateZ = s.wRateZ;
00275 MSGraph<T>::wZeroX = s.wZeroX;
00276 MSGraph<T>::wZeroY = s.wZeroY;
00277 MSGraph<T>::wZeroZ = s.wZeroZ;
00278 MSGraph<T>::wNowX = s.wNowX;
00279 MSGraph<T>::wNowY = s.wNowY;
00280 MSGraph<T>::wNowZ = s.wNowZ;
00281
00282 if (!s.isNull()) {
00283 if (s.refno!=NULL) {
00284 if (*s.refno>=0) {
00285 refno = s.refno;
00286 (*refno)++;
00287 }
00288 else {
00289 DEBUG_MODE PRINT_MESG("ExMSGraph<T>::= (ExMSGraph): コピー元参照数変数の不正!!\n");
00290 }
00291 }
00292 else {
00293 if (refno!=NULL) {
00294 if (*refno<=-1) *refno = 1;
00295 else refno = NULL;
00296 }
00297 }
00298 }
00299
00300 else {
00301 MSGraph<T>::gp = NULL;
00302 if (s.refno!=NULL) {
00303 refno = s.refno;
00304 *refno = -1;
00305 }
00306 else {
00307 if (refno!=NULL) {
00308 if (*refno<=-1) *refno = -1;
00309 else refno = NULL;
00310 }
00311 }
00312 }
00313
00314 if (!dm.isNull()) dm.mfree();
00315 return *this;
00316 }
00317
00318
00319
00320
00321
00322 template <typename T> ExMSGraph<T> ExMSGraph<T>::operator= (MSGraph<T>& s)
00323 {
00324 if (!isNull()) mfree();
00325
00326 MSGraph<T>::xs = s.xs;
00327 MSGraph<T>::ys = s.ys;
00328 MSGraph<T>::zs = s.zs;
00329 MSGraph<T>::gp = s.gp;
00330 MSGraph<T>::zero = s.zero;
00331 MSGraph<T>::base = s.base;
00332
00333 MSGraph<T>::max = s.max;
00334 MSGraph<T>::min = s.min;
00335 MSGraph<T>::color = s.color;
00336 MSGraph<T>::state = s.state;
00337 MSGraph<T>::rbound = s.rbound;
00338 MSGraph<T>::RZxy = s.RZxy;
00339 MSGraph<T>::norm = s.norm;
00340
00341 MSGraph<T>::wRateX = s.wRateX;
00342 MSGraph<T>::wRateY = s.wRateY;
00343 MSGraph<T>::wRateZ = s.wRateZ;
00344 MSGraph<T>::wZeroX = s.wZeroX;
00345 MSGraph<T>::wZeroY = s.wZeroY;
00346 MSGraph<T>::wZeroZ = s.wZeroZ;
00347 MSGraph<T>::wNowX = s.wNowX;
00348 MSGraph<T>::wNowY = s.wNowY;
00349
00350 if (!s.isNull()) {
00351 if (refno!=NULL) {
00352 if (*refno<=-1) *refno = 1;
00353 else refno = NULL;
00354 }
00355 }
00356
00357 else {
00358 MSGraph<T>::gp = NULL;
00359 if (refno!=NULL) {
00360 if (*refno<=-1) *refno = -1;
00361 else refno = NULL;
00362 }
00363 }
00364
00365 return *this;
00366 }
00367
00368
00369
00370
00372
00373
00374
00383 class ExCmnHead : public CmnHead
00384 {
00385 public:
00386 int state;
00387 int dbyte;
00388
00389
00390 int* refno;
00391
00392 public:
00393 ExCmnHead(int x, int y=1, int z=1, int d=8, int* rn=NULL) { set(x, y, z, d, rn);}
00394 ExCmnHead(RBound<int> rb, int d=8, int* rn=NULL) { set(rb, d, rn);}
00395 ExCmnHead(int* rn=NULL) { init(); setRefer(rn);}
00396 ExCmnHead(ExCmnHead& cmhd) = default;
00397 virtual ~ExCmnHead(void) {}
00398
00399 void init(void);
00400
00401 void set (RBound<int> rb, int d=8, int* rn=NULL);
00402 void set (int x, int y=1, int z=1, int d=8, int* rn=NULL);
00403 void getm(int x, int y=1, int z=1, int d=8);
00404
00405 void clear() {memset(grptr, 0, lsize);}
00406 uByte& point(int x, int y=0, int z=0) { return grptr[dbyte*(x+xsize*y+xsize*ysize*z)];}
00407
00408 bool isNull(void);
00409 void free(void);
00410 void mfree(bool azero=false);
00411 void ffree(void);
00412 void setRefer(int* rn);
00413
00414
00415 ExCmnHead operator= (ExCmnHead& m);
00416 ExCmnHead operator= (CmnHead& m);
00417 };
00418
00419
00420
00421 }
00422
00423
00424
00425 #endif //__JBXL_CPP_EXTEND_GRAPHIC_DATA_H_