Changes in / [326a43b:cbf01e]
- Files:
-
- 18 added
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/Doxyfile
r326a43b rcbf01e 114 114 EXCLUDE = 115 115 EXCLUDE_SYMLINKS = NO 116 EXCLUDE_PATTERNS = 116 EXCLUDE_PATTERNS = */unittests/* \ 117 */test/* 117 118 EXAMPLE_PATH = 118 119 EXAMPLE_PATTERNS = * … … 126 127 #--------------------------------------------------------------------------- 127 128 SOURCE_BROWSER = YES 128 INLINE_SOURCES = NO129 STRIP_CODE_COMMENTS = YES129 INLINE_SOURCES = YES 130 STRIP_CODE_COMMENTS = NO 130 131 REFERENCED_BY_RELATION = NO 131 132 REFERENCES_RELATION = NO -
src/Actions/Process.cpp
r326a43b rcbf01e 41 41 } 42 42 43 void Process::setCurrStep(int _currStep){ 44 OBSERVE; 45 currStep = _currStep; 46 } 47 43 48 float Process::getDoneRatio() { 44 49 if(getMaxSteps()) … … 51 56 } 52 57 58 void Process::setMaxSteps(int _maxSteps){ 59 maxSteps = _maxSteps; 60 } 53 61 54 62 void Process::start(){ … … 69 77 starts = false; 70 78 } 79 71 80 void Process::step(){ 72 81 OBSERVE; 73 82 currStep++; 74 83 } 84 75 85 void Process::stop(){ 76 86 stops = true; -
src/Actions/Process.hpp
r326a43b rcbf01e 29 29 bool doesStop(); 30 30 int getCurrStep(); 31 void setCurrStep(int _currStep); 31 32 float getDoneRatio(); 32 33 int getMaxSteps(); 34 void setMaxSteps(int _maxSteps); 33 35 34 36 protected: -
src/Descriptors/AtomDescriptor.hpp
r326a43b rcbf01e 15 15 #include "World.hpp" 16 16 17 class World; 17 18 class atom; 18 19 … … 21 22 22 23 class AtomDescriptor { 24 // close coupling to the world to allow access 23 25 friend atom* World::getAtom(AtomDescriptor descriptor); 24 26 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor); 27 friend class World::AtomIterator; 25 28 26 29 friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); -
src/Descriptors/AtomDescriptor_impl.hpp
r326a43b rcbf01e 1 #include "Descriptors/AtomDescriptor.hpp" 1 #ifndef ATOMDESCRIPTOR_IMPL_HPP 2 #define ATOMDESCRIPTOR_IMPL_HPP 2 3 3 4 /************************ Declarations of implementation Objects ************************/ … … 72 73 AtomDescriptor::impl_ptr arg; 73 74 }; 75 76 #endif //ATOMDESCRIPTOR_IMPL_HPP -
src/Descriptors/AtomIdDescriptor.cpp
r326a43b rcbf01e 22 22 23 23 bool AtomIdDescriptor_impl::predicate(std::pair<int,atom*> atom) { 24 return atom. second->getId()==id;24 return atom.first==id; 25 25 } 26 26 … … 29 29 } 30 30 31 #if 0 32 33 // so far the lookuptable for Atoms-by-id does not work, since atoms don't get an ID upon creation. 34 // instead of this we rely on walking through all atoms. 35 36 atom *AtomIdDescriptor::find(){ 31 atom *AtomIdDescriptor_impl::find(){ 37 32 map<int,atom*> atoms = getAtoms(); 38 33 map<int,atom*>::iterator res = atoms.find(id); … … 40 35 } 41 36 42 vector<atom*> AtomIdDescriptor ::findAll(){37 vector<atom*> AtomIdDescriptor_impl::findAll(){ 43 38 atom *res = find(); 44 39 return (res)?(vector<atom*>(1,res)):(vector<atom*>()); 45 40 } 46 47 #endif -
src/Descriptors/AtomIdDescriptor_impl.hpp
r326a43b rcbf01e 1 #include "Descriptors/AtomIdDescriptor.hpp" 1 #ifndef ATOMIDDESCRIPTOR_IMPL_HPP 2 #define ATOMIDDESCRIPTOR_IMPL_HPP 3 2 4 #include "Descriptors/AtomDescriptor_impl.hpp" 3 5 … … 11 13 12 14 protected: 13 #if 0 14 atom *find(); 15 std::vector<atom*> findAll(); 16 #endif 15 virtual atom *find(); 16 virtual std::vector<atom*> findAll(); 17 17 private: 18 18 int id; 19 19 }; 20 21 #endif //ATOMIDDESCRIPTOR_IMPL_HPP -
src/Legacy/oldmenu.cpp
r326a43b rcbf01e 9 9 #include "Legacy/oldmenu.hpp" 10 10 #include "analysis_correlation.hpp" 11 #include "World.hpp" 11 12 #include "atom.hpp" 12 13 #include "bond.hpp" … … 77 78 case 'a': // absolute coordinates of atom 78 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl; 79 first = new atom;80 first = World::get()->createAtom(); 80 81 first->x.AskPosition(mol->cell_size, false); 81 82 first->type = periode->AskElement(); // give type … … 84 85 85 86 case 'b': // relative coordinates of atom wrt to reference point 86 first = new atom;87 first = World::get()->createAtom(); 87 88 valid = true; 88 89 do { … … 100 101 101 102 case 'c': // relative coordinates of atom wrt to already placed atom 102 first = new atom;103 first = World::get()->createAtom(); 103 104 valid = true; 104 105 do { … … 116 117 117 118 case 'd': // two atoms, two angles and a distance 118 first = new atom;119 first = World::get()->createAtom(); 119 120 valid = true; 120 121 do { … … 216 217 217 218 case 'e': // least square distance position to a set of atoms 218 first = new atom;219 first = World::get()->createAtom(); 219 220 atoms = new (Vector*[128]); 220 221 valid = true; … … 238 239 mol->AddAtom(first); // add to molecule 239 240 } else { 240 delete first;241 World::get()->destroyAtom(first); 241 242 Log() << Verbose(0) << "Please enter at least two vectors!\n"; 242 243 } … … 736 737 Log() << Verbose(0) << "New element by atomic number Z: "; 737 738 cin >> Z; 738 first-> type = periode->FindElement(Z);739 first->setType(Z); 739 740 Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl; 740 741 } … … 781 782 x.AddVector(&y); // per factor one cell width further 782 783 for (int k=count;k--;) { // go through every atom of the original cell 783 first = new atom(); // create a new body784 first = World::get()->createAtom(); // create a new body 784 785 first->x.CopyVector(vectors[k]); // use coordinate of original atom 785 786 first->x.AddVector(&x); // translate the coordinates -
src/Makefile.am
r326a43b rcbf01e 8 8 ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp 9 9 10 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ActionRegistry.cpp 11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ActionRegistry.hpp 10 # only include Actions that are free of user interaction at this point 11 # the UIFactory et. al. wont be known for the libmolecuilder, so the user interaction cannot be done. 12 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ManipulateAtomsProcess.cpp Actions/ActionRegistry.cpp 13 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp 14 15 # All actions that need user interaction go here 16 MENUACTIONSSOURCE = Actions/ErrorAction.cpp Actions/small_actions.cpp 17 MENUACTIONSHEADER = Actions/ErrorAction.hpp Actions/small_actions.hpp 12 18 13 19 PATTERNSOURCE = Patterns/Observer.cpp … … 20 26 MENUHEADER = Menu/Menu.hpp Menu/TextMenu.hpp Menu/MenuItem.hpp Menu/SubMenuItem.hpp Menu/ActionMenuItem.hpp Menu/SeperatorItem.hpp Menu/DisplayMenuItem.hpp 21 27 22 UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp 23 UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp 24 28 UISOURCE = ${MENUACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp UIElements/TextStatusIndicator.cpp 29 UIHEADER = ${MENUACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp UIElements/TextStatusIndicator.hpp 25 30 26 31 FACTORYSOURCE = UIElements/UIFactory.cpp … … 36 41 QTUIMOC_TARGETS = QTMainWindow.moc.cpp QTMenu.moc.cpp QTDialog.moc.cpp QTMoleculesView.moc.cpp GLMoleculeView.moc.cpp QTStatusBar.moc.cpp 37 42 38 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp 39 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp 43 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp 44 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp 40 45 41 46 QTUISOURCE = ${QTUIMOC_TARGETS} UIElements/QT4/QTMainWindow.cpp UIElements/QT4/QTDialog.cpp UIElements/QT4/QTUIFactory.cpp Menu/QT4/QTMenu.cpp Views/QT4/QTMoleculesView.cpp Views/QT4/GLMoleculeView.cpp Views/QT4/QTStatusBar.cpp … … 44 49 QTUI_DEFS = 45 50 46 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${DESCRIPTORSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp 47 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 48 51 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${ACTIONSSOURCE} ${DESCRIPTORSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp WorldIterators.cpp 52 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${ACTIONSHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 49 53 50 54 BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB) -
src/UIElements/Dialog.cpp
r326a43b rcbf01e 142 142 *target = *tmp; 143 143 } 144 145 // Element Queries 146 Dialog::ElementQuery::ElementQuery(std::string title, element **_target) : 147 Query(title), 148 target(_target), 149 tmp(0) 150 {} 151 152 Dialog::ElementQuery::~ElementQuery(){} 153 154 void Dialog::ElementQuery::setResult(){ 155 *target=tmp; 156 } -
src/UIElements/Dialog.hpp
r326a43b rcbf01e 15 15 class molecule; 16 16 class Vector; 17 class element; 17 18 18 19 class Dialog … … 27 28 virtual void queryMolecule(const char*,molecule**,MoleculeListClass*)=0; 28 29 virtual void queryVector(const char*,Vector *,const double *const,bool)=0; 30 virtual void queryElement(const char*,element **)=0; 29 31 30 32 virtual bool display(); … … 48 50 public: 49 51 Query(std::string _title); 50 ~Query();52 virtual ~Query(); 51 53 virtual bool handle()=0; 52 54 virtual void setResult()=0; … … 61 63 public: 62 64 IntQuery(std::string title,int *_target); 63 ~IntQuery();65 virtual ~IntQuery(); 64 66 virtual bool handle()=0; 65 67 virtual void setResult(); … … 73 75 public: 74 76 DoubleQuery(std::string title,double *_target); 75 ~DoubleQuery();77 virtual ~DoubleQuery(); 76 78 virtual bool handle()=0; 77 79 virtual void setResult(); … … 85 87 public: 86 88 StringQuery(std::string title,std::string *_target); 87 ~StringQuery();89 virtual ~StringQuery(); 88 90 virtual bool handle()=0; 89 91 virtual void setResult(); … … 98 100 public: 99 101 MoleculeQuery(std::string title, molecule **_target, MoleculeListClass *_molecules); 100 ~MoleculeQuery();102 virtual ~MoleculeQuery(); 101 103 virtual bool handle()=0; 102 104 virtual void setResult(); … … 111 113 public: 112 114 VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check); 113 ~VectorQuery();115 virtual ~VectorQuery(); 114 116 virtual bool handle()=0; 115 117 virtual void setResult(); … … 122 124 }; 123 125 126 class ElementQuery : public Query { 127 public: 128 ElementQuery(std::string title, element**_target); 129 virtual ~ElementQuery(); 130 virtual bool handle()=0; 131 virtual void setResult(); 132 protected: 133 element *tmp; 134 private: 135 element **target; 136 }; 137 124 138 void registerQuery(Query* query); 125 139 -
src/UIElements/QT4/QTDialog.cpp
r326a43b rcbf01e 21 21 #include <Qt/qcombobox.h> 22 22 23 #include "World.hpp" 24 #include "periodentafel.hpp" 23 25 #include "atom.hpp" 26 #include "element.hpp" 24 27 #include "molecule.hpp" 25 28 … … 95 98 } 96 99 100 void QTDialog::queryElement(const char* title, element **target){ 101 registerQuery(new ElementQTQuery(title,target,inputLayout,this)); 102 } 103 97 104 /************************** Query Objects *******************************/ 98 105 … … 192 199 for(iter = molecules->ListOfMolecules.begin(); 193 200 iter != molecules->ListOfMolecules.end(); 194 iter++) {201 ++iter) { 195 202 stringstream sstr; 196 203 sstr << (*iter)->IndexNr << "\t" << (*iter)->getName(); … … 255 262 256 263 264 QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, element **_target, QBoxLayout *_parent, QTDialog *_dialog) : 265 Dialog::ElementQuery(_title,_target), 266 parent(_parent) 267 { 268 periodentafel *periode = World::get()->getPeriode(); 269 thisLayout = new QHBoxLayout(); 270 titleLabel = new QLabel(QString(getTitle().c_str())); 271 inputBox = new QComboBox(); 272 element* Elemental = 0; 273 for(Elemental = periode->start->next; 274 Elemental!=periode->end; 275 Elemental = Elemental->next) 276 { 277 stringstream sstr; 278 sstr << Elemental->Z << "\t" << Elemental->name; 279 inputBox->addItem(QString(sstr.str().c_str()),QVariant(Elemental->Z)); 280 } 281 parent->addLayout(thisLayout); 282 thisLayout->addWidget(titleLabel); 283 thisLayout->addWidget(inputBox); 284 285 pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox); 286 pipe->update(inputBox->currentIndex()); 287 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int))); 288 } 289 290 QTDialog::ElementQTQuery::~ElementQTQuery() 291 { 292 delete pipe; 293 } 294 295 bool QTDialog::ElementQTQuery::handle(){ 296 return true; 297 } 298 257 299 /*************************** Plumbing *******************************/ 258 300 … … 313 355 } 314 356 357 ElementQTQueryPipe::ElementQTQueryPipe(element **_content, QTDialog *_dialog, QComboBox *_theBox) : 358 content(_content), 359 dialog(_dialog), 360 theBox(_theBox) 361 {} 362 363 ElementQTQueryPipe::~ElementQTQueryPipe() 364 {} 365 366 void ElementQTQueryPipe::update(int newIndex) { 367 QVariant data = theBox->itemData(newIndex); 368 int idx = data.toInt(); 369 (*content) = World::get()->getPeriode()->FindElement(idx); 370 dialog->update(); 371 } 372 -
src/UIElements/QT4/QTDialog.hpp
r326a43b rcbf01e 26 26 class DoubleQTQueryPipe; 27 27 class MoleculeQTQueryPipe; 28 class ElementQTQueryPipe; 28 29 29 30 class QTDialog : public QDialog, public Dialog … … 39 40 virtual void queryMolecule(const char*,molecule**,MoleculeListClass*); 40 41 virtual void queryVector(const char*,Vector *,const double *const,bool); 42 virtual void queryElement(const char*,element **); 41 43 42 44 virtual bool display(); … … 48 50 public: 49 51 IntQTQuery(std::string _title, int *_target,QBoxLayout *_parent,QTDialog *_dialog); 50 ~IntQTQuery();52 virtual ~IntQTQuery(); 51 53 virtual bool handle(); 52 54 private: … … 62 64 public: 63 65 DoubleQTQuery(std::string title, double *_target,QBoxLayout *_parent,QTDialog *_dialog); 64 ~DoubleQTQuery();66 virtual ~DoubleQTQuery(); 65 67 virtual bool handle(); 66 68 private: … … 76 78 public: 77 79 StringQTQuery(std::string _title, std::string *_target, QBoxLayout *_parent,QTDialog *_dialog); 78 ~StringQTQuery();80 virtual ~StringQTQuery(); 79 81 virtual bool handle(); 80 82 private: … … 90 92 public: 91 93 MoleculeQTQuery(std::string _title, molecule **_target, MoleculeListClass *_molecules, QBoxLayout *_parent,QTDialog *_dialog); 92 ~MoleculeQTQuery();94 virtual ~MoleculeQTQuery(); 93 95 virtual bool handle(); 94 96 private: … … 104 106 public: 105 107 VectorQTQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check,QBoxLayout *,QTDialog *); 106 ~VectorQTQuery();108 virtual ~VectorQTQuery(); 107 109 virtual bool handle(); 108 110 private: … … 118 120 }; 119 121 122 class ElementQTQuery : public Dialog::ElementQuery { 123 public: 124 ElementQTQuery(std::string _title, element **_target, QBoxLayout *_parent, QTDialog *_dialog); 125 virtual ~ElementQTQuery(); 126 virtual bool handle(); 127 private: 128 QBoxLayout *parent; 129 QBoxLayout *thisLayout; 130 QLabel *titleLabel; 131 QComboBox *inputBox; 132 133 ElementQTQueryPipe *pipe; 134 }; 135 120 136 private: 121 137 QBoxLayout *mainLayout; … … 133 149 public: 134 150 StringQTQueryPipe(std::string *_content, QTDialog *_dialog); 135 ~StringQTQueryPipe();151 virtual ~StringQTQueryPipe(); 136 152 137 153 public slots: … … 148 164 public: 149 165 IntQTQueryPipe(int *_content, QTDialog *_dialog); 150 ~IntQTQueryPipe();166 virtual ~IntQTQueryPipe(); 151 167 152 168 public slots: … … 163 179 public: 164 180 DoubleQTQueryPipe(double *_content, QTDialog *_dialog); 165 ~DoubleQTQueryPipe();181 virtual ~DoubleQTQueryPipe(); 166 182 167 183 public slots: … … 178 194 public: 179 195 MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox, MoleculeListClass *_molecules); 180 ~MoleculeQTQueryPipe();196 virtual ~MoleculeQTQueryPipe(); 181 197 182 198 public slots: … … 190 206 191 207 }; 208 209 class ElementQTQueryPipe : public QWidget { 210 Q_OBJECT 211 public: 212 ElementQTQueryPipe(element **_content, QTDialog *_dialog, QComboBox *_theBox); 213 virtual ~ElementQTQueryPipe(); 214 215 public slots: 216 void update(int); 217 218 private: 219 element **content; 220 QTDialog *dialog; 221 QComboBox *theBox; 222 }; 192 223 #endif /* QTDIALOG_HPP_ */ -
src/UIElements/TextDialog.cpp
r326a43b rcbf01e 10 10 #include "UIElements/TextDialog.hpp" 11 11 12 #include "World.hpp" 13 #include "periodentafel.hpp" 12 14 #include "atom.hpp" 13 15 #include "molecule.hpp" … … 45 47 void TextDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) { 46 48 registerQuery(new VectorTextQuery(title,target,cellSize,check)); 49 } 50 51 void TextDialog::queryElement(const char* title, element **target){ 52 registerQuery(new ElementTextQuery(title,target)); 47 53 } 48 54 … … 113 119 114 120 bool TextDialog::VectorTextQuery::handle() { 121 Log() << Verbose(0) << getTitle(); 115 122 tmp->AskPosition(cellSize,check); 116 123 return true; 117 124 } 125 126 127 TextDialog::ElementTextQuery::ElementTextQuery(std::string title, element **target) : 128 Dialog::ElementQuery(title,target) 129 {} 130 131 TextDialog::ElementTextQuery::~ElementTextQuery() 132 {} 133 134 bool TextDialog::ElementTextQuery::handle() { 135 int Z; 136 Log() << Verbose(0) << getTitle(); 137 cin >> Z; 138 tmp = World::get()->getPeriode()->FindElement(Z); 139 return tmp; 140 } -
src/UIElements/TextDialog.hpp
r326a43b rcbf01e 24 24 virtual void queryMolecule(const char*,molecule**,MoleculeListClass*); 25 25 virtual void queryVector(const char*,Vector *,const double * const,bool); 26 virtual void queryElement(const char*,element **); 26 27 27 28 protected: … … 30 31 public: 31 32 IntTextQuery(std::string title, int *_target); 32 ~IntTextQuery();33 virtual ~IntTextQuery(); 33 34 virtual bool handle(); 34 35 }; … … 37 38 public: 38 39 DoubleTextQuery(std::string title, double *_target); 39 ~DoubleTextQuery();40 virtual ~DoubleTextQuery(); 40 41 virtual bool handle(); 41 42 }; … … 44 45 public: 45 46 StringTextQuery(std::string title, std::string *_target); 46 ~StringTextQuery();47 virtual ~StringTextQuery(); 47 48 virtual bool handle(); 48 49 }; … … 51 52 public: 52 53 MoleculeTextQuery(std::string title, molecule **_target, MoleculeListClass *_molecules); 53 ~MoleculeTextQuery();54 virtual ~MoleculeTextQuery(); 54 55 virtual bool handle(); 55 56 }; … … 58 59 public: 59 60 VectorTextQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check); 60 ~VectorTextQuery(); 61 virtual ~VectorTextQuery(); 62 virtual bool handle(); 63 }; 64 65 class ElementTextQuery : public Dialog::ElementQuery { 66 public: 67 ElementTextQuery(std::string title, element **_target); 68 virtual ~ElementTextQuery(); 61 69 virtual bool handle(); 62 70 }; -
src/UIElements/TextWindow.cpp
r326a43b rcbf01e 36 36 #include "Menu/DisplayMenuItem.hpp" 37 37 #include "Menu/SubMenuItem.hpp" 38 #include "UIElements/TextStatusIndicator.hpp" 38 39 #include "Actions/MethodAction.hpp" 39 40 #include "Actions/ErrorAction.hpp" … … 97 98 98 99 editMoleculesMenu->addDefault(returnItem); 100 101 // Add status indicators etc... 102 103 statusIndicator = new TextStatusIndicator(); 99 104 } 100 105 … … 105 110 delete returnFromEditMoleculeAction; 106 111 delete moleculeView; 112 delete statusIndicator; 107 113 delete main_menu; 108 114 } -
src/UIElements/TextWindow.hpp
r326a43b rcbf01e 15 15 class oldmenu; 16 16 class StringView; 17 class TextStatusIndicator; 17 18 18 19 class TextWindow : public MainWindow … … 31 32 // all views that are contained in the main Menu 32 33 StringView *moleculeView; 34 TextStatusIndicator *statusIndicator; 33 35 34 36 // This class still contains a lot of scattered functionality -
src/World.cpp
r326a43b rcbf01e 12 12 #include "periodentafel.hpp" 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Actions/ManipulateAtomsProcess.hpp" 14 16 15 17 using namespace std; … … 28 30 } 29 31 32 vector<atom*> World::getAllAtoms(){ 33 return getAllAtoms(AllAtoms()); 34 } 35 30 36 int World::numAtoms(){ 31 37 return atoms.size(); … … 36 42 } 37 43 44 /******************** Methods to change World state *********************/ 45 38 46 molecule* World::createMolecule(){ 39 47 OBSERVE; … … 41 49 mol = new molecule(periode); 42 50 molecules_deprecated->insert(mol); 43 molecules.insert(mol); 51 assert(!molecules.count(currMoleculeId)); 52 // store the molecule by ID 53 molecules[currMoleculeId++] = mol; 44 54 mol->signOn(this); 45 55 return mol; 46 56 } 47 57 58 59 atom *World::createAtom(){ 60 OBSERVE; 61 atom *res = NewAtom(); 62 assert(!atoms.count(currAtomId)); 63 res->setId(currAtomId++); 64 res->setWorld(this); 65 // store the atom by ID 66 atoms[res->getId()] = res; 67 return res; 68 } 69 70 int World::registerAtom(atom *atom){ 71 OBSERVE; 72 assert(!atoms.count(currAtomId)); 73 atom->setId(currAtomId++); 74 atom->setWorld(this); 75 atoms[atom->getId()] = atom; 76 return atom->getId(); 77 } 78 79 void World::destroyAtom(atom* atom){ 80 OBSERVE; 81 int id = atom->getId(); 82 destroyAtom(id); 83 } 84 85 void World::destroyAtom(int id) { 86 OBSERVE; 87 atom *atom = atoms[id]; 88 assert(atom); 89 DeleteAtom(atom); 90 atoms.erase(id); 91 } 92 93 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 94 return new ManipulateAtomsProcess(op, descr,name,true); 95 } 96 97 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){ 98 return manipulateAtoms(op,name,AllAtoms()); 99 } 100 101 /********************* Internal Change methods for double Callback and Observer mechanism ********/ 102 103 void World::doManipulate(ManipulateAtomsProcess *proc){ 104 proc->signOn(this); 105 { 106 OBSERVE; 107 proc->doManipulate(this); 108 } 109 proc->signOff(this); 110 } 111 112 /******************************* Iterators ********************************/ 113 114 /* 115 * Actual Implementation of the iterators can be found in WorldIterators.cpp 116 */ 117 118 World::AtomIterator World::getAtomIter(AtomDescriptor descr){ 119 return AtomIterator(descr,this); 120 } 121 122 World::AtomSet::iterator World::atomEnd(){ 123 return atoms.end(); 124 } 48 125 49 126 /******************************* Singleton Stuff **************************/ … … 53 130 boost::mutex World::worldLock; 54 131 55 56 57 132 World::World() : 58 dummyId(0), 133 currAtomId(0), 134 currMoleculeId(0), 59 135 periode(new periodentafel), 60 molecules_deprecated(new MoleculeListClass) 136 molecules_deprecated(new MoleculeListClass), 137 atoms(), 138 molecules() 61 139 { 62 140 molecules_deprecated->signOn(this); … … 65 143 World::~World() 66 144 { 145 delete molecules_deprecated; 67 146 delete periode; 147 AtomSet::iterator iter; 148 for(iter=atoms.begin();iter!=atoms.end();++iter){ 149 DeleteAtom((*iter).second); 150 } 151 atoms.clear(); 68 152 } 69 153 … … 78 162 79 163 void World::destroy(){ 80 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise81 theWorld->destroyLegacy();82 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.83 84 164 // boost supports RAII-Style locking, so we don't need to unlock 85 165 boost::mutex::scoped_lock guard(worldLock); … … 89 169 90 170 World* World::reset(){ 91 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise92 theWorld->destroyLegacy();93 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.94 95 171 World* oldWorld = 0; 96 172 { … … 119 195 return molecules_deprecated; 120 196 } 121 122 // some legacy stuff to let the World know about items created outside123 void World::registerAtom(atom *theAtom){124 OBSERVE;125 atoms[dummyId++] = theAtom;126 }127 128 void World::destroyLegacy(){129 //delete molecules_deprecated;130 }131 132 void World::unregisterAtom(atom *theAtom){133 OBSERVE;134 atoms.erase(theAtom->getId());135 } -
src/World.hpp
r326a43b rcbf01e 9 9 #define WORLD_HPP_ 10 10 11 #include < boost/thread.hpp>11 #include <string> 12 12 #include <map> 13 13 #include <vector> 14 14 #include <set> 15 #include <boost/thread.hpp> 16 #include <boost/shared_ptr.hpp> 17 15 18 16 19 #include "Patterns/Observer.hpp" … … 24 27 class AtomDescriptor; 25 28 class AtomDescriptor_impl; 29 class ManipulateAtomsProcess; 30 template<typename T> 31 class AtomsCalculation; 26 32 27 33 class World : public Observable 28 34 { 35 // necessary for coupling with descriptors 29 36 friend class AtomDescriptor_impl; 37 friend class AtomDescriptor; 38 39 // Actions, calculations etc associated with the World 40 friend class ManipulateAtomsProcess; 41 template<typename> friend class AtomsCalculation; 42 43 typedef std::map<int,atom*> AtomSet; 44 typedef std::map<int,molecule*> MoleculeSet; 30 45 public: 31 46 32 47 /***** getter and setter *****/ 33 48 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object 49 /** 50 * returns the periodentafel for the world. 51 */ 34 52 periodentafel *&getPeriode(); 53 54 /** 55 * returns the first atom that matches a given descriptor. 56 * Do not rely on ordering for descriptors that match more than one atom. 57 */ 35 58 atom* getAtom(AtomDescriptor descriptor); 59 60 /** 61 * returns a vector containing all atoms that match a given descriptor 62 */ 36 63 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor); 64 std::vector<atom*> getAllAtoms(); 65 66 /** 67 * returns a calculation that calls a given function on all atoms matching a descriptor. 68 * the calculation is not called at this point and can be used as an action, i.e. be stored in 69 * menus, be kept around for later use etc. 70 */ 71 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor); 72 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string); 73 74 /** 75 * get the number of atoms in the World 76 */ 37 77 int numAtoms(); 78 79 /** 80 * get the number of molecules in the World 81 */ 38 82 int numMolecules(); 39 83 40 84 /***** Methods to work with the World *****/ 85 86 /** 87 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique 88 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly. 89 */ 41 90 molecule *createMolecule(); 91 92 /** 93 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores 94 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends. 95 */ 96 atom *createAtom(); 97 98 /** 99 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests. 100 * Do not re-register Atoms already known to the world since this will cause double-frees. 101 */ 102 int registerAtom(atom*); 103 104 /** 105 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 106 * atom directly since this will leave the pointer inside the world. 107 */ 108 void destroyAtom(atom*); 109 110 /** 111 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 112 * atom directly since this will leave the pointer inside the world. 113 */ 114 void destroyAtom(int); 115 116 /** 117 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not 118 * called at this time, so it can be passed around, stored inside menuItems etc. 119 */ 120 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor); 121 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string); 122 123 protected: 124 /**** Iterators to use internal data structures */ 125 class AtomIterator { 126 public: 127 AtomIterator(); 128 AtomIterator(AtomDescriptor, World*); 129 AtomIterator(const AtomIterator&); 130 AtomIterator& operator=(const AtomIterator&); 131 AtomIterator& operator++(); // prefix 132 AtomIterator operator++(int); // postfix with dummy parameter 133 bool operator==(const AtomIterator&); 134 bool operator==(const AtomSet::iterator&); 135 bool operator!=(const AtomIterator&); 136 bool operator!=(const AtomSet::iterator&); 137 atom* operator*(); 138 139 int getCount(); 140 protected: 141 void advanceState(); 142 World* world; 143 AtomSet::iterator state; 144 boost::shared_ptr<AtomDescriptor_impl> descr; 145 int index; 146 }; 147 148 /** 149 * returns an iterator over all Atoms matching a given descriptor. 150 * used for internal purposes, like AtomProcesses and AtomCalculations. 151 */ 152 AtomIterator getAtomIter(AtomDescriptor descr); 153 154 /** 155 * returns an iterator to the end of the AtomSet. Due to overloading this iterator 156 * can be compared to iterators produced by getAtomIter (see the mis-matching types). 157 * Thus it can be used to detect when such an iterator is at the end of the list. 158 * used for internal purposes, like AtomProcesses and AtomCalculations. 159 */ 160 AtomSet::iterator atomEnd(); 161 162 /******* Internal manipulation routines for double callback and Observer mechanism ******/ 163 void doManipulate(ManipulateAtomsProcess *); 164 42 165 private: 43 166 periodentafel *periode; 44 std::map<int,atom*> atoms; 45 std::set<molecule*> molecules; 167 AtomSet atoms; 168 int currAtomId; //!< stores the next available Id for atoms 169 MoleculeSet molecules; 170 int currMoleculeId; 46 171 47 172 48 173 /***** singleton Stuff *****/ 49 174 public: 175 176 /** 177 * get the currently active instance of the World. 178 */ 50 179 static World* get(); 180 181 /** 182 * destroy the currently active instance of the World. 183 */ 51 184 static void destroy(); 185 186 /** 187 * destroy the currently active instance of the World and immidiately 188 * create a new one. Use this to reset while somebody is still Observing 189 * the world and should reset the observed instance. All observers will be 190 * sent the subjectKille() message from the old world. 191 */ 52 192 static World* reset(); 53 193 54 194 private: 195 /** 196 * private constructor to ensure creation of the world using 197 * the singleton pattern. 198 */ 55 199 World(); 200 201 /** 202 * private destructor to ensure destruction of the world using the 203 * singleton pattern. 204 */ 56 205 virtual ~World(); 57 206 … … 68 217 MoleculeListClass *&getMolecules(); 69 218 70 // functions used for the WorldContent template mechanism71 void registerAtom(atom *theAtom);72 void unregisterAtom(atom *theAtom);73 219 private: 74 // this function cleans up anything that cannot be cleaned while the lock is active75 // at a later point all these cleanups have to be moved to the World Class so the deadlock and76 // race condition can both be avoided.77 void destroyLegacy();78 79 220 MoleculeListClass *molecules_deprecated; 80 81 // this is needed to assign unique IDs to atoms... so far82 // IDs are not assigned upon Atom creation, so we cannot query the ID83 // during construction. By using the dummy ID we can make sure all atoms84 // are actually stored in the map and don't overwrite each other.85 int dummyId;86 221 }; 87 222 -
src/atom.cpp
r326a43b rcbf01e 20 20 /** Constructor of class atom. 21 21 */ 22 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)23 { 24 World::get()->registerAtom(this); 22 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr) 24 { 25 25 node = &x; // TesselPoint::x can only be referenced from here 26 26 }; … … 28 28 /** Constructor of class atom. 29 29 */ 30 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr) 31 { 32 World::get()->registerAtom(this); 30 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 33 { 33 34 type = pointer->type; // copy element of atom 34 35 x.CopyVector(&pointer->x); // copy coordination … … 38 39 }; 39 40 41 atom *atom::clone(){ 42 atom *res = new atom(); 43 res->previous=0; 44 res->next=0; 45 res->father = this; 46 res->sort = &nr; 47 res->type = type; 48 res->x.CopyVector(&this->x); 49 res->v.CopyVector(&this->v); 50 res->FixedIon = FixedIon; 51 res->node = &x; 52 World::get()->registerAtom(res); 53 return res; 54 } 55 40 56 41 57 /** Destructor of class atom. … … 43 59 atom::~atom() 44 60 { 45 World::get()->unregisterAtom(this);46 61 unlink(this); 47 62 }; … … 267 282 }; 268 283 284 World *atom::getWorld(){ 285 return world; 286 } 287 288 void atom::setWorld(World* _world){ 289 world = _world; 290 } 291 292 void atom::setId(int _id) { 293 id=_id; 294 } 295 296 int atom::getId() { 297 return id; 298 } 299 300 atom* NewAtom(){ 301 return new atom(); 302 } 303 304 void DeleteAtom(atom* atom){ 305 delete atom; 306 } -
src/atom.hpp
r326a43b rcbf01e 32 32 33 33 class Vector; 34 class World; 34 35 35 36 /********************************************** declarations *******************************/ … … 39 40 */ 40 41 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 42 friend atom* NewAtom(); 43 friend void DeleteAtom(atom*); 41 44 public: 42 45 atom *previous; //!< previous atom in molecule list … … 45 48 int *sort; //!< sort criteria 46 49 47 atom(); 48 atom(class atom *pointer); 49 virtual ~atom(); 50 virtual atom *clone(); 50 51 51 52 bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const; … … 67 68 bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const; 68 69 70 // getter and setter 71 72 /** 73 * returns the World that contains this atom. 74 * Use this if you need to get the world without locking 75 * the singleton for example. 76 * 77 */ 78 World *getWorld(); 79 void setWorld(World*); 80 81 virtual int getId(); 82 virtual void setId(int); 83 protected: 84 /** 85 * Protected constructor to ensure construction of atoms through the world. 86 * see World::createAtom() 87 */ 88 atom(); 89 90 /** 91 * Protected copy-constructor to ensure construction of atoms by cloning. 92 * see atom::clone() 93 */ 94 atom(class atom *pointer); 95 96 /** 97 * Protected destructor to ensure destruction of atoms through the world. 98 * see World::destroyAtom() 99 */ 100 virtual ~atom(); 69 101 private: 102 World* world; 103 int id; 70 104 }; 71 105 106 /** 107 * internal method used by the world. Do not use if you don't know what you are doing. 108 * You might get burned... 109 * Use World::createAtom() instead. 110 */ 111 atom* NewAtom(); 112 113 /** 114 * internal method used by the world. Do not use if you don't know what you are doing. 115 * You might get burned... 116 * Use World::destroyAtom() instead. 117 */ 118 void DeleteAtom(atom*); 119 120 72 121 #endif /* ATOM_HPP_ */ -
src/atom_atominfo.cpp
r326a43b rcbf01e 6 6 */ 7 7 8 #include "periodentafel.hpp" 9 #include "World.hpp" 8 10 #include "atom_atominfo.hpp" 9 11 … … 18 20 }; 19 21 22 element *AtomInfo::getType(){ 23 return type; 24 } 25 26 void AtomInfo::setType(element* _type) { 27 type = _type; 28 } 29 30 void AtomInfo::setType(int Z) { 31 element *elem = World::get()->getPeriode()->FindElement(Z); 32 setType(elem); 33 } -
src/atom_atominfo.hpp
r326a43b rcbf01e 37 37 ~AtomInfo(); 38 38 39 element *getType(); 40 void setType(element *); 41 void setType(int); 42 39 43 private: 40 44 }; -
src/atom_particleinfo.cpp
r326a43b rcbf01e 13 13 ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {}; 14 14 15 ParticleInfo::ParticleInfo(ParticleInfo *pointer) : 16 Name(pointer->Name), 17 nr(pointer->nr) 18 {} 19 20 15 21 /** Destructor of ParticleInfo. 16 22 */ … … 19 25 Free(&Name); 20 26 }; 21 22 int ParticleInfo::getId() {23 return nr;24 }25 27 26 28 ostream & operator << (ostream &ost, const ParticleInfo &a) -
src/atom_particleinfo.hpp
r326a43b rcbf01e 31 31 32 32 ParticleInfo(); 33 ParticleInfo(ParticleInfo*); 33 34 ~ParticleInfo(); 34 35 35 36 ostream & operator << (ostream &ost) const; 36 37 virtual int getId();38 37 39 38 private: -
src/boundary.cpp
r326a43b rcbf01e 887 887 Walker = Walker->next; 888 888 // copy atom ... 889 CopyAtoms[Walker->nr] = new atom(Walker);889 CopyAtoms[Walker->nr] = Walker->clone(); 890 890 891 891 // create atomic random translation vector ... -
src/builder.cpp
r326a43b rcbf01e 1482 1482 SaveFlag = true; 1483 1483 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; 1484 first = new atom;1484 first = World::get()->createAtom(); 1485 1485 first->type = periode->FindElement(atoi(argv[argptr])); 1486 1486 if (first->type != NULL) … … 1642 1642 // first->x.Zero(); 1643 1643 // filler->AddAtom(first); 1644 first = new atom();1644 first = World::get()->createAtom(); 1645 1645 first->type = periode->FindElement(1); 1646 1646 first->x.Init(0.441, -0.143, 0.); 1647 1647 filler->AddAtom(first); 1648 second = new atom();1648 second = World::get()->createAtom(); 1649 1649 second->type = periode->FindElement(1); 1650 1650 second->x.Init(-0.464, 1.137, 0.0); 1651 1651 filler->AddAtom(second); 1652 third = new atom();1652 third = World::get()->createAtom(); 1653 1653 third->type = periode->FindElement(8); 1654 1654 third->x.Init(-0.464, 0.177, 0.); … … 2098 2098 x.AddVector(&y); // per factor one cell width further 2099 2099 for (int k=count;k--;) { // go through every atom of the original cell 2100 first = new atom(); // create a new body2100 first = World::get()->createAtom(); // create a new body 2101 2101 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2102 2102 first->x.AddVector(&x); // translate the coordinates -
src/config.cpp
r326a43b rcbf01e 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 732 733 sprintf(keyword,"%s_%i",name, j+1); 733 734 if (repetition == 0) { 734 neues = new atom();735 neues = World::get()->createAtom(); 735 736 AtomList[i][j] = neues; 736 737 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 811 812 sprintf(keyword,"%s_%i",name, j+1); 812 813 if (repetition == 0) { 813 neues = new atom();814 neues = World::get()->createAtom(); 814 815 AtomList[i][j] = neues; 815 816 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 1287 1288 } 1288 1289 istringstream input2(zeile); 1289 atom *neues = new atom();1290 atom *neues = World::get()->createAtom(); 1290 1291 input2 >> neues->x.x[0]; // x 1291 1292 input2 >> neues->x.x[1]; // y -
src/lists.hpp
r326a43b rcbf01e 9 9 #define LISTS_HPP_ 10 10 11 class atom; 12 11 13 /******************************** Some templates for list management ***********************************/ 12 14 … … 18 20 { 19 21 X *vorher = end->previous; 20 if (vorher != NULL)22 if (vorher != 0) 21 23 vorher->next = walker; 22 24 end->previous = walker; … … 31 33 template <typename X> void unlink(X *walker) 32 34 { 33 if (walker->next != NULL)35 if (walker->next != 0) 34 36 walker->next->previous = walker->previous; 35 if (walker->previous != NULL)37 if (walker->previous != 0) 36 38 walker->previous->next = walker->next; 37 walker->next = NULL;38 walker->previous= NULL;39 walker->next = 0; 40 walker->previous= 0; 39 41 }; 40 42 … … 46 48 template <typename X> bool add(X *pointer, X *end) 47 49 { 48 if (end != NULL) {50 if (end != 0) { 49 51 link(pointer, end); 50 52 } else { 51 pointer->previous = NULL;52 pointer->next = NULL;53 pointer->previous = 0; 54 pointer->next = 0; 53 55 } 54 56 return true; … … 59 61 * \param *start begin of list 60 62 * \param *end end of list 61 * \return X - if found, NULL- if not found63 * \return X - if found, 0 - if not found 62 64 */ 63 65 template <typename X, typename Y> X * find(Y *suche, X *start, X *end) … … 68 70 if (*walker->sort == *suche) return (walker); 69 71 } 70 return NULL;72 return 0; 71 73 }; 72 74 … … 77 79 template <typename X> void removewithoutcheck(X *walker) 78 80 { 79 if (walker != NULL) {81 if (walker != 0) { 80 82 unlink(walker); 81 83 delete(walker); 82 walker = NULL;84 walker = 0; 83 85 } 84 86 }; 87 88 /** Removes an item from the list without check. 89 * specialized for atoms, because these have to be removed from the world as well 90 * the implementation for this declaration is in lists.cpp 91 * \param *walker item to be removed 92 * \return true - removing succeeded, false - given item not found in list 93 */ 94 template <> void removewithoutcheck<atom>(atom *walker); 85 95 86 96 /** Removes an item from the list, checks if exists. … … 99 109 }*/ 100 110 // atom found, now unlink 101 if (walker != NULL)111 if (walker != 0) 102 112 removewithoutcheck(walker); 103 113 else … … 114 124 { 115 125 X *pointer = start->next; 116 X *walker = NULL;126 X *walker = 0; 117 127 while (pointer != end) { // go through list 118 128 walker = pointer; // mark current … … 131 141 { 132 142 X *Binder = me; 133 while(Binder->previous != NULL)143 while(Binder->previous != 0) 134 144 Binder = Binder->previous; 135 145 return Binder; … … 143 153 { 144 154 X *Binder = me; 145 while(Binder->next != NULL)155 while(Binder->next != 0) 146 156 Binder = Binder->next; 147 157 return Binder; -
src/molecule.cpp
r326a43b rcbf01e 8 8 #include <boost/bind.hpp> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 30 31 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 31 32 */ 32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start( new atom), end(new atom),33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()), 33 34 first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0), 34 35 BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.), … … 60 61 delete(first); 61 62 delete(last); 62 delete(end);63 delete(start);63 end->getWorld()->destroyAtom(end); 64 start->getWorld()->destroyAtom(start); 64 65 }; 65 66 … … 135 136 OBSERVE; 136 137 if (pointer != NULL) { 137 atom *walker = new atom(pointer);138 atom *walker = pointer->clone(); 138 139 walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name"); 139 140 strcpy (walker->Name, pointer->Name); … … 242 243 switch(TopBond->BondDegree) { 243 244 case 1: 244 FirstOtherAtom = new atom(); // new atom245 FirstOtherAtom = World::get()->createAtom(); // new atom 245 246 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 246 247 FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity … … 299 300 300 301 // create the two Hydrogens ... 301 FirstOtherAtom = new atom();302 SecondOtherAtom = new atom();302 FirstOtherAtom = World::get()->createAtom(); 303 SecondOtherAtom = World::get()->createAtom(); 303 304 FirstOtherAtom->type = elemente->FindElement(1); 304 305 SecondOtherAtom->type = elemente->FindElement(1); … … 354 355 case 3: 355 356 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid) 356 FirstOtherAtom = new atom();357 SecondOtherAtom = new atom();358 ThirdOtherAtom = new atom();357 FirstOtherAtom = World::get()->createAtom(); 358 SecondOtherAtom = World::get()->createAtom(); 359 ThirdOtherAtom = World::get()->createAtom(); 359 360 FirstOtherAtom->type = elemente->FindElement(1); 360 361 SecondOtherAtom->type = elemente->FindElement(1); … … 475 476 MDSteps++; 476 477 for(i=0;i<NumberOfAtoms;i++){ 477 Walker = new atom;478 Walker = World::get()->createAtom(); 478 479 getline(xyzfile,line,'\n'); 479 480 istringstream *item = new istringstream(line); -
src/moleculelist.cpp
r326a43b rcbf01e 342 342 Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl; 343 343 if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) { 344 CopyAtoms[Walker->nr] = new atom(Walker);344 CopyAtoms[Walker->nr] = Walker->clone(); 345 345 mol->AddAtom(CopyAtoms[Walker->nr]); 346 346 nr++; -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r326a43b rcbf01e 17 17 #include "AnalysisCorrelationToPointUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 56 57 // construct molecule (tetraeder of hydrogens) 57 58 TestMolecule = new molecule(tafel); 58 Walker = new atom();59 Walker = World::get()->createAtom(); 59 60 Walker->type = hydrogen; 60 61 Walker->node->Init(1., 0., 1. ); 61 62 TestMolecule->AddAtom(Walker); 62 Walker = new atom();63 Walker = World::get()->createAtom(); 63 64 Walker->type = hydrogen; 64 65 Walker->node->Init(0., 1., 1. ); 65 66 TestMolecule->AddAtom(Walker); 66 Walker = new atom();67 Walker = World::get()->createAtom(); 67 68 Walker->type = hydrogen; 68 69 Walker->node->Init(1., 1., 0. ); 69 70 TestMolecule->AddAtom(Walker); 70 Walker = new atom();71 Walker = World::get()->createAtom(); 71 72 Walker->type = hydrogen; 72 73 Walker->node->Init(0., 0., 0. ); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r326a43b rcbf01e 17 17 #include "AnalysisCorrelationToSurfaceUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 61 62 // construct molecule (tetraeder of hydrogens) base 62 63 TestMolecule = new molecule(tafel); 63 Walker = new atom();64 Walker = World::get()->createAtom(); 64 65 Walker->type = hydrogen; 65 66 Walker->node->Init(1., 0., 1. ); 66 67 TestMolecule->AddAtom(Walker); 67 Walker = new atom();68 Walker = World::get()->createAtom(); 68 69 Walker->type = hydrogen; 69 70 Walker->node->Init(0., 1., 1. ); 70 71 TestMolecule->AddAtom(Walker); 71 Walker = new atom();72 Walker = World::get()->createAtom(); 72 73 Walker->type = hydrogen; 73 74 Walker->node->Init(1., 1., 0. ); 74 75 TestMolecule->AddAtom(Walker); 75 Walker = new atom();76 Walker = World::get()->createAtom(); 76 77 Walker->type = hydrogen; 77 78 Walker->node->Init(0., 0., 0. ); … … 94 95 95 96 // add outer atoms 96 Walker = new atom();97 Walker = World::get()->createAtom(); 97 98 Walker->type = carbon; 98 99 Walker->node->Init(4., 0., 4. ); 99 100 TestMolecule->AddAtom(Walker); 100 Walker = new atom();101 Walker = World::get()->createAtom(); 101 102 Walker->type = carbon; 102 103 Walker->node->Init(0., 4., 4. ); 103 104 TestMolecule->AddAtom(Walker); 104 Walker = new atom();105 Walker = World::get()->createAtom(); 105 106 Walker->type = carbon; 106 107 Walker->node->Init(4., 4., 0. ); 107 108 TestMolecule->AddAtom(Walker); 108 109 // add inner atoms 109 Walker = new atom();110 Walker = World::get()->createAtom(); 110 111 Walker->type = carbon; 111 112 Walker->node->Init(0.5, 0.5, 0.5 ); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r326a43b rcbf01e 17 17 #include "AnalysisPairCorrelationUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 55 56 // construct molecule (tetraeder of hydrogens) 56 57 TestMolecule = new molecule(tafel); 57 Walker = new atom();58 Walker = World::get()->createAtom(); 58 59 Walker->type = hydrogen; 59 60 Walker->node->Init(1., 0., 1. ); 60 61 TestMolecule->AddAtom(Walker); 61 Walker = new atom();62 Walker = World::get()->createAtom(); 62 63 Walker->type = hydrogen; 63 64 Walker->node->Init(0., 1., 1. ); 64 65 TestMolecule->AddAtom(Walker); 65 Walker = new atom();66 Walker = World::get()->createAtom(); 66 67 Walker->type = hydrogen; 67 68 Walker->node->Init(1., 1., 0. ); 68 69 TestMolecule->AddAtom(Walker); 69 Walker = new atom();70 Walker = World::get()->createAtom(); 70 71 Walker->type = hydrogen; 71 72 Walker->node->Init(0., 0., 0. ); -
src/unittests/DescriptorUnittest.cpp
r326a43b rcbf01e 22 22 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 23 23 24 // some stubs25 class AtomStub : public atom {26 public:27 AtomStub(int _id) :28 atom(),29 id(_id)30 {}31 32 virtual int getId(){33 return id;34 }35 36 private:37 int id;38 };39 40 41 24 // set up and tear down 42 25 void DescriptorUnittest::setUp(){ 43 26 World::get(); 44 27 for(int i=0;i<ATOM_COUNT;++i){ 45 atoms[i]= new AtomStub(i); 28 atoms[i]= World::get()->createAtom(); 29 atomIds[i] = atoms[i]->getId(); 46 30 } 47 31 } 48 32 void DescriptorUnittest::tearDown(){ 49 33 World::destroy(); 50 for(int i=0;i<ATOM_COUNT;++i){51 delete atoms[i];52 }53 34 } 54 35 55 36 // some helper functions 56 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 57 for(int i=min;i<max;++i){ 58 if(!excluded.count(i)){ 37 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){ 38 for(int i=0;i<ATOM_COUNT;++i){ 39 int id = ids[i]; 40 if(!excluded.count(id)){ 59 41 std::vector<atom*>::iterator iter; 60 42 bool res=false; 61 43 for(iter=atoms.begin();iter!=atoms.end();++iter){ 62 res |= (*iter)->getId() == i ;44 res |= (*iter)->getId() == id; 63 45 } 64 46 if(!res) { 65 cout << "Atom " << i << " missing in returned list" << endl;47 cout << "Atom " << id << " missing in returned list" << endl; 66 48 return false; 67 49 } … … 86 68 void DescriptorUnittest::AtomBaseSetsTest(){ 87 69 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 88 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms, 0,ATOM_COUNT));70 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds)); 89 71 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 90 72 … … 95 77 // test Atoms from boundaries and middle of the set 96 78 atom* testAtom; 97 testAtom = World::get()->getAtom(AtomById(0)); 98 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId()); 99 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2)); 100 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId()); 101 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1)); 102 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId()); 79 testAtom = World::get()->getAtom(AtomById(atomIds[0])); 80 CPPUNIT_ASSERT(testAtom); 81 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId()); 82 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2])); 83 CPPUNIT_ASSERT(testAtom); 84 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId()); 85 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1])); 86 CPPUNIT_ASSERT(testAtom); 87 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); 103 88 89 // find some ID that has not been created 90 int outsideId =-1; 91 bool res = false; 92 while(!res) { 93 ++outsideId; 94 res = true; 95 for(int i = 0; i < ATOM_COUNT; ++i){ 96 res &= atomIds[i]!=outsideId; 97 } 98 } 104 99 // test from outside of set 105 testAtom = World::get()->getAtom(AtomById( ATOM_COUNT));100 testAtom = World::get()->getAtom(AtomById(outsideId)); 106 101 CPPUNIT_ASSERT(!testAtom); 107 102 } … … 110 105 { 111 106 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 112 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));107 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 113 108 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 114 109 } … … 116 111 { 117 112 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 118 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));113 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 119 114 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 120 115 } … … 137 132 { 138 133 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 139 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT));134 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds)); 140 135 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 141 136 } … … 143 138 // exclude and include some atoms 144 139 { 145 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById( ATOM_COUNT/2)));140 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 146 141 std::set<int> excluded; 147 excluded.insert( ATOM_COUNT/2);148 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, 0,ATOM_COUNT,excluded));142 excluded.insert(atomIds[ATOM_COUNT/2]); 143 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded)); 149 144 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 150 145 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 152 147 153 148 { 154 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById( ATOM_COUNT/2)));149 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2]))); 155 150 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 156 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());151 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId()); 157 152 } 158 153 } -
src/unittests/DescriptorUnittest.hpp
r326a43b rcbf01e 33 33 private: 34 34 atom *atoms [ATOM_COUNT]; 35 int atomIds [ATOM_COUNT]; 35 36 }; 36 37 -
src/unittests/Makefile.am
r326a43b rcbf01e 31 31 CacheableTest \ 32 32 DescriptorUnittest \ 33 ${MENUTESTS} 34 33 manipulateAtomsTest \ 34 atomsCalculationTest \ 35 ${MENUTESTS} 36 37 35 38 check_PROGRAMS = $(TESTS) 36 39 noinst_PROGRAMS = $(TESTS) … … 109 112 110 113 DescriptorUnittest_SOURCES = DescriptorUnittest.cpp DescriptorUnittest.hpp 111 DescriptorUnittest_LDADD = ${ALLLIBS} 114 DescriptorUnittest_LDADD = ${ALLLIBS} 115 116 manipulateAtomsTest_SOURCES = manipulateAtomsTest.cpp manipulateAtomsTest.hpp 117 manipulateAtomsTest_LDADD = ${ALLLIBS} 118 119 atomsCalculationTest_SOURCES = atomsCalculationTest.cpp atomsCalculationTest.hpp 120 atomsCalculationTest_LDADD = ${ALLLIBS} 112 121 113 122 #AUTOMAKE_OPTIONS = parallel-tests -
src/unittests/analysisbondsunittest.cpp
r326a43b rcbf01e 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "analysis_bonds.hpp" 19 20 #include "analysisbondsunittest.hpp" … … 62 63 // construct molecule (tetraeder of hydrogens) 63 64 TestMolecule = new molecule(tafel); 64 Walker = new atom();65 Walker = World::get()->createAtom(); 65 66 Walker->type = hydrogen; 66 67 Walker->node->Init(1.5, 0., 1.5 ); 67 68 TestMolecule->AddAtom(Walker); 68 Walker = new atom();69 Walker = World::get()->createAtom(); 69 70 Walker->type = hydrogen; 70 71 Walker->node->Init(0., 1.5, 1.5 ); 71 72 TestMolecule->AddAtom(Walker); 72 Walker = new atom();73 Walker = World::get()->createAtom(); 73 74 Walker->type = hydrogen; 74 75 Walker->node->Init(1.5, 1.5, 0. ); 75 76 TestMolecule->AddAtom(Walker); 76 Walker = new atom();77 Walker = World::get()->createAtom(); 77 78 Walker->type = hydrogen; 78 79 Walker->node->Init(0., 0., 0. ); 79 80 TestMolecule->AddAtom(Walker); 80 Walker = new atom();81 Walker = World::get()->createAtom(); 81 82 Walker->type = carbon; 82 83 Walker->node->Init(0.5, 0.5, 0.5 ); -
src/unittests/bondgraphunittest.cpp
r326a43b rcbf01e 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 57 58 // construct molecule (tetraeder of hydrogens) 58 59 TestMolecule = new molecule(tafel); 59 Walker = new atom();60 Walker = World::get()->createAtom(); 60 61 Walker->type = hydrogen; 61 62 Walker->node->Init(1., 0., 1. ); 62 63 TestMolecule->AddAtom(Walker); 63 Walker = new atom();64 Walker = World::get()->createAtom(); 64 65 Walker->type = hydrogen; 65 66 Walker->node->Init(0., 1., 1. ); 66 67 TestMolecule->AddAtom(Walker); 67 Walker = new atom();68 Walker = World::get()->createAtom(); 68 69 Walker->type = hydrogen; 69 70 Walker->node->Init(1., 1., 0. ); 70 71 TestMolecule->AddAtom(Walker); 71 Walker = new atom();72 Walker = World::get()->createAtom(); 72 73 Walker->type = hydrogen; 73 74 Walker->node->Init(0., 0., 0. ); -
src/unittests/listofbondsunittest.cpp
r326a43b rcbf01e 16 16 #include "listofbondsunittest.hpp" 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 50 51 // construct molecule (tetraeder of hydrogens) 51 52 TestMolecule = new molecule(tafel); 52 Walker = new atom();53 Walker = World::get()->createAtom(); 53 54 Walker->type = hydrogen; 54 55 Walker->node->Init(1., 0., 1. ); 55 56 TestMolecule->AddAtom(Walker); 56 Walker = new atom();57 Walker = World::get()->createAtom(); 57 58 Walker->type = hydrogen; 58 59 Walker->node->Init(0., 1., 1. ); 59 60 TestMolecule->AddAtom(Walker); 60 Walker = new atom();61 Walker = World::get()->createAtom(); 61 62 Walker->type = hydrogen; 62 63 Walker->node->Init(1., 1., 0. ); 63 64 TestMolecule->AddAtom(Walker); 64 Walker = new atom();65 Walker = World::get()->createAtom(); 65 66 Walker->type = hydrogen; 66 67 Walker->node->Init(0., 0., 0. ); … … 242 243 243 244 // remove atom2 244 delete(atom2);245 World::get()->destroyAtom(atom2); 245 246 246 247 // check bond if removed from other atom
Note:
See TracChangeset
for help on using the changeset viewer.