AtilaCalculatorSoftware  2.3.4
C++ Interface for Atila fem resources files
utilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Project: AtilaCalculatorSoftware
4  File: utils.h
5 
6  Copyright (c) 2020
7  All rights reserved.
8 
9 =========================================================================*/
10 #ifndef ATILACALCULATORSOFTWARE_UTILITIES_H
11 #define ATILACALCULATORSOFTWARE_UTILITIES_H
12 
13 #include <cstring>
14 #include <iostream>
15 #include <stdexcept>
16 #include <string>
17 #include <zlib.h>
18 
19 // --------------------------------------------------------------------------------------
20 // DEFINES
21 // --------------------------------------------------------------------------------------
22 
26 #define GZ_BUFFER_SIZE 2000
27 
28 // --------------------------------------------------------------------------------------
29 // MACROS
30 // --------------------------------------------------------------------------------------
31 
35 #define __HERE__ std::string(__FILE__) + ":" + std::to_string(__LINE__)
36 
40 #define __THROW__(x) throw std::runtime_error(std::string("[" + __HERE__ + "] " + x));
41 
42 #ifdef DEBUG
43 #define __DEBUG__(x) std::cout << "[" << __HERE__ << "]" << x << std::endl;
44 #define __DEBUG_FIELDS__(x) \
45  __DEBUG__(std::string("Fields: ") + std::string(fields[0]) + std::string(", ") + \
46  std::string(fields[1]) + std::string(", ") + std::string(fields[2]) + \
47  std::string(", ") + std::string(fields[3]) + std::string(", ") + \
48  std::string(fields[4]) + std::string(", ") + std::string(fields[5]) + \
49  std::string(", ") + std::string(fields[6]) + std::string(", ") + \
50  std::string(fields[7]) + std::string(", ") + std::string(fields[8]) + \
51  std::string(", ") + std::string(fields[9]));
52 #define __PDEBUG__(x, y) std::cout << "[" << __HERE__ << "]" << x << ": " << y << std::endl;
53 #else
54 #define __DEBUG__(x) \
55  { }
56 #define __DEBUG_FIELDS__(x) \
57  { }
58 #define __PDEBUG__(x, y) \
59  { }
60 #endif
61 
62 
67 #define GZ_READ_CHECK(FILE, BUFFER, LEN) \
68  if (static_cast<int>((LEN) * sizeof(*(BUFFER))) != \
69  gzread((FILE), (BUFFER), (LEN) * sizeof(*(BUFFER)))) \
70  return (-1);
71 
72 // --------------------------------------------------------------------------------------
73 // STRUCTURES AND TYPES
74 // --------------------------------------------------------------------------------------
75 
76 typedef char dataFields[10][40];
77 
78 // --------------------------------------------------------------------------------------
79 // INLINE METHODS
80 // --------------------------------------------------------------------------------------
81 
87 inline std::string const& to_string(std::string const& s) { return s; }
88 
89 // --------------------------------------------------------------------------------------
90 // TEMPLATES
91 // --------------------------------------------------------------------------------------
92 
99 template<typename... TArgs> std::string concat(TArgs const&... args) {
100  std::string str;
101 
103  using std::to_string;
104 
105  int unpack[] { 0, (str += to_string(args), 0)... };
106  static_cast<void>(unpack);
107 
108  return str;
109 }
110 
111 
112 // --------------------------------------------------------------------------------------
113 // METHODS
114 // --------------------------------------------------------------------------------------
115 
123 unsigned int getFields(gzFile file, char* buffer, dataFields fields);
124 
125 #endif // ATILACALCULATORSOFTWARE_UTILITIES_H
std::string const & to_string(std::string const &s)
Allows to use to_string method for elements that are already string.
Definition: utilities.h:87
std::string concat(TArgs const &... args)
Cast and concatenate parameter pack elements as string.
Definition: utilities.h:99
unsigned int getFields(gzFile file, char *buffer, dataFields fields)
Read fields from the given resource file.
Definition: utilities.cpp:12
char dataFields[10][40]
Definition: utilities.h:76