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 NetworkLinkControl element. 27 28 #ifndef KML_DOM_NETWORKLINKCONTROL_H__ 29 #define KML_DOM_NETWORKLINKCONTROL_H__ 30 31 #include <vector> 32 #include "kml/dom/abstractview.h" 33 #include "kml/dom/container.h" 34 #include "kml/dom/element.h" 35 #include "kml/dom/feature.h" 36 #include "kml/dom/kml22.h" 37 #include "kml/dom/kml_ptr.h" 38 #include "kml/dom/object.h" 39 #include "kml/base/util.h" 40 41 namespace kmldom { 42 43 class Visitor; 44 class VisitorDriver; 45 46 // UpdateOperation 47 // An internal class from which <Create>, <Delete> and <Change> derive. The 48 // KML XSD uses a choice here which is not readily modeled in C++. 49 class UpdateOperation : public Element { 50 public: 51 virtual ~UpdateOperation(); 52 53 // Visitor API methods, see visitor.h. 54 virtual void Accept(Visitor* visitor); 55 56 protected: 57 // UpdateOperation is abstract. 58 UpdateOperation(); 59 60 private: 61 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(UpdateOperation); 62 }; 63 64 // <Create> 65 class Create : public UpdateOperation { 66 public: 67 virtual ~Create(); Type()68 virtual KmlDomType Type() const { return ElementType(); } IsA(KmlDomType type)69 virtual bool IsA(KmlDomType type) const { return type == ElementType(); } ElementType()70 static KmlDomType ElementType() { return Type_Create; } 71 72 // Create targets containers. add_container(const ContainerPtr & container)73 void add_container(const ContainerPtr& container) { 74 AddComplexChild(container, &container_array_); 75 } 76 get_container_array_size()77 size_t get_container_array_size() const { 78 return container_array_.size(); 79 } 80 get_container_array_at(size_t index)81 const ContainerPtr& get_container_array_at(size_t index) const { 82 return container_array_[index]; 83 } 84 85 // Visitor API methods, see visitor.h. 86 virtual void Accept(Visitor* visitor); 87 virtual void AcceptChildren(VisitorDriver* driver); 88 89 private: 90 friend class KmlFactory; 91 Create(); 92 friend class KmlHandler; 93 virtual void AddElement(const ElementPtr& element); 94 friend class Serializer; 95 virtual void Serialize(Serializer& serializer) const; 96 std::vector<ContainerPtr> container_array_; 97 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Create); 98 }; 99 100 // <Delete> 101 class Delete : public UpdateOperation { 102 public: 103 virtual ~Delete(); Type()104 virtual KmlDomType Type() const { return ElementType(); } IsA(KmlDomType type)105 virtual bool IsA(KmlDomType type) const { return type == ElementType(); } ElementType()106 static KmlDomType ElementType() { return Type_Delete; } 107 108 // Delete targets Features. add_feature(const FeaturePtr & feature)109 void add_feature(const FeaturePtr& feature) { 110 AddComplexChild(feature, &feature_array_); 111 } 112 get_feature_array_size()113 size_t get_feature_array_size() const { 114 return feature_array_.size(); 115 } 116 get_feature_array_at(size_t index)117 const FeaturePtr& get_feature_array_at(size_t index) const { 118 return feature_array_[index]; 119 } 120 121 // Visitor API methods, see visitor.h. 122 virtual void Accept(Visitor* visitor); 123 virtual void AcceptChildren(VisitorDriver* driver); 124 125 private: 126 friend class KmlFactory; 127 Delete(); 128 friend class KmlHandler; 129 virtual void AddElement(const ElementPtr& element); 130 friend class Serializer; 131 virtual void Serialize(Serializer& serializer) const; 132 std::vector<FeaturePtr> feature_array_; 133 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Delete); 134 }; 135 136 // <Change> 137 class Change : public UpdateOperation { 138 public: 139 virtual ~Change(); Type()140 virtual KmlDomType Type() const { return ElementType(); } IsA(KmlDomType type)141 virtual bool IsA(KmlDomType type) const { return type == ElementType(); } ElementType()142 static KmlDomType ElementType() { return Type_Change; } 143 144 // Change targets Objects. add_object(const ObjectPtr & object)145 void add_object(const ObjectPtr& object) { 146 AddComplexChild(object, &object_array_); 147 } 148 get_object_array_size()149 size_t get_object_array_size() const { 150 return object_array_.size(); 151 } 152 get_object_array_at(size_t index)153 const ObjectPtr& get_object_array_at(size_t index) const { 154 return object_array_[index]; 155 } 156 157 // Visitor API methods, see visitor.h. 158 virtual void Accept(Visitor* visitor); 159 virtual void AcceptChildren(VisitorDriver* driver); 160 161 private: 162 friend class KmlFactory; 163 Change(); 164 friend class KmlHandler; 165 virtual void AddElement(const ElementPtr& element); 166 friend class Serializer; 167 virtual void Serialize(Serializer& serializer) const; 168 std::vector<ObjectPtr> object_array_; 169 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Change); 170 }; 171 172 // <Update> 173 class Update : public BasicElement<Type_Update> { 174 public: 175 virtual ~Update(); 176 177 // <targetHref> get_targethref()178 const string& get_targethref() const { return targethref_; } has_targethref()179 bool has_targethref() const { return has_targethref_; } set_targethref(const string & targethref)180 void set_targethref(const string& targethref) { 181 targethref_ = targethref; 182 has_targethref_ = true; 183 } clear_targethref()184 void clear_targethref() { 185 targethref_.clear(); 186 has_targethref_ = false; 187 } 188 189 // <Create>, <Delete> and <Change> elements. add_updateoperation(const UpdateOperationPtr & updateoperation)190 void add_updateoperation(const UpdateOperationPtr& updateoperation) { 191 AddComplexChild(updateoperation, &updateoperation_array_); 192 } 193 get_updateoperation_array_size()194 size_t get_updateoperation_array_size() const { 195 return updateoperation_array_.size(); 196 } 197 get_updateoperation_array_at(size_t index)198 const UpdateOperationPtr& get_updateoperation_array_at( 199 size_t index) const { 200 return updateoperation_array_[index]; 201 } 202 203 // Visitor API methods, see visitor.h. 204 virtual void Accept(Visitor* visitor); 205 virtual void AcceptChildren(VisitorDriver* driver); 206 207 private: 208 friend class KmlFactory; 209 Update(); 210 friend class KmlHandler; 211 virtual void AddElement(const ElementPtr& element); 212 friend class Serializer; 213 virtual void Serialize(Serializer& serializer) const; 214 string targethref_; 215 bool has_targethref_; 216 std::vector<UpdateOperationPtr> updateoperation_array_; 217 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(Update); 218 }; 219 220 // <NetworkLinkControl> 221 class NetworkLinkControl : public BasicElement<Type_NetworkLinkControl> { 222 public: 223 virtual ~NetworkLinkControl(); 224 225 // <minRefreshPeriod> get_minrefreshperiod()226 double get_minrefreshperiod() const { return minrefreshperiod_; } has_minrefreshperiod()227 bool has_minrefreshperiod() const { return has_minrefreshperiod_; } set_minrefreshperiod(double value)228 void set_minrefreshperiod(double value) { 229 minrefreshperiod_ = value; 230 has_minrefreshperiod_ = true; 231 } clear_minrefreshperiod()232 void clear_minrefreshperiod() { 233 minrefreshperiod_ = 0.0; 234 has_minrefreshperiod_ = false; 235 } 236 237 // <maxSessionLength> get_maxsessionlength()238 double get_maxsessionlength() const { return maxsessionlength_; } has_maxsessionlength()239 bool has_maxsessionlength() const { return has_maxsessionlength_; } set_maxsessionlength(double value)240 void set_maxsessionlength(double value) { 241 maxsessionlength_ = value; 242 has_maxsessionlength_ = true; 243 } clear_maxsessionlength()244 void clear_maxsessionlength() { 245 maxsessionlength_ = 0.0; 246 has_maxsessionlength_ = false; 247 } 248 249 // <cookie> get_cookie()250 const string& get_cookie() const { return cookie_; } has_cookie()251 bool has_cookie() const { return has_cookie_; } set_cookie(const string & cookie)252 void set_cookie(const string& cookie) { 253 cookie_ = cookie; 254 has_cookie_ = true; 255 } clear_cookie()256 void clear_cookie() { 257 cookie_.clear(); 258 has_cookie_ = false; 259 } 260 261 // <message> get_message()262 const string& get_message() const { return message_; } has_message()263 bool has_message() const { return has_message_; } set_message(const string & message)264 void set_message(const string& message) { 265 message_ = message; 266 has_message_ = true; 267 } clear_message()268 void clear_message() { 269 message_.clear(); 270 has_message_ = false; 271 } 272 273 // <linkName> get_linkname()274 const string& get_linkname() const { return linkname_; } has_linkname()275 bool has_linkname() const { return has_linkname_; } set_linkname(const string & linkname)276 void set_linkname(const string& linkname) { 277 linkname_ = linkname; 278 has_linkname_ = true; 279 } clear_linkname()280 void clear_linkname() { 281 linkname_.clear(); 282 has_linkname_ = false; 283 } 284 285 // <linkDescription> get_linkdescription()286 const string& get_linkdescription() const { return linkdescription_; } has_linkdescription()287 bool has_linkdescription() const { return has_linkdescription_; } set_linkdescription(const string & linkdescription)288 void set_linkdescription(const string& linkdescription) { 289 linkdescription_ = linkdescription; 290 has_linkdescription_ = true; 291 } clear_linkdescription()292 void clear_linkdescription() { 293 linkdescription_.clear(); 294 has_linkdescription_ = false; 295 } 296 297 // <linkSnippet> get_linksnippet()298 const LinkSnippetPtr& get_linksnippet() const { return linksnippet_; } has_linksnippet()299 bool has_linksnippet() const { return linksnippet_ != NULL; } set_linksnippet(LinkSnippetPtr linksnippet)300 void set_linksnippet(LinkSnippetPtr linksnippet) { 301 SetComplexChild(linksnippet, &linksnippet_); 302 } clear_linksnippet()303 void clear_linksnippet() { 304 set_linksnippet(NULL); 305 } 306 307 // <expires> get_expires()308 const string& get_expires() const { return expires_; } has_expires()309 bool has_expires() const { return has_expires_; } set_expires(const string & expires)310 void set_expires(const string& expires) { 311 expires_ = expires; 312 has_expires_ = true; 313 } clear_expires()314 void clear_expires() { 315 expires_.clear(); 316 has_expires_ = false; 317 } 318 319 // <Update> get_update()320 const UpdatePtr& get_update() const { return update_; } has_update()321 bool has_update() const { return update_ != NULL; } set_update(const UpdatePtr & update)322 void set_update(const UpdatePtr& update) { 323 SetComplexChild(update, &update_); 324 } clear_update()325 void clear_update() { 326 set_update(NULL); 327 } 328 329 // AbstractView get_abstractview()330 const AbstractViewPtr& get_abstractview() const { return abstractview_; } has_abstractview()331 bool has_abstractview() const { return abstractview_ != NULL; } set_abstractview(const AbstractViewPtr & abstractview)332 void set_abstractview(const AbstractViewPtr& abstractview) { 333 SetComplexChild(abstractview, &abstractview_); 334 } clear_abstractview()335 void clear_abstractview() { 336 set_abstractview(NULL); 337 } 338 339 // Visitor API methods, see visitor.h. 340 virtual void Accept(Visitor* visitor); 341 virtual void AcceptChildren(VisitorDriver* driver); 342 343 private: 344 friend class KmlFactory; 345 NetworkLinkControl(); 346 friend class KmlHandler; 347 virtual void AddElement(const ElementPtr& element); 348 friend class Serializer; 349 virtual void Serialize(Serializer& serializer) const; 350 double minrefreshperiod_; 351 bool has_minrefreshperiod_; 352 double maxsessionlength_; 353 bool has_maxsessionlength_; 354 string cookie_; 355 bool has_cookie_; 356 string message_; 357 bool has_message_; 358 string linkname_; 359 bool has_linkname_; 360 string linkdescription_; 361 bool has_linkdescription_; 362 LinkSnippetPtr linksnippet_; 363 string expires_; 364 bool has_expires_; 365 UpdatePtr update_; 366 AbstractViewPtr abstractview_; 367 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(NetworkLinkControl); 368 }; 369 370 } // namespace kmldom 371 372 #endif // KML_DOM_NETWORKLINKCONTROL_H__ 373