source: trunk/GDE/SINA/builddir/src/cseq_impl.h

Last change on this file was 19170, checked in by westram, 2 years ago
  • sina source
    • unpack + remove tarball
    • no longer ignore sina builddir.
File size: 4.0 KB
Line 
1/*
2Copyright (c) 2006-2018 Elmar Pruesse <elmar.pruesse@ucdenver.edu>
3
4This file is part of SINA.
5SINA is free software: you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
7Software Foundation, either version 3 of the License, or (at your
8option) any later version.
9
10SINA is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13for more details.
14
15You should have received a copy of the GNU General Public License
16along with SINA.  If not, see <http://www.gnu.org/licenses/>.
17
18Additional permission under GNU GPL version 3 section 7
19
20If you modify SINA, or any covered work, by linking or combining it
21with components of ARB (or a modified version of that software),
22containing parts covered by the terms of the
23ARB-public-library-license, the licensors of SINA grant you additional
24permission to convey the resulting work. Corresponding Source for a
25non-source form of such a combination shall include the source code
26for the parts of ARB used as well as that of the covered work.
27*/
28
29#ifndef _CSEQ_IMPL_H_
30#define _CSEQ_IMPL_H_
31
32#include "cseq.h"
33
34namespace sina {
35
36inline cseq_base&
37cseq_base::append(const std::string& str) {
38  return append(str.c_str());
39}
40
41template<typename T>
42class lexical_cast_visitor
43    : public boost::static_visitor<T> {
44public:
45    template<typename S>
46    const T operator()(const S& s) const {
47        try {
48            return boost::lexical_cast<T>(s);
49        } catch (...) {
50            return T();
51        }
52    }
53
54    // no convert for identical type
55
56    const T operator()(const T& t) const {
57        return t;
58    }
59
60    // return default value for vector (no sense to convert)
61    const T operator()(const std::vector<cseq_base>& /*v*/) const {
62        return T();
63    }
64};
65
66inline cseq_base::iterator
67prev_begin(const cseq_base& c, const cseq_base::iterator& it) {
68  if (c.begin() != it) {
69    return it-1;
70  }
71  return it;
72}
73inline cseq_base::iterator
74prev_end(const cseq_base& /*c*/, const cseq_base::iterator& it) {
75  return it;
76}
77inline bool
78has_prev(const cseq_base& c, const cseq_base::iterator& it) {
79  return c.begin() != it;
80}
81
82inline cseq_base::iterator
83next_begin(const cseq_base& /*c*/, const cseq_base::iterator& it) {
84  return it+1;
85}
86inline cseq_base::iterator
87next_end(const cseq_base& c, const cseq_base::iterator& it) {
88  if (it+1 == c.end()) {
89    return it + 1;
90  }
91  return it + 2;
92}
93inline bool
94has_next(const cseq_base& c, const cseq_base::iterator& it) {
95  return (it+1) != c.end();
96}
97
98
99inline cseq_base::idx_type
100get_node_id(cseq_base& c, const cseq_base::iterator& it){
101    return it - c.begin();
102}
103
104inline cseq_base::iterator
105cseq_base::begin() {
106    return {bases.begin()};
107}
108
109inline cseq_base::const_iterator
110cseq_base::begin() const {
111    return {bases.begin()};
112}
113
114inline cseq_base::const_reverse_iterator
115cseq_base::rbegin() const {
116    return {bases.rbegin()};
117}
118
119
120inline cseq_base::iterator
121cseq_base::end() {
122    return {bases.end()};
123}
124
125inline cseq_base::const_iterator
126cseq_base::end() const {
127    return {bases.end()};
128}
129inline cseq_base::const_reverse_iterator
130cseq_base::rend() const {
131    return {bases.rend()};
132}
133
134inline cseq_base::iterator
135cseq_base::getIterator(cseq_base::vidx_type i) {
136  // this is weird. FIXME
137    return {std::lower_bound(bases.begin(),
138                                bases.end(),aligned_base(i,'.'))};
139}
140
141inline cseq_base::const_iterator
142cseq_base::getIterator(cseq_base::vidx_type i) const {
143    return {lower_bound(bases.begin(),
144                                      bases.end(),aligned_base(i,'.'))};
145}
146
147
148template<typename T>
149void
150for_each_prev(cseq_base::iterator cit, T t) {
151    t(*(cit-1));
152}
153
154} // namespace sina
155
156#endif // _CSEQ_IMPL_H_
157
158/*
159  Local Variables:
160  mode:c++
161  c-file-style:"stroustrup"
162  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163  indent-tabs-mode:nil
164  fill-column:99
165  End:
166*/
167// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
Note: See TracBrowser for help on using the repository browser.