BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
test_IFile.cxx File Reference
#include "xmlBase/IFile.h"
#include <string>
#include <iostream>

Go to the source code of this file.

Functions

void lookFor (xmlBase::IFile *ifile, const char *section, const char *item)
 Test program for IFile facility within xmlBase package.
 
int main ()
 

Function Documentation

◆ 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 std::cout << " was found." << std::endl;
64 // try writing in various formats
65 const char* charRep = ifile->getString(section, item);
66 std::cout << "..as a string = " << charRep << std::endl;
67
68 try {
69 int intRep = ifile->getInt(section, item);
70 std::cout << "..as an int = " << intRep << std::endl;
71 }
72 catch (xmlBase::IFileException toCatch) {
73 std::cout << "**ERROR** int conversion failed "
74 << std::endl << std::endl;
75 }
76
77 try {
78 double doubleRep = ifile->getDouble(section, item);
79 std::cout << "..as a double = " << doubleRep << std::endl;
80 }
81 catch (xmlBase::IFileException toCatch) {
82 std::cout << " **ERROR** double conversion failed "
83 << std::endl << std::endl;
84 }
85
86 }
87 else std::cout << " was NOT found." << std::endl;
88}
virtual int getInt(const char *section, const char *item)
Definition: IFile.cxx:334
virtual bool contains(const char *section, const char *item)
Definition: IFile.cxx:231
virtual const char * getString(const char *section, const char *item)
Definition: IFile.cxx:286
virtual double getDouble(const char *section, const char *item)
Definition: IFile.cxx:316

Referenced by main().

◆ main()

int main ( )

Definition at line 11 of file test_IFile.cxx.

11 {
12
13 std::string filename("$(XMLBASEROOT)/xml/myIFile.xml");
14 xmlBase::IFile* ifile = 0;
15
16 ifile = new xmlBase::IFile(filename.c_str());
17 // fetch some stuff
18
19 if (ifile) {
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 // Now do it again for IFile referencing schema rather than dtd
31 std::string filename2("$(XMLBASEROOT)/xml/mySchemaIFile.xml");
32
33 std::cout << std::endl << std::endl;
34 std::cout << "And for my next trick: process an IFile using XML Schema.";
35 std::cout << std::endl;
36 std::cout <<
37 "This file should be flagged bad; it doesn't follow schema content model."
38 << std::endl << std::endl;
39
40 xmlBase::IFile* ifile2 = 0;
41
42 ifile2 = new xmlBase::IFile(filename2.c_str());
43 // fetch some stuff
44
45 if (ifile2) {
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.
Definition: test_IFile.cxx:58

Referenced by ClassImp(), and THelixFitter::fit().