This example_cpp page provides an example of compiling and linking C++ application against librnr.
configuration databases.
#include <iostream>
#include <string>
#include <libgen.h>
{
"Example of C++ using librnr grab bag of goodies.",
"The %P command demonstrates compiling-linking C++ with librnr facilities.",
NULL
};
{
{
"test",
't',
required_argument,
true,
"<test>",
"Set the logging test(s) to conduct.\n"
"%A is one of:\n"
" 0 - No tests.\n"
" 1 - Test #1.\n"
" 2 - Test #2.\n"
" 3 - All tests."
},
};
static void logtest_num1(
void *p,
const char *sFruit,
int n,
int half,
double f,
int hex,
bool_t bAreRipe)
{
if( bAreRipe )
{
LOGDIAG2(
"There are %d juicy %s in %s", n, sFruit,
"Tuscany");
}
else
{
LOGDIAG2(
"There are %d green %s in %s", n, sFruit,
"Utah");
}
}
{
FILE *fp;
const char *sFileName = "PackingShedOnStrike.newsflash";
while( count-- > 0 )
{
LOGERROR(
"Salmonella scare %d...", count);
}
if( (fp = fopen(sFileName, "r")) == NULL )
{
}
else
{
LOGDIAG4(
"%s: what a pleasant surprise", sFileName);
fclose(fp);
}
}
{
short h = 10;
int i = 12;
switch( OptsTest )
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
LOGERROR(
"bug: %d: unexpected test", OptsTest);
return 0;
}
return 1;
}
enum BodyId_T
{
unknown,
Sun,
Mercury,
Venus,
Earth, Moon,
Mars, Phobos, Deimos,
Ceres,
Jupiter, Io, Europa, Ganymede, Callisto,
Saturn, Titan,
Uranus, Titania,
Neptune, Triton,
Pluto, Charon,
Eris,
NumBodies
};
{
{"unknown", unknown},
{"Sun", Sun},
{"Mercury", Mercury},
{"Venus", Venus},
{"Earth", Earth},
{"Moon", Moon},
{"Mars", Mars},
{"Phobos", Phobos},
{"Deimos", Deimos},
{"Jupiter", Jupiter},
{"Io", Io},
{"Europa", Europa},
{"Ganymede", Ganymede},
{"Callisto", Callisto},
{"Saturn", Saturn},
{"Titan", Titan},
{"Uranus", Uranus},
{"Titania", Titania},
{"Neptune", Neptune},
{"Triton", Triton},
{"Ceres", Ceres},
{"Pluto", Pluto},
{"Charon", Charon}
};
{
cout << oid << " --> "
<< endl;
}
{
cout << name << " --> "
<< endl;
}
{
byte_t buf[] =
"\x04\xf3 apple\t\n\va day.";
cout << endl;
}
{
string path[] = {".", "./examples", "/prj/pkg/librnr/examples"};
string filepath;
int i;
for(i=0; (i<
arraysize(path)) && (ini == NULL); ++i)
{
filepath = path[i] + "/" + inifile;
}
if( ini != NULL )
{
}
}
{
DListStr_T *dlist;
DListStrIter_T iter;
char *s;
DListStrAppend(dlist, (char *)"elephant");
DListStrAppend(dlist, (char *)"rhinocerus");
DListStrPrepend(dlist, (char *)"hippopotomous");
cout << "count = " << DListStrCount(dlist) << endl;
for(s=DListStrIterDataFirst(dlist, &iter);
s=DListStrIterDataNext(&iter))
{
cout << s << endl;
}
}
{
{"mt_elbert", "14,433"},
{"mt_massive", "14,421"},
{"mt_harvard", "14,420"},
{"blanca_peak", "14,345"},
{"la_plata_peak", "14,336"},
{"uncompahgre_peak", "14,309"},
{"crestone_peak", "14,294"},
{"mt_lincoln", "14,286"},
{"grays_peak", "14,270"},
{"mt_antero", "14,269"},
{"torreys_peak", "14,267"},
{"castle_peak", "14,265"},
{"quandary_peak", "14,265"},
{"mt_evans", "14,264"},
{"longs_peak", "14,255"},
{"mt_wilson", "14,246"}
};
{
delete((char *)key);
delete((char *)val);
}
{
true,
NULL,
NULL,
char *key, *val;
for(
size_t i=0; i<
arraysize(Colorado14ers); ++i)
{
}
{
}
}
static int init(
int argc,
char *argv[])
{
FILE *fp;
int i;
Argv0 = basename(argv[0]);
argv =
OptsGet(Argv0, &
PkgInfo, &LogExamplePgmInfo, LogExampleOptsInfo,
true,
&argc, argv);
CHKEXPR_INT(OptsTest, ((OptsTest >= 0) || (OptsTest <= 3)), 0);
{
LOGDIAG1(
"Post options processed non-option arguments:");
for(i=0; i<argc; ++i)
{
fprintf(fp, " argv[%d]=\"%s\"\n", i, argv[i]);
}
}
return 1;
}
int main(
int argc,
char *argv[])
{
cout << "Testing librnr Linkage" << endl
<< "----------------------" << endl;
cout << "* Validate options and logging." << endl;
{
return 3;
}
cout << "* Validate associative mapping." << endl;
cout << endl;
cout << "* Validate char." << endl;
cout << endl;
cout << "* Validate config (ini)." << endl;
cout << endl;
cout << "* Validate string dlist." << endl;
cout << endl;
cout << "* Validate hash and new." << endl;
cout << endl;
return 0;
}