1 // Copyright 2008, Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 //  1. Redistributions of source code must retain the above copyright notice,
7 //     this list of conditions and the following disclaimer.
8 //  2. Redistributions in binary form must reproduce the above copyright notice,
9 //     this list of conditions and the following disclaimer in the documentation
10 //     and/or other materials provided with the distribution.
11 //  3. Neither the name of Google Inc. nor the names of its contributors may be
12 //     used to endorse or promote products derived from this software without
13 //     specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 // This file contains the declaration of the abstract Vec2 element.
27 
28 #ifndef KML_DOM_VEC2_H__
29 #define KML_DOM_VEC2_H__
30 
31 #include "kml/dom/element.h"
32 #include "kml/dom/kml22.h"
33 #include "kml/base/util.h"
34 
35 namespace kmlbase {
36 class Attributes;
37 }
38 
39 namespace kmldom {
40 
41 class Serializer;
42 class Visitor;
43 
44 // OGC KML 2.2 Standard: 16.21 kml:vec2Type
45 // OGC KML 2.2 XSD: <complexType name="vec2Type"...
46 class Vec2 : public Element {
47  public:
48   virtual ~Vec2();
Type()49   virtual KmlDomType Type() const { return Type_Vec2; }
IsA(KmlDomType type)50   virtual bool IsA(KmlDomType type) const {
51     return type == Type_Vec2;
52   }
53 
get_x()54   double get_x() const { return x_; }
has_x()55   bool has_x() const { return has_x_; }
set_x(double value)56   void set_x(double value) {
57     x_ = value;
58     has_x_ = true;
59   }
clear_x()60   void clear_x() {
61     x_ = 1.0;
62     has_x_ = false;
63   }
64 
get_y()65   double get_y() const { return y_; }
has_y()66   bool has_y() const { return has_y_; }
set_y(double value)67   void set_y(double value) {
68     y_ = value;
69     has_y_ = true;
70   }
clear_y()71   void clear_y() {
72     y_ = 1.0;
73     has_y_ = false;
74   }
75 
get_xunits()76   int get_xunits() const { return xunits_; }
has_xunits()77   bool has_xunits() const { return has_xunits_; }
set_xunits(int value)78   void set_xunits(int value) {
79     xunits_ = value;
80     has_xunits_ = true;
81   }
clear_xunits()82   void clear_xunits() {
83     xunits_ = false;
84     has_xunits_ = false;
85   }
86 
get_yunits()87   int get_yunits() const { return yunits_; }
has_yunits()88   bool has_yunits() const { return has_yunits_; }
set_yunits(int value)89   void set_yunits(int value) {
90     yunits_ = value;
91     has_yunits_ = true;
92   }
clear_yunits()93   void clear_yunits() {
94     yunits_ = false;
95     has_yunits_ = false;
96   }
97 
98   // Visitor API methods, see visitor.h.
99   virtual void Accept(Visitor* visitor);
100 
101  protected:
102   // Vec2 is abstract, derived class access only.
103   Vec2();
104   virtual void ParseAttributes(kmlbase::Attributes* attributes);
105   virtual void SerializeAttributes(kmlbase::Attributes* attributes) const;
106   void Serialize(Serializer& serializer) const;
107 
108  private:
109   double x_;
110   bool has_x_;
111   double y_;
112   bool has_y_;
113   int xunits_;
114   bool has_xunits_;
115   int yunits_;
116   bool has_yunits_;
117   LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Vec2);
118 };
119 
120 }  // end namespace kmldom
121 
122 #endif  // KML_DOM_VEC2_H__
123