Vlasiator
ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
item_storage.h
Go to the documentation of this file.
1
/*
2
* This file is part of Vlasiator.
3
* Copyright 2010-2016 Finnish Meteorological Institute
4
*
5
* For details of usage, see the COPYING file and read the "Rules of the Road"
6
* at http://www.physics.helsinki.fi/vlasiator/
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
12
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
18
* You should have received a copy of the GNU General Public License along
19
* with this program; if not, write to the Free Software Foundation, Inc.,
20
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
*/
22
23
#ifndef ITEM_STORAGE_H
24
#define ITEM_STORAGE_H
25
26
#include <map>
27
#include <string>
28
29
#include "
definitions.h
"
30
35
template
<
typename
ITEM>
36
class
ItemStorage
{
37
public
:
38
bool
get
(
const
std::string& name,ITEM& item)
const
;
39
bool
store
(
const
std::string& name,ITEM item);
40
41
private
:
42
std::map<std::string,ITEM>
warehouse
;
43
};
44
49
template
<
typename
ITEM>
inline
50
bool
ItemStorage<ITEM>::get
(
const
std::string& name,ITEM& item)
const
{
51
typename
std::map<std::string,ITEM>::const_iterator it =
warehouse
.find(name);
52
if
(it ==
warehouse
.end())
return
false
;
53
item = it->second;
54
return
true
;
55
}
56
62
template
<
typename
ITEM>
inline
63
bool
ItemStorage<ITEM>::store
(
const
std::string& name,ITEM item) {
64
// The insert returns a pair<iterator,bool>, where the boolean value is 'true'
65
// if the function was inserted to the map. Skip the pair creation and just return the boolean.
66
return
warehouse
.insert(make_pair(name,item)).second;
67
}
68
69
#endif
ItemStorage
Definition
item_storage.h:36
ItemStorage::get
bool get(const std::string &name, ITEM &item) const
Definition
item_storage.h:50
ItemStorage::store
bool store(const std::string &name, ITEM item)
Definition
item_storage.h:63
ItemStorage::warehouse
std::map< std::string, ITEM > warehouse
Definition
item_storage.h:42
definitions.h
item_storage.h
Generated on
for Vlasiator by
1.16.1