AAO DRAMA C++ Interface (Old style)
DRAMA C++, Depreciated, don't use for new code
gittpl.h
1/*
2 * Name: filter.m4
3 *
4 * Description:
5 * DOXYGEN Input file filter for DRAMA source files.
6 *
7 * This file must be complatible with both Solaris and GNU m4. All
8 * unused macros are deleted and this comment must end up as a C/C++
9 * compatible comment which is not picked up by DOXYGEN.
10 *
11 * Synopsis:
12 * DCF(func) => Produces a link to a DRAMA C source file func.html
13 * in ../routines.
14 * DDL(link,text) => Produce a link to ../link.html, specified link text.
15 *
16 * Language: m4 macro.
17 *
18 * Author: Tony Farrell, AAO.
19 *
20 * "@(#) $Id$"
21 *
22 * History:
23 * 10-Nov-2004 - TJF - Original Version.
24 */
25
26
27
28#ifndef GITTEMPLSINC
29#define GITTEMPLSINC
30/*
31 * Copyright (c) Anglo-Australian Telescope Board, 1995.
32 * Not to be used for commercial purposes without AATB permission.
33 *
34 * @(#) $Id$
35 *
36 * Template versions of the Git C++ interfaces - within the GitTpl namespace.
37 *
38 * This file now uses DOXYGEN comments to generate the C++ web pages.
39 * m4 macros of the form @htmlonly <a href="../routines/function.html">function()</a>@endhtmlonly are used in the comments
40 * to refer to DRAMA C function documentation (see DramaHtml/Makefile,
41 * DramaHtml/doxygen.config and DramaHtml/filter.m4 for detials)
42 *
43 */
44
45#include "Git.h"
46#include <string>
47#include <limits.h>
48
49namespace GitTpl {
56 public:
65 virtual unsigned int GetMaxValue() const = 0;
76 virtual const char ** GetStringArray() const = 0;
79 virtual ~EnumLookupClass() {}
80};
81
104template <typename LookupClass, typename EnumType> DPUBLICCLASS Enum : public Git {
105 private:
106 EnumType value; // The underlying value and the only memory used by the class.
107 LookupClass lookupObject; // allows us to invoke the methods of this class.
108
109 // Set the value of the object from an int. If out of range, set to
110 // GetMaxValue + 1.
111 void SetValue(const unsigned int i) {
112 if (i > lookupObject.GetMaxValue())
113 value = InvalidValue();
114 else
115 value = (EnumType)i;
116 }
117 EnumType InvalidValue() const {
118 return (EnumType)(lookupObject.GetMaxValue()+1);
119 }
120 protected:
121 public:
128 value = InvalidValue();
129 }
136 Enum(EnumType InitialValue) : value(InitialValue) {}
137
148 Enum(const SdsId& Id,
149 const char * const Name,
150 const int Position,
151 StatusType *status,
152 const char *Default=0,
153 const int Flags = Git::Upper|Git::Abbrev) {
154 value = InvalidValue();
155 Get(Id, Name, Position, status, Default, Flags);
156 }
157
173 void Get(const SdsId& Id,
174 const char * const Name,
175 const int Position,
176 StatusType *status,
177 const char *Default=0,
178 const int Flags = Git::Upper|Git::Abbrev|Git::KeepErr) {
179 char string[100];
180 int index;
181 GitArgGetS((SdsIdType)Id,Name,Position,
182 lookupObject.GetStringArray(),
183 Default,
184 Flags,sizeof(string),string,&index,status);
185 SetValue(index);
186 };
189 operator EnumType() const {
190 return value;
191 }
194 operator const char *() const {
195 return lookupObject.GetStringArray()[int(value)];
196 }
199 virtual ~Enum() {};
200
201};
202
203
204
228template <long int MinVal,
229 long int MaxVal,
230 long int DefaultVal=0> DPUBLICCLASS Real : public GitReal {
231 private:
232 // Return the range we need.
233 virtual const double * Range() {
234 static const double range[] = { MinVal, MaxVal };
235 return range;
236 }
237 public:
238
243 Real(const double def = (double)DefaultVal) : GitReal(def) { }
244
256 Real ( /*Constructor with automatic Get */
257 const SdsId& Id,
258 const char * const Name,
259 const int Position,
260 StatusType * const status,
261 const double Default = (double)DefaultVal,
262 const int Flags = Git::KeepErr) : GitReal(Default) {
263 GitReal::Get(Id,Name,Position,status,Default,Flags);
264 }
265};
266
286template <long int MinVal=LONG_MIN,
287 long int MaxVal=LONG_MAX,
288 long int DefaultVal=0> DPUBLICCLASS Int : public GitInt {
289 private:
290 // Return the range we need.
291 virtual const long int * Range() {
292 static const long int range[] = { MinVal, MaxVal };
293 return range;
294 }
295 public:
296
301 Int(const long def = DefaultVal) : GitInt(def) { }
302
314 Int ( /*Constructor with automatic Get */
315 const SdsId& Id,
316 const char * const Name,
317 const int Position,
318 StatusType * const status,
319 const long Default = DefaultVal,
320 const int Flags = Git::KeepErr) : GitInt(Default) {
321 GitInt::Get(Id,Name,Position,status,Default,Flags);
322 }
323};
324
335class String : public std::string {
336
337 private:
338 static const unsigned DefaultStringLength = 100;
339
340 public:
343 String() : std::string() {}
348 String(const std::string & str) : std::string(str) {}
357 String(const std::string & str, size_type pos, size_type n=std::string::npos) :
358 std::string(str, pos, n) {}
363 String(const char * s) : std::string(s) {}
369 String(const char * s, size_type n) : std::string(s,n) {}
372 String(size_type n, char c) : std::string(n,c) {}
378 template<class InputIterator>
379 String(InputIterator beg, InputIterator end) : std::string(beg,end){}
380
392 String( const SdsId& Id,
393 const char * const Name,
394 const int Position,
395 StatusType * const status,
396 const char * Default = 0,
397 const int Flags = Git::KeepErr) {
398 this->Get(Id, Name, Position, status, Default, Flags);
399 }
400
401
406 String& operator=(const std::string &str) {
407 this->std::string::operator=(str);
408 return *this;
409 }
414 String& operator=(const String &str) {
415 this->std::string::operator=(std::string(str));
416 return *this;
417 }
423 String& operator=(const char *s) {
424 this->std::string::operator=(s);
425 return *this;
426 }
434 String& operator=(char c) {
435 this->std::string::operator=(c);
436 return *this;
437 }
449 /*
450 * source of this function is in gitcpp.C.
451 */
452 void Get (const SdsId& Id,
453 const char * const Name,
454 const int Position,
455 StatusType * const status,
456 const char * Default = 0,
457 const int Flags = Git::KeepErr);
458}; /* String */
459
460
461} /* namespace Git */
462#endif /* define GITNEWINC */
virtual void Get(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const long int Default=0, const int Flags=0)
Get the value of the object from an SDS struture.
Definition Git.h:756
A class which reads integer values from an SDS argument structure.
Definition Git.h:685
virtual void Get(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const double Default=0.0, const int Flags=0)
Get the value of the object from an SDS struture.
Definition Git.h:645
A class which reads real values from an SDS argument structure.
Definition Git.h:573
virtual unsigned int GetMaxValue() const =0
This function should return the maximum normal value of the enumerated value.
virtual const char ** GetStringArray() const =0
Return a pointer to an array of enum strings equivalents.
virtual ~EnumLookupClass()
Destructor.
Definition gittpl.h:79
A virtual base class for the lookup class template arguments to GitTpl::Enum.
Definition gittpl.h:55
Enum(const SdsId &Id, const char *const Name, const int Position, StatusType *status, const char *Default=0, const int Flags=Git::Upper|Git::Abbrev)
Constructor which contructs the values from an SDS type.
Definition gittpl.h:148
virtual ~Enum()
Destructor.
Definition gittpl.h:199
Enum(EnumType InitialValue)
Constructor with initial value supplied.
Definition gittpl.h:136
Enum()
Default contructor for the object.
Definition gittpl.h:127
void Get(const SdsId &Id, const char *const Name, const int Position, StatusType *status, const char *Default=0, const int Flags=Git::Upper|Git::Abbrev|Git::KeepErr)
Get the value of the object from an SDS struture.
Definition gittpl.h:173
A class which reads Enumerated values from a SDS argument structures.
Definition gittpl.h:104
Int(const long def=DefaultVal)
Simple constructor with a default value specified.
Definition gittpl.h:301
Int(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const long Default=DefaultVal, const int Flags=Git::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gittpl.h:314
A class which reads integer values from an SDS argument structure.
Definition gittpl.h:288
Real(const double def=(double) DefaultVal)
Simple constructor with a default value specified.
Definition gittpl.h:243
Real(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const double Default=(double) DefaultVal, const int Flags=Git::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gittpl.h:256
A class which reads real values from an SDS argument structure.
Definition gittpl.h:230
String & operator=(const char *s)
Copy contents of s into this string.
Definition gittpl.h:423
String(const std::string &str)
Create a Git::String from a std::string.
Definition gittpl.h:348
String(const char *s)
Create a Git::String from a C character array.
Definition gittpl.h:363
String(InputIterator beg, InputIterator end)
Create a Git::String that is initialised by all characters from beg to end.
Definition gittpl.h:379
String & operator=(char c)
Set value to string of length 1.
Definition gittpl.h:434
String(const char *s, size_type n)
Create a Git::String from the first n characters a C string.
Definition gittpl.h:369
void Get(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const char *Default=0, const int Flags=Git::KeepErr)
Fetch the value of this item from an SDS structure.
String(const SdsId &Id, const char *const Name, const int Position, StatusType *const status, const char *Default=0, const int Flags=Git::KeepErr)
Constructor with the initial value set from an SDS structure.
Definition gittpl.h:392
String & operator=(const std::string &str)
Assign str to this string.
Definition gittpl.h:406
String(size_type n, char c)
Create a Git::String intialised with n occurances of c.
Definition gittpl.h:372
String & operator=(const String &str)
Assign str to this string.
Definition gittpl.h:414
String()
Create an empty Git::String.
Definition gittpl.h:343
String(const std::string &str, size_type pos, size_type n=std::string::npos)
Create a Git::String from a std::string, initialised from s starting at index pos,...
Definition gittpl.h:357
A class which reads a a string item from an SDS structure.
Definition gittpl.h:335
@ Abbrev
Allow abbreviations
Definition Git.h:352
@ KeepErr
Keep error status on return
Definition Git.h:351
@ Upper
Convert strings to upper case.
Definition Git.h:349
The GitArgGet flags set up appropriately for C++.
Definition Git.h:346
A C++ Interface to the handling SDS structures.
Definition sds.h:761