IMP  2.2.1
The Integrative Modeling Platform
endian.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/endian.h
3  * \brief functions to deal with endian of EM images
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6 */
7 
8 #ifndef IMPALGEBRA_ENDIAN_H
9 #define IMPALGEBRA_ENDIAN_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include <IMP/base/base_macros.h>
13 #include <iostream>
14 #include <fstream>
15 
16 IMPALGEBRA_BEGIN_NAMESPACE
17 
18 /** \name Endian
19  \imp provides a variety of functionality to manage byte order in
20  input and output data.
21  @{
22 */
23 
24 //! Reads from file in normal or reverse order
25 /** If the reverse parameter is true, the data will be read in reverse order.
26  */
27 void IMPALGEBRAEXPORT reversed_read(void* dest, size_t size, size_t nitems,
28  std::ifstream& f, bool reverse);
29 
30 //! Writes to a file in normal or reversed order
31 /**
32  * This function is the same as fread from C, but at the end there is a flag
33  * saying if data should be read in reverse order or not.
34  *
35  * If the reverse parameter is true, the data will be written in reverse order.
36  */
37 void IMPALGEBRAEXPORT reversed_write(const void* src, size_t size,
38  size_t nitems, std::ofstream& f,
39  bool reverse = false);
40 
41 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
42 void IMPALGEBRAEXPORT byte_swap(unsigned char* b, int n);
43 #endif
44 
45 //! Conversion between little and big endian. Goes both ways
46 template <class T>
47 inline void get_swapped_endian(T& x) {
48  byte_swap((unsigned char*)&x, sizeof(T));
49 }
50 
51 //! Returns 1 if machine is big endian else 0
52 bool IMPALGEBRAEXPORT get_is_big_endian();
53 
54 //! Returns 1 if machine is little endian else 0
55 bool IMPALGEBRAEXPORT get_is_little_endian();
56 /** @} */
57 
58 IMPALGEBRA_END_NAMESPACE
59 
60 #endif /* IMPALGEBRA_ENDIAN_H */
bool get_is_big_endian()
Returns 1 if machine is big endian else 0.
Various general useful macros for IMP.
bool get_is_little_endian()
Returns 1 if machine is little endian else 0.
void reversed_read(void *dest, size_t size, size_t nitems, std::ifstream &f, bool reverse)
Reads from file in normal or reverse order.
void reversed_write(const void *src, size_t size, size_t nitems, std::ofstream &f, bool reverse=false)
Writes to a file in normal or reversed order.
void get_swapped_endian(T &x)
Conversion between little and big endian. Goes both ways.
Definition: endian.h:47