-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmisc.hh
More file actions
58 lines (44 loc) · 1.3 KB
/
misc.hh
File metadata and controls
58 lines (44 loc) · 1.3 KB
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
#ifndef MISC_BINACC_HH
#define MISC_BINACC_HH
#include <vector>
#include <string>
#include <algorithm>
#include "memimage.hh"
typedef dm::memimage<double> image_dbl;
typedef dm::memimage<float> image_float;
typedef dm::memimage<long> image_long;
typedef dm::memimage<short> image_short;
typedef dm::memimage<bool> image_bool;
typedef std::vector<unsigned> vec_unsigned;
typedef std::vector<double> vec_dbl;
// split a string into parts separated by delim
inline std::vector<std::string> split_string(const std::string& in, const char delim)
{
std::vector<std::string> out;
std::string::const_iterator i = in.begin();
while(true)
{
std::string::const_iterator e = std::find(i, in.end(), delim);
if(e == in.end())
break;
out.push_back( std::string(i, e) );
i = e+1;
}
return out;
}
// A simple RIAA pointer class to ensure pointers are deleted at end
// of scope. This should be replaced by something standard for C++11.
template<class T> class delete_ptr
{
public:
delete_ptr(T* p=0) : _ptr(p) {}
~delete_ptr() { delete _ptr; }
T& operator*() const { return *_ptr; }
T* operator->() const { return _ptr; }
void operator=(T* p) { _ptr = p; } // note this doesn't delete!
T* ptr() const { return _ptr; }
T** pptr() { return &_ptr; }
private:
T* _ptr;
};
#endif