forked from schrodinger/maeparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaeBlock.cpp
96 lines (83 loc) · 2.62 KB
/
MaeBlock.cpp
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
#include "MaeBlock.hpp"
#include "MaeParser.hpp"
namespace schrodinger
{
namespace mae
{
Block::~Block()
{
// TODO: check with valgrind whether some destructor is needed
}
std::shared_ptr<IndexedBlock> Block::getIndexedBlock(const std::string& name)
{
return m_indexed_block_map->getIndexedBlock(name);
}
bool IndexedBlockMap::hasIndexedBlock(const std::string& name)
{
return m_indexed_block.find(name) != m_indexed_block.end();
}
std::shared_ptr<IndexedBlock>
IndexedBlockMap::getIndexedBlock(const std::string& name)
{
std::map<std::string, std::shared_ptr<IndexedBlock>>::const_iterator itb =
m_indexed_block.find(name);
if (itb != m_indexed_block.end()) {
return itb->second;
} else {
throw std::out_of_range("Indexed block not found: " + name);
}
}
bool BufferedIndexedBlockMap::hasIndexedBlock(const std::string& name)
{
if (m_indexed_buffer.find(name) != m_indexed_buffer.end()) {
return true;
} else if (m_indexed_block.find(name) != m_indexed_block.end()) {
return true;
} else {
return false;
}
}
std::shared_ptr<IndexedBlock>
BufferedIndexedBlockMap::getIndexedBlock(const std::string& name)
{
std::map<std::string, std::shared_ptr<IndexedBlock>>::const_iterator itb =
m_indexed_block.find(name);
if (itb != m_indexed_block.end()) {
return itb->second;
}
auto itbb = m_indexed_buffer.find(name);
if (itbb == m_indexed_buffer.end()) {
throw std::out_of_range("Indexed block not found: " + name);
} else {
std::shared_ptr<IndexedBlock> ib(itbb->second->getIndexedBlock());
m_indexed_buffer.erase(itbb);
return ib;
}
}
template <>
EXPORT_MAEPARSER void IndexedBlock::setProperty<bool>(
const std::string& name, std::shared_ptr<IndexedProperty<bool>> value)
{
set_indexed_property<IndexedProperty<bool>>(m_bmap, name, value);
}
template <>
EXPORT_MAEPARSER void IndexedBlock::setProperty<double>(
const std::string& name, std::shared_ptr<IndexedProperty<double>> value)
{
set_indexed_property<IndexedProperty<double>>(m_rmap, name, value);
}
template <>
EXPORT_MAEPARSER void IndexedBlock::setProperty<int>(const std::string& name,
std::shared_ptr<IndexedProperty<int>> value)
{
set_indexed_property<IndexedProperty<int>>(m_imap, name, value);
}
template <>
EXPORT_MAEPARSER void IndexedBlock::setProperty<std::string>(
const std::string& name,
std::shared_ptr<IndexedProperty<std::string>> value)
{
set_indexed_property<IndexedProperty<std::string>>(m_smap, name, value);
}
} // namespace mae
} // namespace schrodinger