-
Notifications
You must be signed in to change notification settings - Fork 33
/
hash_stream.h
38 lines (34 loc) · 992 Bytes
/
hash_stream.h
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
// Copyright (C) University of Oxford 2010
#ifndef _HASH_STREAM_DEF_H
#define _HASH_STREAM_DEF_H
template <typename K, typename V>
inline
std::istream & operator >> (std::istream &is, CHashMap<K, V> &table) {
K key ;
// V value ;
char c ;
std::string s ;
if (!getline(is, s)) THROW("hash map file ended unexpectedly");
while (is && !(s.empty())) {
std::istringstream iss(s) ;
iss >> key;
iss >> c;
ASSERT( c == ':' , "Hash map does not match key : value format (column missing); key was: " << key) ;
iss >> table[key] ;
//TRACE("Read " << key << " : " << table[key]);
getline(is, s);
}
return is;
}
template <typename K, typename V>
inline
std::ostream & operator << (std::ostream &os, CHashMap<K, V> &table) {
typename CHashMap<K, V>::iterator it = table.begin() ;
while (it != table.end()) {
os << it.first() << "\t:\t" << it.second() << std::endl ;
++ it;
}
os << std::endl ;
return os ;
}
#endif