1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2018, Knut Reinert, FU Berlin
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 //       notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above copyright
13 //       notice, this list of conditions and the following disclaimer in the
14 //       documentation and/or other materials provided with the distribution.
15 //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
16 //       its contributors may be used to endorse or promote products derived
17 //       from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32 // Author: Andreas Gogol-Döring <andreas.doering@mdc-berlin.de>
33 // ==========================================================================
34 // Interface specification functions for types that have a host.
35 // ==========================================================================
36 
37 // TODO(holtgrew): We could add a HostedTypeConcept and make this a submodule of basic, e.g. basic/hosted.
38 // TODO(holtgrew): This looks a bit unused/underused.
39 
40 #ifndef SEQAN_INCLUDE_SEQAN_BASIC_HOSTED_TYPE_INTERFACE_H_
41 #define SEQAN_INCLUDE_SEQAN_BASIC_HOSTED_TYPE_INTERFACE_H_
42 
43 namespace seqan {
44 
45 // ============================================================================
46 // Forwards
47 // ============================================================================
48 
49 // ============================================================================
50 // Tags, Classes, Enums
51 // ============================================================================
52 
53 /*!
54  * @concept HostedConcept
55  * @brief Concept for types that have a host.
56  *
57  * @signature concept HostedConcept;
58  *
59  * @section Remarks
60  *
61  * The functions of this concept assume that the hosted object exports a function <tt>_dataHost</tt> that returns a
62  * reference to a holder type of <tt>Host&lt;T&gt;::Type &amp;</tt>.
63  */
64 
65 // ============================================================================
66 // Metafunctions
67 // ============================================================================
68 
69 /*!
70  * @mfn HostedConcept#Host
71  * @brief Type of the object a given object depends on.
72  *
73  * @signature Host<T>::Type
74  *
75  * @tparam T Type for which the host type is determined.
76  * @return Type The Host type.
77  */
78 
79 template <typename T>
80 struct Host;
81 
82 // ============================================================================
83 // Functions
84 // ============================================================================
85 
86 // ----------------------------------------------------------------------------
87 // Function emptyHost()
88 // ----------------------------------------------------------------------------
89 
90 /*!
91  * @fn HostedConcept#emptyHost
92  * @brief Query emptiness state of a hosted object.
93  *
94  * @signature bool emptyHost(object);
95  *
96  * @param[in] object The object query state of host of.
97  *
98  * @return bool <tt>true</tt> if the host is empty, <tt>false</tt> otherwise.
99  */
100 
101 template <typename T>
102 inline bool
emptyHost(T const & me)103 emptyHost(T const & me)
104 {
105     return empty(_dataHost(me));
106 }
107 
108 // ----------------------------------------------------------------------------
109 // Function dependentHost()
110 // ----------------------------------------------------------------------------
111 
112 /*!
113  * @fn HostedConcept#dependentHost
114  * @brief Query dependent state of a hosted object.
115  *
116  * @signature void clearHost(object);
117  *
118  * @param[in] object The object query state of host of.
119  *
120  * @return bool <tt>true</tt> if the host is dependent, <tt>false</tt> otherwise.
121  */
122 
123 template <typename T>
124 inline bool
dependentHost(T const & me)125 dependentHost(T const & me)
126 {
127     return dependent(_dataHost(me));
128 }
129 
130 // ----------------------------------------------------------------------------
131 // Function clearHost()
132 // ----------------------------------------------------------------------------
133 
134 /*!
135  * @fn HostedConcept#clearHost
136  * @brief Clear the host of the given object.
137  *
138  * @signature void clearHost(object);
139  *
140  * @param[in,out] object The object to clear the host of.
141  */
142 
143 template <typename T>
144 inline void
clearHost(T & me)145 clearHost(T & me)
146 {
147     clear(_dataHost(me));
148 }
149 
150 // ----------------------------------------------------------------------------
151 // Function createHost()
152 // ----------------------------------------------------------------------------
153 
154 /*!
155  * @fn HostedConcept#createHost
156  * @brief Construct the host of the given object.
157  *
158  * @signature void createHost(object[, host]);
159  *
160  * @param[in,out] object The object to copy construct the host of.
161  * @param[in]     host   The object to copy in host creation.
162  *
163  * @section Remarks
164  *
165  * If <tt>host</tt> is given then it is used for copy creation.  Otherwise, the default constructor is used.
166  */
167 
168 template <typename T>
169 inline void
createHost(T & me)170 createHost(T & me)
171 {
172     create(_dataHost(me));
173 }
174 
175 template <typename T, typename THost>
176 inline void
createHost(T & me,THost const & host_)177 createHost(T & me,
178            THost const & host_)
179 {
180     create(_dataHost(me), host_);
181 }
182 
183 // ----------------------------------------------------------------------------
184 // Function host()
185 // ----------------------------------------------------------------------------
186 
187 /*!
188  * @fn HostedConcept#host
189  * @brief The object a given object depends on.
190  *
191  * @signature THostRef host(object);
192  *
193  * @param[in] object An object.
194  *
195  * @return THostRef Reference to the host object.
196  */
197 
198 /// TODO(holtgrew): Move documentation here?
199 
200 template <typename T>
201 inline typename Host<T>::Type &
host(T & me)202 host(T & me)
203 {
204     return value(_dataHost(me));
205 }
206 
207 // TODO(holtgrew): Is this function unnecessary? Should be since the above one is catch-all.
208 // (weese:) No, the above wouldn't catch const refs.
209 template <typename T>
210 inline typename Host<T const>::Type &
host(T const & me)211 host(T const & me)
212 {
213     return value(_dataHost(me));
214 }
215 
216 // ----------------------------------------------------------------------------
217 // Function setHost()
218 // ----------------------------------------------------------------------------
219 
220 /*!
221  * @fn HostedConcept#setHost
222  * @brief Sets the host of an object.
223  *
224  * @signature void setHost(object, host);
225  *
226  * @param[in,out] host   The new host. Types: String
227  * @param[in]     object The object that will get a new host.
228  *
229  * @section Remarks
230  *
231  * After this operation, <tt>object</tt> depends on <tt>host</tt>.
232  *
233  * Note that setting the host can invalidate <tt>object</tt>.  For example, if one changes the host of a Segment object,
234  * it is possible that begin- and end-position of the segment does not fit into the new host sequence.
235  */
236 
237 template <typename T, typename THost>
238 inline void
setHost(T & me,THost && host_)239 setHost(T & me,
240         THost && host_)
241 {
242     setValue(_dataHost(me), std::forward<THost>(host_));
243 }
244 
245 // ----------------------------------------------------------------------------
246 // Function assignHost()
247 // ----------------------------------------------------------------------------
248 
249 /*!
250  * @fn HostedConcept#assignHost
251  * @brief Assign to the host of a given value.
252  *
253  * @signature void assignHost(object, host);
254  *
255  * @param[in,out] host   The object to assign as host.
256  * @param[in]     object The object to assign the host of.
257  */
258 
259 template <typename T, typename THost>
260 inline void
assignHost(T & me,THost const & host_)261 assignHost(T & me,
262            THost const & host_)
263 {
264     assignValue(_dataHost(me), host_);
265 }
266 
267 // ----------------------------------------------------------------------------
268 // Function moveHost()
269 // ----------------------------------------------------------------------------
270 
271 /*!
272  * @fn HostedConcept#moveHost
273  * @brief Move to the host of a given value.
274  *
275  * @signature void moveHost(object, host);
276  *
277  * @param[in,out] host   The object to move-assign as host.
278  * @param[in,out] object The object to move-assign the host of.
279  */
280 
281 template <typename T, typename THost>
282 inline void
moveHost(T & me,THost & host_)283 moveHost(T & me,
284          THost & host_)
285 {
286     moveValue(_dataHost(me), host_);
287 }
288 
289 }  // namespace seqan
290 
291 #endif  // #ifndef SEQAN_INCLUDE_SEQAN_BASIC_HOSTED_TYPE_INTERFACE_H_
292