IMP logo
IMP Reference Guide  2.22.0
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 byte order.
4  *
5  * Copyright 2007-2022 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_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 fwrite from C, but at the end there is a flag
33  * saying if data should be written 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 //! Returns 1 if machine is big endian else 0
42 bool IMPALGEBRAEXPORT get_is_big_endian();
43 
44 //! Returns 1 if machine is little endian else 0
45 bool IMPALGEBRAEXPORT get_is_little_endian();
46 /** @} */
47 
48 IMPALGEBRA_END_NAMESPACE
49 
50 #endif /* IMPALGEBRA_ENDIAN_H */
bool get_is_big_endian()
Returns 1 if machine is big endian else 0.
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.
Various general useful macros for IMP.