Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Array.h
Go to the documentation of this file.
1 //===-- serialbox/core/Array.h ------------------------------------------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_ARRAY_H
16 #define SERIALBOX_CORE_ARRAY_H
17 
18 #include <sstream>
19 #include <string>
20 #include <type_traits>
21 #include <vector>
22 
23 namespace serialbox {
24 
27 
30 template <class T>
31 using Array = std::vector<T>;
32 
34 struct ArrayUtil {
35 
37  template <class T>
38  static std::string toString(const Array<T>& array) {
39  std::stringstream ss;
40  if(!array.empty()) {
41  for(std::size_t i = 0; i < array.size() - 1; ++i)
42  ss << array[i] << ", ";
43  ss << array.back();
44  }
45  return ss.str();
46  }
47 };
48 
51 template <typename T>
52 struct IsArray : public std::false_type {};
53 
54 template <typename T>
55 struct IsArray<Array<T>> : public std::true_type {};
57 
58 namespace internal {
59 
60 template <class T, bool IsArray>
61 struct MakePrimitiveImpl {
62  using type = typename T::value_type;
63 };
64 
65 template <class T>
66 struct MakePrimitiveImpl<T, false> {
67  using type = T;
68 };
69 
70 } // namespace internal
71 
73 template <class T>
74 struct MakePrimitive {
75  using type = typename internal::MakePrimitiveImpl<T, IsArray<T>::value>::type;
76 };
77 
79 
80 } // namespace serialbox
81 
82 #endif
Utilites for Array.
Definition: Array.h:34
static std::string toString(const Array< T > &array)
Convert to string.
Definition: Array.h:38
std::vector< T > Array
Array class used by serialbox to store meta-information.
Definition: Array.h:31
Namespace of the serialbox library.
Definition: Archive.h:25
Return the primtive type (T::value_type) if T is an Array or T otherwise.
Definition: Array.h:74
Check if type T is an Array.
Definition: Array.h:52