1 |
chuckv |
522 |
/* |
2 |
|
|
* GeometryFactory.cpp |
3 |
|
|
* OOPSE-2.0 |
4 |
|
|
* |
5 |
|
|
* Created by Charles F. Vardeman II on 5/3/05. |
6 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
7 |
|
|
* |
8 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
9 |
|
|
* non-exclusive, royalty free, license to use, modify and |
10 |
|
|
* redistribute this software in source and binary code form, provided |
11 |
|
|
* that the following conditions are met: |
12 |
|
|
* |
13 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
14 |
|
|
* publication of scientific results based in part on use of the |
15 |
|
|
* program. An acceptable form of acknowledgement is citation of |
16 |
|
|
* the article in which the program was described (Matthew |
17 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
18 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
19 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
20 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
21 |
|
|
* |
22 |
|
|
* 2. Redistributions of source code must retain the above copyright |
23 |
|
|
* notice, this list of conditions and the following disclaimer. |
24 |
|
|
* |
25 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
26 |
|
|
* notice, this list of conditions and the following disclaimer in the |
27 |
|
|
* documentation and/or other materials provided with the |
28 |
|
|
* distribution. |
29 |
|
|
* |
30 |
|
|
* This software is provided "AS IS," without a warranty of any |
31 |
|
|
* kind. All express or implied conditions, representations and |
32 |
|
|
* warranties, including any implied warranty of merchantability, |
33 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
34 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
35 |
|
|
* be liable for any damages suffered by licensee as a result of |
36 |
|
|
* using, modifying or distributing the software or its |
37 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
38 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
39 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
40 |
|
|
* damages, however caused and regardless of the theory of liability, |
41 |
|
|
* arising out of the use of or inability to use software, even if the |
42 |
|
|
* University of Notre Dame has been advised of the possibility of |
43 |
|
|
* such damages. |
44 |
|
|
*/ |
45 |
|
|
|
46 |
|
|
#include "nanoRodBuilder/GeometryFactory.hpp" |
47 |
|
|
#include "nanoRodBuilder/GeometryCreator.hpp" |
48 |
|
|
|
49 |
|
|
namespace oopse{ |
50 |
|
|
|
51 |
|
|
//initialize instance of GeometryFactory |
52 |
|
|
GeometryFactory* GeometryFactory::instance_ = NULL; |
53 |
|
|
GeometryFactory::~GeometryFactory() { |
54 |
|
|
CreatorMapType::iterator i; |
55 |
|
|
for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) { |
56 |
|
|
delete i->second; |
57 |
|
|
} |
58 |
|
|
creatorMap_.clear(); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
bool GeometryFactory::registerGeometry(GeometryCreator* creator) { |
63 |
|
|
return creatorMap_.insert( |
64 |
|
|
CreatorMapType::value_type(creator->getIdent(), creator)).second; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
bool GeometryFactory::unregisterGeometry(const std::string& id) { |
68 |
|
|
return creatorMap_.erase(id) == 1; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
Geometry* GeometryFactory::createGeometry(const std::string& id) { |
72 |
|
|
CreatorMapType::iterator i = creatorMap_.find(id); |
73 |
|
|
if (i != creatorMap_.end()) { |
74 |
|
|
//invoke functor to create object |
75 |
|
|
return (i->second)->create(); |
76 |
|
|
} else { |
77 |
|
|
return NULL; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
std::vector<std::string> GeometryFactory::getIdents() { |
82 |
|
|
IdentVectorType idents; |
83 |
|
|
CreatorMapType::iterator i; |
84 |
|
|
|
85 |
|
|
for (i = creatorMap_.begin(); i != creatorMap_.end(); ++i) { |
86 |
|
|
idents.push_back(i->first); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
return idents; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
std::ostream& operator <<(std::ostream& o, GeometryFactory& factory) { |
93 |
|
|
GeometryFactory::IdentVectorType idents; |
94 |
|
|
GeometryFactory::IdentVectorIterator i; |
95 |
|
|
|
96 |
|
|
idents = factory.getIdents(); |
97 |
|
|
|
98 |
|
|
o << "Avaliable type identifiers in this factory: " << std::endl; |
99 |
|
|
for (i = idents.begin(); i != idents.end(); ++i) { |
100 |
|
|
o << *i << std::endl; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
return o; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
} |