GeoTessCPPExamples  2.0
ExtendedModel.cc
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- retains certain rights in this software.
6 //-
7 //- BSD Open Source License.
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35 
36 #include "CPPUtils.h"
37 #include "GeoTessModelExtended.h"
38 
39 using namespace geotess;
40 
41 /**
42  * An example of how to implement an extension of a GeoTessModel.
43  * The definition of the extended model is contained in files
44  * GeoTessModelExtended.h and .cc. This method instantiates
45  * an instance of the model and queries it for the extra data.
46  * <p>
47  * The program takes one command line argument which specifies the
48  * full path to the file GeoTessModels/crust20.geotess
49  * that was delivered with the GeoTess package.
50  */
51 int main(int argc, char** argv)
52 {
53  try
54  {
55  string path;
56  if(argc < 2)
57  {
58  cout << "Must supply a single command line argument specifying path to the GeoTessModels directory" << endl;
59  return -1;
60  }
61 
62  path = CPPUtils::insertPathSeparator(argv[1], "crust20.geotess");
63 
64  // load a regular GeoTessModel. This is not the extended model.
65  GeoTessModel* baseModel = new GeoTessModel(path);
66 
67  // construct an instance of a GeoTessModelExtended that
68  // has MetaData, Grid and Profile information copied from
69  // the base class. The extra data accessible only from the
70  // derived class is initialized in the constructor to "default value".
71  GeoTessModelExtended extModel(baseModel);
72 
73  // all information has been copied from baseModel to extendedModel
74  // so baseModel can be deleted.
75  delete baseModel;
76 
77  // in this trivial example, the extended model implements a single
78  // string called 'extraData'. It is initialized to 'default value'
79  // in the GeoTessModelExtended constructor. A getter() and setter()
80  // are implemented to allow applications to retrieve and modify the
81  // value. Likely, real classes that extend GeoTessModel
82  // would involve more complicated structures.
83 
84  // print the extraData to the screen. This is the default value
85  // assigned by the GeoTessModelExtended constructor.
86  cout << extModel.getExtraData() << endl;
87 
88  // change the extraData to a new string.
89  extModel.setExtraData("modified value");
90 
91  // retrieve the modified value of extraData.
92  cout << extModel.getExtraData() << endl;
93 
94  cout << "done." << endl;
95 
96  }
97  catch (GeoTessException& ex)
98  {
99  cout << ex.emessage << endl;
100  return 1;
101  }
102  catch(...)
103  {
104  cout << endl << "Unidentified error detected " << endl
105  << __FILE__ << " " << __LINE__ << endl;
106  return 2;
107  }
108 
109  return 0;
110 }
geotess
Definition: AK135Model.h:55
GeoTessModelExtended.h
geotess::GeoTessModelExtended
Definition: GeoTessModelExtended.h:104
geotess::GeoTessModelExtended::getExtraData
string getExtraData()
Definition: GeoTessModelExtended.cc:344
main
int main(int argc, char **argv)
Definition: ExtendedModel.cc:51
geotess::GeoTessModelExtended::setExtraData
void setExtraData(const string &xData)
Definition: GeoTessModelExtended.cc:350