source: src/Geometry/GeometryRegistry.cpp@ 033646

Candidate_v1.7.1 stable
Last change on this file since 033646 was c8cb0d, checked in by Frederik Heber <frederik.heber@…>, 6 weeks ago

Streamlines channel creation in Observables.

  • CodePatterns is now version 1.3.4.
  • we no longer need to add the channels manually in the cstor of a class that derives from Observable. Instead, we just need to pass the maximum number of channels (as they are typically enumerated anyway) and they are generated and added.
  • added mutex protection when inserting.
  • adjusted class Relay to forward similar convenience cstors.
  • adjusted all call sites in molecuilder.
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2017 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * GeometryRegistry.cpp
25 *
26 * Created on: Mar 25, 2017
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include "GeometryRegistry.hpp"
38
39#include <algorithm>
40#include <boost/assign.hpp>
41
42#include "CodePatterns/Singleton_impl.hpp"
43#include "CodePatterns/Registry_impl.hpp"
44#include "CodePatterns/Observer/Channels.hpp"
45
46using namespace boost::assign;
47
48GeometryRegistry::GeometryRegistry() :
49 Observable::Observable("GeometryRegistry", NotificationType_MAX)
50{
51 _lastchanged = NULL;
52
53 fillRegistry();
54}
55
56GeometryRegistry::~GeometryRegistry()
57{
58 cleanup();
59}
60
61void GeometryRegistry::fillRegistry()
62{
63 const GeometryObject zeroVector(zeroVec, std::string("zeroVector"));
64 addGeometry(zeroVector);
65 const GeometryObject unitVectorX(unitVec[0], std::string("unitVectorX"));
66 addGeometry(unitVectorX);
67 const GeometryObject unitVectorY(unitVec[1], std::string("unitVectorY"));
68 addGeometry(unitVectorY);
69 const GeometryObject unitVectorZ(unitVec[2], std::string("unitVectorZ"));
70 addGeometry(unitVectorZ);
71}
72
73void GeometryRegistry::addGeometry(const GeometryObject &_v)
74{
75 OBSERVE;
76 GeometryObject *instance = new GeometryObject(_v);
77 registerInstance(instance);
78 _lastchanged = instance;
79 NOTIFY(GeometryInserted);
80}
81
82void GeometryRegistry::removeGeometry(const std::string &name)
83{
84 GeometryObject *instance = getByName(name);
85 {
86 OBSERVE;
87 _lastchanged = instance;
88 NOTIFY(GeometryRemoved);
89 }
90 unregisterInstance(instance);
91 delete(instance);
92}
93
94static std::vector<std::string> setProtectedNames()
95{
96 std::vector<std::string> names;
97 names += std::string("zeroVector"),
98 std::string("unitVectorX"),
99 std::string("unitVectorY"),
100 std::string("unitVectorZ");
101 return names;
102}
103
104bool GeometryRegistry::isProtectedName(const std::string &_name) const
105{
106 static std::vector<std::string> protected_names = setProtectedNames();
107
108 if (std::count(protected_names.begin(), protected_names.end(), _name) != 0)
109 return true;
110 return false;
111}
112
113CONSTRUCT_SINGLETON(GeometryRegistry)
114CONSTRUCT_REGISTRY(GeometryObject)
Note: See TracBrowser for help on using the repository browser.