KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
autolayer.h
Go to the documentation of this file.
1 
6 /*
7  * $Id: autolayer.h 17606 2014-09-26 01:09:51Z predoehl $
8  */
9 
10 #ifndef AUTOLAYER_H_UOFARIZONAVISION
11 #define AUTOLAYER_H_UOFARIZONAVISION
12 
13 #include <l_cpp/l_util.h>
14 #include <l_cpp/l_exception.h>
15 #include <topo_cpp/layer.h>
16 #include <topo_cpp/xml.h>
17 
18 #include <string>
19 
20 namespace kjb
21 {
22 namespace TopoFusion
23 {
24 
26 class AutoLayer
27 {
28  layer my_layer;
29 
31  int set_name( const std::string& name )
32  {
33  if ( name.size() >= LAYER_FN_SIZE )
34  {
35  return kjb_c::ERROR;
36  }
37  strcpy( my_layer.filename, name.c_str() );
38  return kjb_c::NO_ERROR;
39  }
40 
41  void set_numTracks( int );
42 
43  AutoLayer( const AutoLayer& );
44 
45 public:
48  {
49  initLayer( &my_layer );
50  }
51 
53  AutoLayer( const std::string& filename )
54  {
55  initLayer( &my_layer );
56  KJB( ETX( readTrack_GPX( filename, &my_layer ) ) );
57  }
58 
59 
60  pt* set_track0points( unsigned, const pt* src=00 );
61 
62 
63  void add_waypoint( const pt&, const char*, int );
64 
65 
67  operator const layer& () const
68  {
69  return my_layer;
70  }
71 
74  {
75  return &my_layer;
76  }
77 
79  int write( const std::string& filename )
80  {
81  KJB( ETX( set_name( filename ) ) );
82  KJB( ETX( writeTrack_GPX( filename, my_layer ) ) );
83  return kjb_c::NO_ERROR;
84  }
85 
88  {
89  destroyLayer( &my_layer );
90  }
91 };
92 
93 }
94 } // end namespace kjb
95 
96 
97 #endif /* autolayer.h */
#define ETX(a)
Definition: l_exception.h:67
Contains definitions of basic TopoFusion data structures.
int write(const std::string &filename)
Write a layer into a file.
Definition: autolayer.h:79
const size_t LAYER_FN_SIZE
max length of a layer's filename field
Definition: layer.h:30
pt * set_track0points(unsigned, const pt *src=00)
define the first track in a layer.
Definition: autolayer.cpp:71
int readTrack_GPX(const std::string &filename, layer *l)
read a track from a named file into the pointed-to layer
Definition: xml.cpp:1039
#define KJB(x)
Definition: l_util.h:9
int writeTrack_GPX(const std::string &filename, const layer &l)
write a track (stored in the indicated layer) into a named file
Definition: xml.cpp:1103
char filename[LAYER_FN_SIZE]
each layer is associated with a file
Definition: layer.h:87
void initLayer(layer *l)
clear all the fields of a layer (pointers assumed to be dangling)
Definition: layer.cpp:89
RAII approach to the old TopoFusion Layer data structure.
Definition: autolayer.h:26
AutoLayer(const std::string &filename)
ctor loads a layer from a named file
Definition: autolayer.h:53
layer * get_writable_ptr()
This is a "dangerous" method that lets you manipulate the Layer.
Definition: autolayer.h:73
~AutoLayer()
Dtor makes sure the layer resources are released.
Definition: autolayer.h:87
void destroyLayer(layer *l)
release memory in the layer's tracks and waypoints arrays
Definition: layer.cpp:105
XML processing prototypes.
definition used for layer
Definition: layer.h:82
AutoLayer()
default ctor makes a Layer ready for writing
Definition: autolayer.h:47
Support for error handling exception classes in libKJB.
void add_waypoint(const pt &, const char *, int)
A layer can hold a list of waypoints; this adds one to the list.
Definition: autolayer.cpp:117
definition for a TopoFusion pt
Definition: layer.h:34