00001
00014 #ifndef ATOMMAP_H
00015 #define ATOMMAP_H
00016
00017 #include "NamdTypes.h"
00018
00019 #ifdef MEM_OPT_VERSION
00020
00021 struct AtomMapEntry {
00022 AtomMapEntry *next;
00023 int pid;
00024 short index;
00025 short aid_upper;
00026 };
00027
00028 #endif
00029
00030 enum { notUsed = -1 };
00031
00032 class AtomMap
00033 {
00034 public:
00035 static AtomMap *Instance();
00036 inline static AtomMap *Object() { return CkpvAccess(AtomMap_instance); }
00037 ~AtomMap(void);
00038 void checkMap();
00039
00040 void allocateMap(int nAtomIDs);
00041
00042 LocalID localID(AtomID id);
00043
00044 friend class AtomMapper;
00045
00046 protected:
00047 AtomMap(void);
00048
00049 private:
00050 int registerIDsCompAtomExt(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end);
00051 int registerIDsFullAtom(PatchID pid, const FullAtom *begin, const FullAtom *end);
00052 int unregisterIDsCompAtomExt(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end);
00053 int unregisterIDsFullAtom(PatchID pid, const FullAtom *begin, const FullAtom *end);
00054
00055 #ifdef MEM_OPT_VERSION
00056 AtomMapEntry **entries;
00057 bool onlyUseTbl;
00058 #endif
00059
00060 LocalID *localIDTable;
00061 int tableSz;
00062
00063 };
00064
00065 #ifndef MEM_OPT_VERSION
00066
00067
00068
00069 inline LocalID AtomMap::localID(AtomID id)
00070 {
00071 return localIDTable[id];
00072 }
00073 #endif
00074
00075
00076 class AtomMapper {
00077 public:
00078 AtomMapper(PatchID _pid) : pid(_pid), mapped(0), map(AtomMap::Object()) {}
00079 ~AtomMapper() {
00080 if ( mapped ) NAMD_bug("deleted AtomMapper with atoms still mapped");
00081 }
00082 void registerIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end);
00083 void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end);
00084 void unregisterIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end);
00085 void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end);
00086
00087 private:
00088 const PatchID pid;
00089 int mapped;
00090 AtomMap *map;
00091 #ifdef MEM_OPT_VERSION
00092 ResizeArray<AtomMapEntry> entries;
00093 #endif
00094 };
00095
00096
00097 #endif
00098