libpnicore
make_array.hpp
1 //
2 // (c) Copyright 2013 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpnicore.
5 //
6 // libpnicore is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpnicore is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpnicore. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // ============================================================================
20 //
21 // Created on: Jan 11, 2013
22 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 //
24 #pragma once
25 
26 #include "../arrays.hpp"
27 
28 namespace pni{
29 namespace core{
30 
44  template<
45  typename T,
46  typename STYPE
47  >
48  array make_array(const STYPE &shape)
49  {
50  typedef dynamic_array<T> array_type;
51 
52  return array(array_type::create(shape));
53  }
54 
55  //------------------------------------------------------------------------
69  template<typename CTYPE>
70  array make_array(type_id_t tid,const CTYPE &shape)
71  {
72  if(tid == type_id_t::UINT8)
73  return make_array<uint8>(shape);
74  else if(tid == type_id_t::INT8)
75  return make_array<int8>(shape);
76  else if(tid == type_id_t::UINT16)
77  return make_array<uint16>(shape);
78  else if(tid == type_id_t::INT16)
79  return make_array<int16>(shape);
80  else if(tid == type_id_t::UINT32)
81  return make_array<uint32>(shape);
82  else if(tid == type_id_t::INT32)
83  return make_array<int32>(shape);
84  else if(tid == type_id_t::UINT64)
85  return make_array<uint64>(shape);
86  else if(tid == type_id_t::INT64)
87  return make_array<int64>(shape);
88  else if(tid == type_id_t::FLOAT32)
89  return make_array<float32>(shape);
90  else if(tid == type_id_t::FLOAT64)
91  return make_array<float64>(shape);
92  else if(tid == type_id_t::FLOAT128)
93  return make_array<float128>(shape);
94  else if(tid == type_id_t::COMPLEX32)
95  return make_array<complex32>(shape);
96  else if(tid == type_id_t::COMPLEX64)
97  return make_array<complex64>(shape);
98  else if(tid == type_id_t::COMPLEX128)
99  return make_array<complex128>(shape);
100  else if(tid == type_id_t::BOOL)
101  return make_array<bool_t>(shape);
102  else if(tid == type_id_t::BINARY)
103  return make_array<binary>(shape);
104  else if(tid == type_id_t::STRING)
105  return make_array<string>(shape);
106  else
107  throw type_error(EXCEPTION_RECORD,"Type ID cannot be processed!");
108 
109 
110  }
111 //end of namespace
112 }
113 }
32Bit IEEE floating point
#define EXCEPTION_RECORD
macro creating an instance of ExceptionRecord
Definition: exceptions.hpp:48
type erasure array types
Definition: array.hpp:74
data type error
Definition: exceptions.hpp:544
signed 8Bit integer
unsigned 32Bit integer
unsigned 64Bit integer
unsigned 16Bit integer
128Bit IEEE floating point complex
64Bit IEEE floating point
Definition: add_op.hpp:29
array make_array(type_id_t tid, const CTYPE &shape)
create array
Definition: make_array.hpp:70
unsigned 8Bit integer
template for a multi-dimensional array class
Definition: mdarray.hpp:66
32Bit IEEE floating point complex
128Bit IEEE floating point
type_id_t
type codes for PNI data types
Definition: types/types.hpp:148
64Bit IEEE floating point complex
signed 64Bit integer
signed 32Bit integer
signed 16Bit integer