Box.h

Go to the documentation of this file.
00001 
00007 #ifndef BOX_H
00008 #define BOX_H
00009 
00010 // #define BOX_DEBUG
00011 
00012 #include "OwnerBox.h"
00013 
00014 template <class Owner, class Data> class Box {
00015 
00016   friend class OwnerBox<Owner,Data>;
00017 
00018   private:
00019 
00020     Box(OwnerBox<Owner,Data>* o, int n = -1):
00021 #ifdef BOX_DEBUG
00022       state(CLOSED), user(n),
00023 #endif
00024       ownerBox(o) {}
00025 
00026     ~Box(void) {};
00027 
00028 #ifdef BOX_DEBUG
00029     enum box_state {OPEN, CLOSED} state;
00030 #endif
00031 
00032     OwnerBox<Owner,Data> *ownerBox;     
00033 
00034   public:
00035 #ifdef BOX_DEBUG
00036   int user;
00037 #endif
00038 
00039     Data* open(void) {
00040       ownerBox->openCount--;
00041 #ifdef BOX_DEBUG
00042       if (ownerBox->openCount < 0) NAMD_bug("too many boxes opened");
00043       if (state != CLOSED) NAMD_bug("box re-opened");
00044       state = OPEN; 
00045 #endif
00046       return ownerBox->data; 
00047     }
00048 
00049     void close(Data ** const t) {
00050       *t = NULL;
00051       ownerBox->closeCount--;
00052 #ifdef BOX_DEBUG
00053       if (ownerBox->closeCount < 0) NAMD_bug("too many boxes closed");
00054       if (state != OPEN) NAMD_bug("box re-closed");
00055       state = CLOSED;
00056 #endif
00057       // Trigger callback!
00058       if ( ! ownerBox->closeCount ) {
00059         ownerBox->close();
00060       }
00061     }
00062 
00063     void skip(void) {
00064       ownerBox->openCount--;
00065       ownerBox->closeCount--;
00066 #ifdef BOX_DEBUG
00067       if (state != CLOSED) NAMD_bug("box skipped while open");
00068       if (ownerBox->openCount < 0) NAMD_bug("too many boxes opened");
00069       if (ownerBox->closeCount < 0) NAMD_bug("too many boxes closed");
00070 #endif
00071       if ( ! ownerBox->closeCount ) {
00072         ownerBox->close();
00073       }
00074     }
00075 
00076 };
00077 
00078 #endif // BOX_H

Generated on Sat Sep 23 01:17:11 2017 for NAMD by  doxygen 1.4.7