Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Box.h

Go to the documentation of this file.
00001 
00007 #ifndef BOX_H
00008 #define BOX_H
00009 
00010 #include "OwnerBox.h"
00011 
00012 template <class Owner, class Data> class Box {
00013 
00014   friend class OwnerBox<Owner,Data>;
00015 
00016   private:
00017 
00018     Box(OwnerBox<Owner,Data>* o): ownerBox(o) { state = CLOSED; };
00019 
00020     ~Box(void) {};
00021 
00022     enum box_state {OPEN, CLOSED} state;
00023     OwnerBox<Owner,Data> *ownerBox;     
00024 
00025   public:
00026 
00027     Data* open(void) {
00028       if (state != OPEN) {
00029         state = OPEN; 
00030         ownerBox->openCount--;
00031       }
00032       return ownerBox->data; 
00033     }
00034     void close(Data ** const t) {
00035       if (state != CLOSED) {
00036         state = CLOSED;
00037         *t = NULL;
00038 
00039         // Trigger callback!
00040         if ( ! --ownerBox->closeCount ) {
00041           ownerBox->close();
00042         }
00043       }
00044     }
00045 
00046 };
00047 
00048 #endif // BOX_H

Generated on Fri Jul 25 04:07:14 2008 for NAMD by  doxygen 1.3.9.1