File: atomTypes.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (140 lines) | stat: -rw-r--r-- 2,710 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: atomTypes.C,v 1.13 2003/08/26 09:17:53 oliver Exp $
//

#include <BALL/MOLMEC/PARAMETER/atomTypes.h>
#include <BALL/MOLMEC/PARAMETER/forceFieldParameters.h>

using namespace std;

namespace BALL 
{


	AtomTypes::AtomTypes() 
		: ParameterSection(),
			type_map_(),
			names_()
	{
	}


	AtomTypes::AtomTypes(const AtomTypes& atom_types) 
		: ParameterSection(atom_types),
			type_map_(atom_types.type_map_),
			names_(atom_types.names_)
	{
	}


	AtomTypes::~AtomTypes() 
	{
		clear();

		valid_ = false;
	}

	void AtomTypes::clear() 
	{
		names_.clear();
		type_map_.clear();

		ParameterSection::clear();
	}


	AtomTypes& AtomTypes::operator = (const AtomTypes& atom_types) 
	{
		clear();

		ParameterSection::operator = (atom_types);
		names_ = atom_types.names_;
		type_map_ = atom_types.type_map_;

		return *this;
	}


	bool AtomTypes::extractSection
		(Parameters& parameters, const String& section_name) 
	{
		valid_ = true;
		// extract the basis information
		if (!ParameterSection::extractSection(parameters, section_name))
		{
			Log.error() << "AtomTypes::extractSection: didn't find section for " << section_name << endl;
			return false;
		}

		// clear type map and name array
		type_map_.clear();
		names_.clear();

		// insert the wildcard name for type 0 (ANY_TYPE)
		names_.push_back(BALL_ATOM_UNKNOWN_NAME);
		type_map_[BALL_ATOM_WILDCARD_NAME] = (Atom::Type)0;
		type_map_[BALL_ATOM_UNKNOWN_NAME] = (Atom::Type)0;

		// iterate over all entries and insert them into
		// the hash map and the names_ array
		for (Size i = 0; i < getNumberOfKeys(); i++)
		{
			// insert the name into the hash map
			// and the names array
			type_map_[getKey(i)] = (Atom::Type)(names_.size());
			names_.push_back(getKey(i));
		}
		
		return true;
	}


	bool AtomTypes::hasType(const String& name) const 
	{
		return type_map_.has(name);
	}


	Atom::Type AtomTypes::getType(const String& name) const 
	{
		// try to find the name in the hash map
		StringHashMap<Atom::Type>::ConstIterator it = type_map_.find(name);
		if (it != type_map_.end())
		{
			return it->second;
		} 
		else 
		{
			return Atom::UNKNOWN_TYPE;
		}
	}


	String AtomTypes::getTypeName(Atom::Type type) const 
	{
		static const String empty_string;
		if ((type < 0) || (type >= (Index)names_.size()))
		{
			return empty_string;
		}
		
		return names_[type];
	}


	Size AtomTypes::getNumberOfTypes() const 
	{
		return (Size)names_.size();
	}


	bool AtomTypes::operator == (const AtomTypes& atom_types) const 
	{
		return (ParameterSection::operator == (atom_types)
			&& (type_map_ == atom_types.type_map_)
			&& (names_ == atom_types.names_));
	}

} // namespace BALL