libpnicore
binary.hpp
1 //
2 // (c) Copyright 2011 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: Feb 8, 2012
22 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 //
24 
25 #pragma once
26 #include <iostream>
27 
28 
29 namespace pni{
30 namespace core{
31 
57  template<typename NTYPE> class binary_t
58  {
59  public:
60  //=================public data types===============================
62  typedef NTYPE storage_type;
63  private:
65  storage_type _value;
66 
68  const binary_t<storage_type> &
69  operator+=(const binary_t<storage_type> &b) = delete;
71  const binary_t<storage_type> &
72  operator-=(const binary_t<storage_type> &b) = delete;
74  const binary_t<storage_type> &
75  operator*=(const binary_t<storage_type> &b) = delete;
77  const binary_t<storage_type> &
78  operator/=(const binary_t<storage_type> &b) = delete;
79  public:
80 
81  //=============constructors and destructor=========================
83  explicit binary_t():_value(storage_type(0)) {}
84 
85  //-----------------------------------------------------------------
87  binary_t(const storage_type &value):_value(value) {}
88 
89  //-----------------------------------------------------------------
92  _value(o._value)
93  {}
94 
95  //-----------------------------------------------------------------
101  operator NTYPE() const
102  {
103  return _value;
104  }
105 
106  };
107 
108 
110  template<typename NTYPE> binary_t<NTYPE>
111  operator+(const binary_t<NTYPE> &a,const binary_t<NTYPE> &b)
112  = delete;
113 
115  template<typename NTYPE> binary_t<NTYPE>
116  operator-(const binary_t<NTYPE> &a,const binary_t<NTYPE> &b)
117  =delete;
118 
120  template<typename NTYPE> binary_t<NTYPE>
121  operator*(const binary_t<NTYPE> &a,const binary_t<NTYPE> &b)
122  =delete;
123 
125  template<typename NTYPE> binary_t<NTYPE>
126  operator/(const binary_t<NTYPE> &a,const binary_t<NTYPE> &b)
127  =delete;
128 
129 
130  //-------------------------------------------------------------------------
142  template<typename NTYPE>
143  std::ostream &operator<<(std::ostream &os,const binary_t<NTYPE> &o)
144  {
145  NTYPE b = o;
146  os<<b;
147  return os;
148  }
149 
150  //-------------------------------------------------------------------------
162  template<typename NTYPE>
163  std::istream &operator>>(std::istream &is,binary_t<NTYPE> &o)
164  {
165  NTYPE b;
166  is>>b;
167  o = b;
168  return is;
169  }
170 
171 //end of namespace
172 }
173 }
const binary_t< storage_type > & operator/=(const binary_t< storage_type > &b)=delete
unary division operator - delete
std::istream & operator>>(std::istream &is, binary_t< NTYPE > &o)
input stream operator for binary data
Definition: binary.hpp:163
Definition: add_op.hpp:29
binary_t(const storage_type &value)
constructor
Definition: binary.hpp:87
const binary_t< storage_type > & operator*=(const binary_t< storage_type > &b)=delete
unary multiplication operator
scalar_iterator< ITERABLE > operator+(const scalar_iterator< ITERABLE > &a, ssize_t b)
add scalar to iterator
Definition: scalar_iterator.hpp:272
const binary_t< storage_type > & operator+=(const binary_t< storage_type > &b)=delete
unary addition operator - deleted
const binary_t< storage_type > & operator-=(const binary_t< storage_type > &b)=delete
unary subtraction operator - delete
binary_t(const binary_t< storage_type > &o)
copy constructor
Definition: binary.hpp:91
Binary data type.
Definition: binary.hpp:57
NTYPE storage_type
native type that is used for binary data
Definition: binary.hpp:62
binary_t()
default constructor
Definition: binary.hpp:83
type erasure for POD data
Definition: value.hpp:46
storage_type _value
data value
Definition: binary.hpp:65
scalar_iterator< ITERABLE > operator-(const scalar_iterator< ITERABLE > &a, ssize_t b)
subtract offset from iterator
Definition: scalar_iterator.hpp:312