1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. 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 | * ShapeFactory.cpp
|
---|
25 | *
|
---|
26 | * Created on: Sep 5, 2012
|
---|
27 | * Author: ankele
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 | #include "CodePatterns/Log.hpp"
|
---|
37 |
|
---|
38 | #include "ShapeFactory.hpp"
|
---|
39 |
|
---|
40 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
41 |
|
---|
42 | const char *ShapeFactory::shapeNames[ShapeFactory::SHAPETYPES_MAX] = {"sphere", "cube", "cylinder"};
|
---|
43 |
|
---|
44 | ShapeFactory::ShapeFactory()
|
---|
45 | {
|
---|
46 | // Create map (type -> name).
|
---|
47 | for (int i=0; i<SHAPETYPES_MAX; i++)
|
---|
48 | shapeNameMap.insert(std::pair<ShapeType, std::string>((ShapeType)i, shapeNames[i]));
|
---|
49 |
|
---|
50 | // Create inverse map.
|
---|
51 | for (int i=0; i<SHAPETYPES_MAX; i++)
|
---|
52 | nameShapeMap.insert(std::pair<std::string, ShapeType>(shapeNames[i], (ShapeType)i));
|
---|
53 | }
|
---|
54 |
|
---|
55 | ShapeFactory::ShapeType ShapeFactory::getShapeByName(const std::string& name)
|
---|
56 | {
|
---|
57 | NameShapeMap::iterator iter = nameShapeMap.find(name);
|
---|
58 | ASSERT(iter != nameShapeMap.end(),
|
---|
59 | "ShapeFactory::getShapeByName() - unknown name: "+name+".");
|
---|
60 | return iter->second;
|
---|
61 | }
|
---|
62 |
|
---|
63 | std::string ShapeFactory::getShapeName(ShapeType type)
|
---|
64 | {
|
---|
65 | ShapeNameMap::iterator iter = shapeNameMap.find(type);
|
---|
66 | ASSERT(iter != shapeNameMap.end(),
|
---|
67 | "ShapeFactory::getShapeName() - unknown type: "+toString(type)+".");
|
---|
68 | return iter->second;
|
---|
69 | }
|
---|
70 |
|
---|
71 | ShapeFactory::~ShapeFactory()
|
---|
72 | {
|
---|
73 | }
|
---|
74 |
|
---|
75 | CONSTRUCT_SINGLETON(ShapeFactory)
|
---|