retdec
type_conversions.h
Go to the documentation of this file.
1 
7 #ifndef FILEINFO_FILE_INFORMATION_FILE_INFORMATION_TYPES_TYPE_CONVERSIONS_H
8 #define FILEINFO_FILE_INFORMATION_FILE_INFORMATION_TYPES_TYPE_CONVERSIONS_H
9 
10 #include <limits>
11 #include <vector>
12 
14 
15 namespace retdec {
16 namespace fileinfo {
17 
18 std::string getBinaryRepresentation(unsigned long long number, unsigned long long numberOfBits);
19 
29 template<typename N> std::string getNumberAsString(
30  N number,
31  std::ios_base &(* format)(std::ios_base &) = std::dec)
32 {
33  if((!std::numeric_limits<N>::is_signed && number != std::numeric_limits<N>::max())
34  || (std::numeric_limits<N>::is_signed && number != std::numeric_limits<N>::min()))
35  {
36  std::ostringstream ss;
37  ss << format << number;
38  return ss.str();
39  }
40 
41  return "";
42 }
43 
50 template<typename N> inline bool indexIsValid(const std::vector<N> &list, std::size_t index)
51 {
52  return index < list.size();
53 }
54 
55 } // namespace fileinfo
56 } // namespace retdec
57 
58 #endif
Conversion utilities.
std::string getBinaryRepresentation(unsigned long long number, unsigned long long numberOfBits)
Definition: type_conversions.cpp:18
bool indexIsValid(const std::vector< N > &list, std::size_t index)
Definition: type_conversions.h:50
std::string getNumberAsString(N number, std::ios_base &(*format)(std::ios_base &)=std::dec)
Definition: type_conversions.h:29
Definition: archive_wrapper.h:19