FV3 Bundle
oops/interface/GeometryIterator.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_INTERFACE_GEOMETRYITERATOR_H_
12 #define OOPS_INTERFACE_GEOMETRYITERATOR_H_
13 
14 #include <iterator>
15 #include <string>
16 
17 #include <boost/scoped_ptr.hpp>
18 
19 #include "oops/base/GeoLocation.h"
20 #include "oops/util/Logger.h"
21 #include "oops/util/ObjectCounter.h"
22 #include "oops/util/Printable.h"
23 #include "oops/util/Timer.h"
24 
25 namespace oops {
26 
27 // -----------------------------------------------------------------------------
28 template<typename MODEL>
29 class GeometryIterator: public std::iterator<std::forward_iterator_tag, GeoLocation>,
30  public util::Printable,
31  private util::ObjectCounter<GeometryIterator<MODEL>> {
32  typedef typename MODEL::GeometryIterator GeometryIterator_;
33 
34  public:
35  static const std::string classname() {return "oops::GeometryIterator";}
36 
38  explicit GeometryIterator(const GeometryIterator_&);
40 
41  bool operator==(const GeometryIterator&);
42  bool operator!=(const GeometryIterator&);
45 
46 /// Interfacing
47  const GeometryIterator_ & geometryiter() const {return *geometryiter_;}
49 
50  private:
51  void print(std::ostream &) const;
52  boost::scoped_ptr<GeometryIterator_> geometryiter_;
53 };
54 
55 // -----------------------------------------------------------------------------
56 
57 template<typename MODEL>
59  Log::trace() << "GeometryIterator<MODEL>::GeometryIterator starting" << std::endl;
60  util::Timer timer(classname(), "GeometryIterator");
61  geometryiter_.reset(new GeometryIterator_(other.geometryiter()));
62  Log::trace() << "GeometryIterator<MODEL>::GeometryIterator done" << std::endl;
63 }
64 
65 // -----------------------------------------------------------------------------
66 
67 template<typename MODEL>
69  Log::trace() << "GeometryIterator<MODEL>::GeometryIterator starting" << std::endl;
70  util::Timer timer(classname(), "GeometryIterator");
71  geometryiter_.reset(new GeometryIterator_(iter));
72  Log::trace() << "GeometryIterator<MODEL>::GeometryIterator done" << std::endl;
73 }
74 
75 // -----------------------------------------------------------------------------
76 
77 template<typename MODEL>
79  Log::trace() << "GeometryIterator<MODEL>::~GeometryIterator starting" << std::endl;
80  util::Timer timer(classname(), "~GeometryIterator");
81  geometryiter_.reset();
82  Log::trace() << "GeometryIterator<MODEL>::~GeometryIterator done" << std::endl;
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 template<typename MODEL>
89  Log::trace() << "GeometryIterator<MODEL>::operator== starting" << std::endl;
90  util::Timer timer(classname(), "operator==");
91  bool equals = (*geometryiter_ == other.geometryiter());
92  Log::trace() << "GeometryIterator<MODEL>::operator== done" << std::endl;
93  return equals;
94 }
95 
96 // -----------------------------------------------------------------------------
97 
98 template<typename MODEL>
100  Log::trace() << "GeometryIterator<MODEL>::operator!= starting" << std::endl;
101  util::Timer timer(classname(), "operator!=");
102  bool notequals = (*geometryiter_ != other.geometryiter());
103  Log::trace() << "GeometryIterator<MODEL>::operator!= done" << std::endl;
104  return notequals;
105 }
106 
107 
108 // -----------------------------------------------------------------------------
109 
110 template<typename MODEL>
112  Log::trace() << "GeometryIterator<MODEL>::operator* starting" << std::endl;
113  util::Timer timer(classname(), "operator*");
114  GeoLocation geoloc = *(*geometryiter_);
115  Log::trace() << "GeometryIterator<MODEL>::operator* done" << std::endl;
116  return geoloc;
117 }
118 
119 // -----------------------------------------------------------------------------
120 
121 template<typename MODEL>
123  Log::trace() << "GeometryIterator<MODEL>::operator++ starting" << std::endl;
124  util::Timer timer(classname(), "operator++");
125  ++(*geometryiter_);
126  Log::trace() << "GeometryIterator<MODEL>::operator++ done" << std::endl;
127  return *this;
128 }
129 
130 
131 // -----------------------------------------------------------------------------
132 
133 template<typename MODEL>
134 void GeometryIterator<MODEL>::print(std::ostream & os) const {
135  Log::trace() << "GeometryIterator<MODEL>::print starting" << std::endl;
136  util::Timer timer(classname(), "print");
137  os << *geometryiter_;
138  Log::trace() << "GeometryIterator<MODEL>::print done" << std::endl;
139 }
140 
141 
142 } // namespace oops
143 
144 #endif // OOPS_INTERFACE_GEOMETRYITERATOR_H_
bool operator!=(const GeometryIterator &)
boost::scoped_ptr< GeometryIterator_ > geometryiter_
static const std::string classname()
The namespace for the main oops code.
const GeometryIterator_ & geometryiter() const
Interfacing.
bool operator==(const GeometryIterator &)
MODEL::GeometryIterator GeometryIterator_
void print(std::ostream &) const
GeometryIterator(const GeometryIterator &)