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 program shows basic ProcessUpdate() with <Change>.
27 
28 #include <iostream>
29 #include "kml/convenience/convenience.h"
30 #include "kml/dom.h"
31 #include "kml/engine.h"
32 
33 using kmldom::ChangePtr;
34 using kmldom::FolderPtr;
35 using kmldom::KmlFactory;
36 using kmldom::KmlPtr;
37 using kmldom::PlacemarkPtr;
38 using kmldom::UpdatePtr;
39 using kmlengine::KmlFile;
40 using kmlengine::KmlFilePtr;
41 
HelloUpdateChange()42 static void HelloUpdateChange() {
43   // This is the same KML as in the kmlfile.cc example.
44   KmlFactory* kml_factory = KmlFactory::GetFactory();
45   FolderPtr folder = kml_factory->CreateFolder();
46   folder->set_id("f0");
47   folder->set_name("Folder 0");
48   PlacemarkPtr placemark = kml_factory->CreatePlacemark();
49   placemark->set_id("pm0");
50   placemark->set_name("Placemark 0");
51   folder->add_feature(placemark);
52   placemark = kml_factory->CreatePlacemark();
53   placemark->set_id("pm1");
54   placemark->set_name("Placemark 1");
55   folder->add_feature(placemark);
56   KmlPtr kml = kml_factory->CreateKml();
57   kml->set_feature(folder);
58 
59   // Importing to a KmlFile creates an internal database of object id mappings.
60   KmlFilePtr kml_file = KmlFile::CreateFromImport(kml);
61 
62   ChangePtr change = kml_factory->CreateChange();
63   placemark = kmlconvenience::CreatePointPlacemark("new name", 38, -120);
64   placemark->set_targetid("pm0");
65   change->add_object(placemark);
66   UpdatePtr update = kml_factory->CreateUpdate();
67   update->add_updateoperation(change);
68 
69   kmlengine::ProcessUpdate(update, kml_file);
70 
71   std::string xml;
72   kml_file->SerializeToString(&xml);
73   std::cout << xml;
74 }
75 
main(int argc,char ** argv)76 int main(int argc, char** argv) {
77   HelloUpdateChange();
78   return 0;
79 }
80