AAO DRAMA/DRAMA2 C++ Interface
argtest.cpp
/*
* Program name:
argtest.cpp
* Function:
A program to test the drama::sds "Arg" interfaces
* Description:
Tests the various methods of drama::sds used to constructor and access
traditional DRAMA command line arguments - such as supported by the
C level "Arg" series of methods.
* Methods not yet tested.
* Language:
C++
* Support: Tony Farrell, AAO
* History:
29-Feb-2014 - TJF - Original version
* Copyright (c) Anglo-Australian Telescope Board, 2005
Not to be used for commercial purposes without AATB permission.
* @(#) $Id: ACMM:Drama2/examples/argtest.cpp,v 1.45+ 22-Feb-2016 14:09:53+11 tjf $
*/
static const char *rcsId="@(#) $Id: ACMM:Drama2/examples/argtest.cpp,v 1.45+ 22-Feb-2016 14:09:53+11 tjf $";
static void *use_rcsId = (0 ? (void *)(&use_rcsId) : (void *) &rcsId);
#include "drama/util.hh"
#include "drama/sds.hh"
#include "drama.h"
#include "mess.h"
#include "sds_err_msgt.h"
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <unistd.h>
static void Construct(drama::sds::Id *topLevel);
static void Examine(drama::sds::Id &topLevel);
int main(int , const char *[])
{
/*
* Allow us to translate error codes
*/
MessPutFacility(&MessFac_SDS);
try
{
drama::sds::Id topLevel;
/*
* Construct a structure and write it out to a file.
*/
Construct(&topLevel);
fprintf(stderr,"Converted to string = \"%s\"\n",
topLevel.toString().c_str());
topLevel.Write("argtest.sds");
topLevel.List();
/*
* Read the structure back in and examine it.
*/
drama::sds::Id topLevel2(drama::sds::Id::FromFile("argtest.sds"));
Examine(topLevel);
Examine(topLevel2);
topLevel2 = topLevel.Copy();
}
catch (drama::Exception &e)
{
e.Print();
return 1;
}
/*
* Get rid of the file.
*/
unlink("argtest.sds");
return 0;
}
static void Construct(drama::sds::Id *topLevel)
{
/*
* Create a top level structure.
*/
/*
* Put a bunch of items (covering each "Put()" method).
*/
topLevel->Put("BoolItem", true);
topLevel->Put("SimpleIntItem", 2);
topLevel->Put("CharItem", (char)(3));
topLevel->Put("ShortItem", (short)(4));
topLevel->Put("UShortItem", (unsigned short)(5));
topLevel->Put("INT32Item", (INT32)(6));
topLevel->Put("UINT32Item", (UINT32)(7));
topLevel->Put("INT64Item", (INT64)(8));
topLevel->Put("UINT64Item", (UINT64)(9));
topLevel->Put("FloatItem", (float)(10));
topLevel->Put("DoubleItem", (double)(11));
topLevel->Put("StringItem1", "12");
std::string test13("13");
topLevel->Put("StringItem2", test13);
}
/*
* This template method will fetch an item from the SDS structure
* and compare it to an expected value, throwing an exception if
* the value it not correct.
*
* The template parameter (executeValue parameter type) should be
* one of the standard SDS types.
*/
template <typename T>
void CheckItem(
const std::string &name,
T expectedValue)
{
T actualValue;
top.Get(name, &actualValue);
if (actualValue != expectedValue)
{
std::cerr << "Failed to fetch correct value from item \""
<< name
<< "\""
<< std::endl
<< " Expected \""
<< expectedValue
<< "\" Got \""
<< actualValue
<< "\""
<< std::endl;
DramaTHROW(SDS__TESTERR, "Test error");
return;
}
}
static void Examine(drama::sds::Id &topLevel)
{
/*
* Check each of the expected values in the structure.
*/
CheckItem(topLevel, "BoolItem", true);
CheckItem(topLevel, "SimpleIntItem", 2);
CheckItem(topLevel, "CharItem", (char)(3));
CheckItem(topLevel, "ShortItem", (short)(4));
CheckItem(topLevel, "UShortItem", (unsigned short)(5));
CheckItem(topLevel, "INT32Item", (INT32)(6));
CheckItem(topLevel, "UINT32Item", (UINT32)(7));
CheckItem(topLevel, "INT64Item", (INT64)(8));
CheckItem(topLevel, "UINT64Item", (UINT64)(9));
CheckItem(topLevel, "FloatItem", (float)(10));
CheckItem(topLevel, "DoubleItem", (double)(11));
CheckItem(topLevel, "StringItem1", std::string("12"));
CheckItem(topLevel, "StringItem2", std::string("13"));
}

Click here for the DRAMA home page and here for the AAO home page.

For more information, contact tjf@aao.gov.au 

Generated on Mon Feb 22 2016 15:57:52 for AAO DRAMA/DRAMA2 C++ Interface by doxygen 1.8.10