E57 Foundation API v1.1.312  Aug. 10, 2011
Functions
examples/NameParse.cpp File Reference

example: parse good and bad element names More...

Include dependency graph for NameParse.cpp:

Functions

void tryParse (ImageFile imf, ustring pathName)
 Try various parsing functions on an element name.
int main (int, char **)
 Example use of element name parsing functions.

Detailed Description

example: parse good and bad element names

Also see listing at end of this page for source without line numbers (to cut&paste from).

00001 /*** NameParse.cpp example: parse good and bad element names */
00004 #include <iostream>
00005 #include "E57Foundation.h"
00006 using namespace e57;
00007 using namespace std;
00008 
00010 void tryParse(ImageFile imf, ustring pathName) {
00011     cout << "pathName=" << pathName << endl;
00012 
00013     try {
00014         ustring prefix, localPart;
00015         imf.elementNameParse(pathName, prefix, localPart);
00016         cout << "  prefix=\"" << prefix << "\" localPart=\"" << localPart << "\"" << endl;
00017     } catch(E57Exception& ex) {
00018         if (ex.errorCode() == E57_ERROR_BAD_PATH_NAME)
00019             cout << "  Is not legal element name" << endl;
00020     }
00021 
00022     if (imf.isElementNameExtended(pathName))
00023         cout << "  Is extended element name" << endl;
00024     else
00025         cout << "  Is not extended element name" << endl;
00026 }
00027 
00029 int main(int /*argc*/, char** /*argv*/) {
00030     try {
00031         ImageFile imf("temp._e57", "w");
00032 
00033         tryParse(imf, "bar");
00034         tryParse(imf, "foo:bar");
00035 
00036         imf.close(); // don't forget to explicitly close the ImageFile
00037     } catch(E57Exception& ex) {
00038         ex.report(__FILE__, __LINE__, __FUNCTION__);
00039         return(-1);
00040     }
00041     return(0);
00042 }

This example program illustrates the element parsing functions of ImageFile. See the HelloWorld.cpp example for discussion of the use of include files, constructing an ImageFile, and the try/catch block to handle exceptions.

A write-mode ImageFile is created in source line 31. A test function is called with two example element names in source lines 33-34. The parsing functions don't actually check to see if there are objects defined with the given path names or element names, they just test whether they are syntactically correct. The ImageFile::isElementNameExtended functions only checks to see if a prefix is used, and not if it is declared in the ImageFile.

The output lines 2-3 show that "bar" can be parsed and it is not extended. The output lines 5-6 show that "foo:bar" can be parsed and it is extended.

The following console output is produced:

The XML section of the temp._e57 E57 file produced by this example program is as follows:

Here is the source code without line numbers to cut&paste from:

/*** NameParse.cpp example: parse good and bad element names */
#include <iostream>
#include "E57Foundation.h"
using namespace e57;
using namespace std;

void tryParse(ImageFile imf, ustring pathName) {
    cout << "pathName=" << pathName << endl;

    try {
        ustring prefix, localPart;
        imf.elementNameParse(pathName, prefix, localPart);
        cout << "  prefix=\"" << prefix << "\" localPart=\"" << localPart << "\"" << endl;
    } catch(E57Exception& ex) {
        if (ex.errorCode() == E57_ERROR_BAD_PATH_NAME)
            cout << "  Is not legal element name" << endl;
    }

    if (imf.isElementNameExtended(pathName))
        cout << "  Is extended element name" << endl;
    else
        cout << "  Is not extended element name" << endl;
}

int main(int /*argc*/, char** /*argv*/) {
    try {
        ImageFile imf("temp._e57", "w");

        tryParse(imf, "bar");
        tryParse(imf, "foo:bar");

        imf.close(); // don't forget to explicitly close the ImageFile
    } catch(E57Exception& ex) {
        ex.report(__FILE__, __LINE__, __FUNCTION__);
        return(-1);
    }
    return(0);
}
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines