astrotypes  0.0
SigProcVariable.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wall"
26 #pragma GCC diagnostic ignored "-Wpragmas"
27 #pragma GCC diagnostic ignored "-Wunused-parameter"
28 #pragma GCC diagnostic ignored "-Wunused-variable"
29 #include <boost/units/quantity.hpp>
30 #pragma GCC diagnostic pop
31 
32 #ifndef PSS_ASTROTYPES_SIGPROC_SIGPROCVARIABLE_H
33 #define PSS_ASTROTYPES_SIGPROC_SIGPROCVARIABLE_H
34 
35 #include <cstring>
36 #include <iostream>
37 
38 namespace pss {
39 namespace astrotypes {
40 namespace sigproc {
41 
50 template<typename T>
52 {
57  static unsigned write(std::ostream&, T const& var);
58 
63  static unsigned read(std::istream&, T& var);
64 };
65 
66 // specialisation for std::string
67 template<>
68 struct SigProcVariable<std::string>
69 {
70  static unsigned write(std::ostream&, std::string const& var);
71  static unsigned read(std::istream&, std::string& var);
72 };
73 
74 // specialisation for boost::quantity types
75 template<typename Unit, typename T>
76 struct SigProcVariable<boost::units::quantity<Unit, T>>
77 {
78  static unsigned write(std::ostream&, boost::units::quantity<Unit, T> const& var);
79  static unsigned read(std::istream&, boost::units::quantity<Unit, T>& var);
80 };
81 
82 // strong typing for the Header labels
84 {
86  explicit SigProcLabel(std::string const& s) : _string(s) {}
87  explicit SigProcLabel(const char * s) : _string(s) {}
88 
89  std::size_t size() const {
90  return _string.size() + sizeof(int32_t);
91  }
92 
93  inline bool operator!=(const char* txt) const {
94  return std::strcmp(_string.c_str(), txt) != 0;
95  }
96 
97  // allows to be stored in std::map
98  inline bool operator<(SigProcLabel const& v) const { return _string < v._string; }
99 
100  std::string const& string() const { return _string; }
101 
102  void write(std::ostream& os) const;
103  void read(std::istream& is);
104 
105  private:
106  std::string _string;
107 };
108 
109 std::istream& operator>>(std::istream& stream, SigProcLabel& var);
110 std::ostream& operator<<(std::ostream& stream, SigProcLabel const& var);
111 
112 } // namespace sigproc
113 } // namespace astrotypes
114 } // namespace pss
115 
116 #include "SigProcVariable.cpp"
117 
118 #endif // PSS_ASTROTYPES_SIGPROC_SIGPROCVARIABLE_H
Definition: Quantity.h:93
static unsigned write(std::ostream &, T const &var)
write the provided variable to the stream
std::string const & string() const
STL namespace.
bool operator<(SigProcLabel const &v) const
static unsigned read(std::istream &, T &var)
read form the stream into the variable provided
std::istream & operator>>(std::istream &stream, HeaderBase< Derived > &headers)
Definition: HeaderBase.cpp:180
Read and write variables to sigproc format.
Header::InfoSentry< Stream > operator<<(Stream &os, Header::Info const &adapter)
Definition: Header.cpp:397
bool operator!=(const char *txt) const
void write(std::ostream &os) const