| ||||||||
firstobject Access LanguageThe firstobject access language "FOAL" based on C++ syntax is specialized for retrieving and reporting information in markup text documents. It also introduces an efficient and versatile way of doing lists and structures using markup. Built around the CMarkup API, it opens up new potential for rapid development of high performance processing and transformation of XML and other markup documents. UnitA document or file is a "unit" that contains functions. If there are multiple functions, the unit will often have a primary function for the sake of running it conveniently. You can name the primary function Differences from C++FOAL is based on C++ syntax, just like Java is. This is not to be confused with being C++. FOAL supports a small subset of C++ syntax and capabilities as well as some of its own unique flavors. The C++ syntax was chosen to be compatible with the examples already supplied in the firstobject documentation. The main differences from C++ are the fundamental types FOAL has no pointers. Functions can be declared to accept arguments "by reference" meaning that operations on the variable inside the function will affect the variable that was passed in. Plus FOAL allows default values for reference arguments, unlike C++. Also, for a function that does not return a value, the FOAL currently only supports TypesFOAL has the following types: int a 32-bit integerbool a boolean value, false=0, true=1num a precision decimal numberstr a Unicode stringCMarkup a markup documentFOAL provides automatic conversion between types for assignments and passing to arguments as follows:
When going between numbers and strings, a period is always used to represent the decimal point "separator". This ensures that programs work the same way regardless of locale. It is also good practice to standardize on a period in XML documents that may pass between locales, and just use the implicit conversion that expects periods. When dealing with locale dependent display or data entry, use the StringsMost examples in the CMarkup documentation can be run in the firstobject access language, with only minor changes relating to the string type. Since CMarkup is developed primarily to work with both MFC ( The NumbersAn The Because 9.50 + .5 = 10.00 9.50 - 9.5 = 0.00 With division and multiplication, the number of decimal places may grow if required to up to the maximum precision supported by the type. With multiplication it will never be more than the total of the decimal places in the operands. With division it can often go to the limits of precision and you should probably round the result to the desired precision. 9.50 * 2.0 = 19.00 .3 * .5 = 1.5 2.01 * 0.3 = 0.603 .3 / 2 = 0.15 .30 / 2 = 0.15 20 / 3 = 6.66666666 You can confidently compare 1.5000 == 1.5 1 == 1.0 Also, there are no floating-point concerns with rounding, it always yields the expected results: NumRound( 9.5 ) == 10 NumRound( 9.85, 1 ) == 9.9 NumRound( 9.95, 1 ) == 10.0 NumRound( 155, -1 ) == 160 Lists and ArraysHere is some code to create a list of values: CMarkup mList; mList.AddElem( "E", "Smith" ); mList.AddElem( "E", "Doe" ); mList.AddElem( "E", "Jones" ); <E>Smith</E>
<E>Doe</E>
<E>Jones</E>
You can loop through all the items in the list with mList.ResetPos();
while ( mList.FindElem() )
{
str sLastName = mList.GetData();
// ...
}
Although it is more efficently used as a list where you loop through the elements sequentially, you can also access it like an array. To go directly to the second item and get the value call: str sVal = mList.FindGetData("/*[2]");
Note the slash in StructuresThere are no structures or classes like C++, but you can store any complex set of data in a CMarkup object (see Dynamic Structure Documents). The subdocument functions (AddSubDoc, GetSubDoc) can help mimic substructures as well (see Subdocuments and Fragments of XML Documents). | ||||||||||||||||||||||||||||||||||||||||||||
|
Posted July 26, 2007. Question or comment about this article? ©Copyright 2008 First Objective Software, Inc. All rights reserved. |