#include "xmlBase/IFile.h"
#include <iostream>
#include <string>
Go to the source code of this file.
◆ lookFor()
| void lookFor |
( |
xmlBase::IFile * | ifile, |
|
|
const char * | section, |
|
|
const char * | item ) |
Test program for IFile facility within xmlBase package.
Definition at line 58 of file test_IFile.cxx.
58 {
59 bool haveItem = ifile->
contains( section, item );
60 std::cout << "Item " << item << " in section " << section;
61
62 if ( haveItem )
63 {
64 std::cout << " was found." << std::endl;
65
66 const char* charRep = ifile->
getString( section, item );
67 std::cout << "..as a string = " << charRep << std::endl;
68
69 try
70 {
71 int intRep = ifile->
getInt( section, item );
72 std::cout << "..as an int = " << intRep << std::endl;
74 { std::cout << "**ERROR** int conversion failed " << std::endl << std::endl; }
75
76 try
77 {
78 double doubleRep = ifile->
getDouble( section, item );
79 std::cout << "..as a double = " << doubleRep << std::endl;
81 { std::cout << " **ERROR** double conversion failed " << std::endl << std::endl; }
82 }
83 else std::cout << " was NOT found." << std::endl;
84}
virtual int getInt(const char *section, const char *item)
virtual bool contains(const char *section, const char *item)
virtual const char * getString(const char *section, const char *item)
virtual double getDouble(const char *section, const char *item)
Referenced by main().
◆ main()
Definition at line 10 of file test_IFile.cxx.
10 {
11
12 std::string filename( "$(XMLBASEROOT)/xml/myIFile.xml" );
14
16
17
18 if ( ifile )
19 {
20
21 lookFor( ifile,
"section1",
"section1-val1" );
22 lookFor( ifile,
"section1",
"section1-val2" );
23 lookFor( ifile,
"subsection",
"subsectionItem" );
24 lookFor( ifile,
"section2",
"subsectionItem" );
25 lookFor( ifile,
"section2",
"bad-int" );
26 }
27 else std::cout << "Unable to read file " << ifile << std::endl;
28
29
30 std::string filename2( "$(XMLBASEROOT)/xml/mySchemaIFile.xml" );
31
32 std::cout << std::endl << std::endl;
33 std::cout << "And for my next trick: process an IFile using XML Schema.";
34 std::cout << std::endl;
35 std::cout << "This file should be flagged bad; it doesn't follow schema content model."
36 << std::endl
37 << std::endl;
38
40
42
43
44 if ( ifile2 )
45 {
46
47 lookFor( ifile2,
"section1",
"section1-val1" );
48 lookFor( ifile2,
"section1",
"section1-val2" );
49 lookFor( ifile2,
"subsection",
"subsectionItem" );
50 lookFor( ifile2,
"section2",
"subsectionItem" );
51 lookFor( ifile2,
"section2",
"bad-int" );
52 }
53 else std::cout << "Unable to read file " << ifile2 << std::endl;
54
55 return ( 0 );
56}
void lookFor(xmlBase::IFile *ifile, const char *section, const char *item)
Test program for IFile facility within xmlBase package.