libpniio
conversion_trait.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2015 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio 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 // libpniio 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 libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 //
20 // Created on: Jan 30, 2015
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 //
24 #pragma once
25 
26 #include <sstream>
27 
28 #include<pni/core/types.hpp>
29 
30 
31 namespace pni{
32 namespace io{
33 
45  template<typename T>
47  {
49  typedef T result_type;
51  typedef T read_type;
52 
61  static result_type convert(read_type &&v)
62  {
63  return v;
64  }
65 
66  //--------------------------------------------------------------------
76  static result_type convert(const read_type &v)
77  {
78  return v;
79  }
80  };
81 
82  //------------------------------------------------------------------------
90  template<>
91  struct conversion_trait<pni::core::uint8>
92  {
94  typedef pni::core::uint8 result_type;
96  typedef pni::core::uint16 read_type;
97 
98  //------------------------------------------------------------------
111  static result_type convert(read_type &&v)
112  {
113  return pni::core::convert<result_type>(v);
114  }
115 
116  //------------------------------------------------------------------
129  static result_type convert(const read_type &v)
130  {
131  return pni::core::convert<result_type>(v);
132  }
133  };
134 
135  //------------------------------------------------------------------------
143  template<>
144  struct conversion_trait<pni::core::int8>
145  {
147  typedef pni::core::int8 result_type;
149  typedef pni::core::int16 read_type;
150 
151  //------------------------------------------------------------------
164  static result_type convert(read_type &&v)
165  {
166  return pni::core::convert<result_type>(v);
167  }
168 
169  //------------------------------------------------------------------
182  static result_type convert(const read_type &v)
183  {
184  return pni::core::convert<result_type>(v);
185  }
186  };
187 
188 //end of namespace
189 }
190 }
default conversion trait
Definition: conversion_trait.hpp:46
static result_type convert(const read_type &v)
convert uint16 to uint8
Definition: conversion_trait.hpp:129
static result_type convert(read_type &&v)
conversion function
Definition: conversion_trait.hpp:61
pni::core::uint16 read_type
the type to read
Definition: conversion_trait.hpp:96
pni::core::uint8 result_type
the type requested by the user
Definition: conversion_trait.hpp:94
static result_type convert(read_type &&v)
convert uint16 to uint8
Definition: conversion_trait.hpp:111
T result_type
the type requested by the user
Definition: conversion_trait.hpp:49
Definition: cbf_reader.hpp:41
pni::core::int16 read_type
the type used for reading
Definition: conversion_trait.hpp:149
T read_type
the type to read
Definition: conversion_trait.hpp:51
static result_type convert(read_type &&v)
convert int16 to int8
Definition: conversion_trait.hpp:164
pni::core::int8 result_type
the type requested by the user
Definition: conversion_trait.hpp:147
static result_type convert(const read_type &v)
conversion function
Definition: conversion_trait.hpp:76
static result_type convert(const read_type &v)
convert int16 to int8
Definition: conversion_trait.hpp:182