Open Source X9.37 To Text: Example2

In C++ we often use "pimpl" (pointer to implementation), and this helps hide details from the rest of the application.  Someone called it the "Cheshire Cat" algorithm.  (The cheshire cat in "Alice in Wonderland" is hiding something.).

Well, "pimpl" helps put things in libraries, and/or makes pieces of the code easier to replace. It basically is a new class which has a pointer to the class that does the work, and details can easily reside in only one lib.

Nothing is free in C++. There is a trivial bit of complexity added to make things clearer (how ironic), so, the first example did not have the pimpl-s. However, if we continue to require knowledge of every support aspect of every class, then the applications get beastly and honestly start reminding me of old assembler code where you had to know the entire application to read any piece of code.

Aside: Why did I use pimpl for reading an X9? One compiler is used for the fastest disk money can buy. This "disk" is honestly a computer that sits in a rack. If your code uses C++ io, then you incur a 20% penality (locale and buffering on buffering are expenses which add up when the speed of IO approaches zero). However, I also use the same code in Windows and therefore the cheapest terabyte disk money can buy (I paid $100). The Microsoft compiler also starts complaining if I use the "deprecated" functions. So, the two are conflicting.   If this was visible in the header, then I'd be drowing in these warnings.  I dont like to see warnings, they waste my time, nor can I turn these warnings off (msvc 6.0).  So, pimpl resolves the conflicts and I see the warnings only once. (And there is also a 16 byte memory leak in the compilers c++ locale code, I sugguested a different compiler, but was reminded the compiler company was the indirect employer! lol. So, I kept flipping between open, fopen, and c++ streams.  Any memory leak is unacceptable in daemon code, so, this needed open or fopen, while this is not C++ best practice.).


Example1 was designed to use a minimum files, and minimum classes but did not hide anything. Example2 invokes the pimpl method of info hiding, uses a namspace, shows account number (annex A) and also adds a function for copying a substring from an x9 buffer.


Source Code for X937-2-text, Example 2. Description.
GetDefinitions.cpp Contains "function" to return the list of field definitions given x9 data.
x9.cpp This is the application class, and the implementation.
x9Read.cpp This is the pimpl class and the impl class.
Conversions.hpp Convert from EBCDIC to ASCII and back, inlined for efficiency.
x9buffer.hpp In theory this is like std::string, however, for x9 data and their unique issues.
Example.cpp contains main() and little else.


The output of example2 against the sample one item x9.37, x9.100 file.






Valid XHTML 1.0 Transitional