astrotypes  0.0
SigProcFormat.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 #ifndef PSS_ASTROTYPES_SIGPROC_SIGPROCFORMAT_H
25 #define PSS_ASTROTYPES_SIGPROC_SIGPROCFORMAT_H
26 
28 #include <iostream>
29 
30 namespace pss {
31 namespace astrotypes {
32 namespace sigproc {
33 
38 template<typename Dimension1, typename Dimension2>
40  SigProcFormat() { static_assert(true, "dimesions must be Time or Frequency for SigProcFormat"); }
41 };
42 
43 
44 template<typename Dimension1>
45 class SigProcFormat<Dimension1, Dimension1> {
46  SigProcFormat() { static_assert(true, "dimesions cannot be the same for SigProcFormat"); }
47 };
48 
49 
50 template<>
52 {
53  public:
54  class OSigProcFormat {
55  friend SigProcFormat;
56  protected:
57  OSigProcFormat(std::ostream& os) : _os(os) {}
58 
59  public:
60  template<typename T>
61  typename std::enable_if<has_exact_dimensions<T, units::Time, units::Frequency>::value, OSigProcFormat const&>::type
62  operator<<(T const&) const;
63 
64  template<typename T>
65  typename std::enable_if<has_exact_dimensions<T, units::Time>::value, OSigProcFormat const&>::type
66  operator<<(T const&) const;
67 
68  template<typename T>
69  typename std::enable_if<has_exact_dimensions<T, units::Frequency>::value, OSigProcFormat const&>::type
70  operator<<(T const&) const;
71 
72  template<typename T>
73  typename std::enable_if<has_exact_dimensions<T, units::Frequency, units::Time>::value, OSigProcFormat const&>::type
74  operator<<(T const&) const;
75 
76  protected:
77  std::ostream& _os;
78  };
79 
80  class ISigProcFormat {
81  friend SigProcFormat;
82  protected:
83  ISigProcFormat(std::istream& is) : _is(is) {}
84 
85  public:
86  template<typename T>
87  typename std::enable_if<has_exact_dimensions<T, units::Time, units::Frequency>::value, ISigProcFormat const&>::type
88  operator>>(T&) const;
89 
90  template<typename T>
91  typename std::enable_if<has_exact_dimensions<T, units::Time>::value, ISigProcFormat const&>::type
92  operator>>(T&) const;
93 
94  template<typename T>
95  typename std::enable_if<has_exact_dimensions<T, units::Frequency, units::Time>::value, ISigProcFormat const&>::type
96  operator>>(T&) const;
97 
98  protected:
99  std::istream& _is;
100  };
101 
102  public:
104  inline OSigProcFormat operator<<(std::ostream&) const;
105  inline ISigProcFormat operator>>(std::istream&) const;
106 };
107 
108 template<>
110 {
111  public:
112  class OSigProcFormat {
113  friend SigProcFormat;
114 
115  protected:
116  OSigProcFormat(std::ostream& os) : _os(os) {}
117 
118  public:
119  template<typename T, typename Alloc>
120  OSigProcFormat const& operator<<(astrotypes::TimeFrequency<T, Alloc> const&);
121 
122  template<typename T, typename Alloc>
123  OSigProcFormat const& operator<<(astrotypes::FrequencyTime<T, Alloc> const&);
124 
125  template<typename T>
126  typename std::enable_if<has_exact_dimensions<T, units::Time>::value, OSigProcFormat const&>::type
127  operator<<(T const&) const;
128 
129  template<typename T>
130  typename std::enable_if<has_exact_dimensions<T, units::Frequency>::value, OSigProcFormat const&>::type
131  operator<<(T const&) const;
132 
133  protected:
134  std::ostream& _os;
135  };
136 
137  class ISigProcFormat {
138  friend SigProcFormat;
139  protected:
140  ISigProcFormat(std::istream& is) : _is(is) {}
141 
142  public:
143  template<typename T>
144  typename std::enable_if<has_exact_dimensions<T, units::Frequency, units::Time>::value, ISigProcFormat const&>::type
145  operator>>(T&) const;
146 
147  template<typename T>
148  typename std::enable_if<has_exact_dimensions<T, units::Frequency>::value, ISigProcFormat const&>::type
149  operator>>(T&) const;
150 
151  template<typename T>
152  typename std::enable_if<has_exact_dimensions<T, units::Time, units::Frequency>::value, ISigProcFormat const&>::type
153  operator>>(T&) const;
154 
155  protected:
156  std::istream& _is;
157  };
158 
159  public:
161  inline OSigProcFormat operator<<(std::ostream&) const;
162  inline ISigProcFormat operator>>(std::istream&) const;
163 };
164 
165 // forward declaration
166 template<typename Dimension1, typename Dimension2>
167 typename SigProcFormat<Dimension1, Dimension2>::OSigProcFormat operator<<(std::ostream& os, SigProcFormat<Dimension1, Dimension2> const&);
168 
169 template<typename Dimension1, typename Dimension2>
170 typename SigProcFormat<Dimension1, Dimension2>::ISigProcFormat operator>>(std::istream& os, SigProcFormat<Dimension1, Dimension2> const&);
171 
172 } // namespace sigproc
173 } // namespace astrotypes
174 } // namespace pss
175 #include "detail/SigProcFormat.cpp"
176 
177 #endif // PSS_ASTROTYPES_SIGPROC_SIGPROCFORMAT_H
boost::units::time_dimension Time
Definition: Time.h:42
std::istream & operator>>(std::istream &stream, HeaderBase< Derived > &headers)
Definition: HeaderBase.cpp:180
stream adapter to convert TimeFrequency or FrequencyTime types to filterbank output ...
Definition: SigProcFormat.h:39
Header::InfoSentry< Stream > operator<<(Stream &os, Header::Info const &adapter)
Definition: Header.cpp:397
boost::units::frequency_dimension Frequency
Definition: Frequency.h:45