1 |
/* -*- c++ -*- */ |
2 |
#ifndef UTILS_SYSTEMUTILITIES_HPP |
3 |
#define UTILS_SYSTEMUTILITIES_HPP |
4 |
|
5 |
#include "config.h" |
6 |
#include <string> |
7 |
#include <algorithm> |
8 |
|
9 |
#include "utils/Report.hpp" |
10 |
|
11 |
|
12 |
namespace OpenMD { |
13 |
/// Changes to the actual directory of the file name |
14 |
bool changeDirectory(const std::string &fileName); |
15 |
|
16 |
/// Test if the file is accessible |
17 |
bool isAccessible(const std::string &fileName); |
18 |
|
19 |
void splitFileName(const std::string &filename, std::string &dirname, |
20 |
std::string &basename, std::string &extension); |
21 |
|
22 |
unsigned int getFileSize(const std::string &filename); |
23 |
|
24 |
/// Does an abort, calling the adequate abort system function |
25 |
void openMDAbort(); |
26 |
|
27 |
/// Sets function to be called when calling OpenMDAbort() |
28 |
void setopenMDAbort(void (*abortFunction)()); |
29 |
|
30 |
/// Does an exit, calling the adequate exit system function |
31 |
void openMDExit(); |
32 |
|
33 |
/// Sets function to be called when calling OpenMDxit() |
34 |
void setOpenMDExit(void (*exitFunction)()); |
35 |
|
36 |
/// Initiates the serialization block, e.g., used by Report |
37 |
void openMDStartSerial(bool exludeMaster); |
38 |
|
39 |
/// Sets function to be called to start serialization |
40 |
void setOpenMDStartSerial(void (*startSerialFunction)(bool)); |
41 |
|
42 |
/// Finializes the serialization block |
43 |
void openMDEndSerial(bool exludeMaster); |
44 |
|
45 |
/// Sets function to be called to end serialization |
46 |
void setopenMDEndSerial(void (*endSerialFunction)(bool)); |
47 |
|
48 |
/// Return an resolved absolute path |
49 |
std::string getCanonicalPath(const std::string &path); |
50 |
|
51 |
/// Swap function to change endianess |
52 |
template<typename T> inline |
53 |
void swapBytes(T &t) { |
54 |
if (sizeof(T) % 2 != 0) |
55 |
Report::report << Report::error << "Cannot swap types of uneven size." << |
56 |
Report::endr; |
57 |
char *res = reinterpret_cast<char *> (&t); |
58 |
std::reverse(res, res + sizeof(T)); |
59 |
} |
60 |
|
61 |
/// Shift left of four Real's |
62 |
inline void shift(RealType &a, RealType &b, RealType &c, const RealType d) { |
63 |
a = b; b = c; c = d; |
64 |
} |
65 |
|
66 |
/// bool constant if the machine is littleEndian or not |
67 |
extern const bool ISLITTLEENDIAN; |
68 |
|
69 |
/// Clears a container explicitly |
70 |
template<typename T> inline |
71 |
void realclear(T &t) {T tmp; t.swap(tmp);} |
72 |
|
73 |
/// Shrinks the capacity of a container explicitly |
74 |
template<typename T> inline |
75 |
void shrink(T &t) {T tmp(t); t.swap(tmp);} |
76 |
|
77 |
namespace SystemUtilities { |
78 |
bool unlink(const std::string &path); |
79 |
void rename(const std::string &src, const std::string &dst); |
80 |
}; |
81 |
} |
82 |
#endif /* SYSTEMUTILITIES_H */ |