StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
Tutorials

Table of Contents

Introduction

This page contains some tutorial examples that will help you getting started using StdAir. Most examples show how to construct some simple business objects, i.e., instances of the so-named Business Object Model (BOM).

Preparing the StdAir Project for Development

The source code for these examples can be found in the batches and test/stdair directories. They are compiled along with the rest of the StdAir project. See the User Guide (Users Guide) for more details on how to build the StdAir project.

Build a Predefined BOM Tree

A few steps:

Instanciate the BOM Root Object

First, a BOM root object (i.e., a root for all the classes in the project) is instantiated by the stdair::STDAIR_ServiceContext context object, when the stdair::STDAIR_Service is itself instantiated. The corresponding StdAir type (class) is stdair::BomRoot.

In the following sample, that object is named ioBomRoot, and is given as input/output parameter of the stdair::CmdBomManager::buildSampleBom() method:

void CmdBomManager::buildSampleBom (BomRoot& ioBomRoot) {

Instanciate the (Airline) Inventory Object

An airline inventory object can then be instantiated. Let us give it the "BA" airline code (corresponding to British Airways) as the object key. That is, an object (let us name it lBAKey) of type (class) stdair::InventoryKey has first to be instantiated.

const InventoryKey lBAKey (lAirlineCodeBA);

Thanks to that key, an airline inventory object, i.e. of type (class) stdair::Inventory, can be instantiated. Let us name that airline inventory object lBAInv.

Inventory& lBAInv = FacBom<Inventory>::instance().create (lBAKey);

Link the Inventory Object with the BOM Root

Then, both objects have to be linked: the airline inventory object (stdair::Inventory) has to be linked with the root of the BOM tree (stdair::BomRoot). That operation is as simple as using the stdair::FacBomManager::addToListAndMap() method:

FacBomManager::addToListAndMap (ioBomRoot, lBAInv);
FacBomManager::linkWithParent (ioBomRoot, lBAInv);

Build Another Airline Inventory

Another airline inventory object, corresponding to the Air France (Air France) company, is instantiated the same way:

const InventoryKey lAFKey (lAirlineCodeAF);
Inventory& lAFInv = FacBom<Inventory>::instance().create (lAFKey);
FacBomManager::addToListAndMap (ioBomRoot, lAFInv);
FacBomManager::linkWithParent (ioBomRoot, lAFInv);

See the corresponding full program (C++ Class Building Sample StdAir BOM Trees) for more details.

Dump The BOM Tree Content

From the BomRoot (of type stdair::BomRoot) object instance, the list of airline inventories (of type stdair::Inventory) can then be retrieved...

const InventoryList_T& lInventoryList =
BomManager::getList<Inventory> (iBomRoot);

... and browsed:

for (InventoryList_T::const_iterator itInv = lInventoryList.begin();
itInv != lInventoryList.end(); ++itInv, ++invIdx) {
const Inventory* lInv_ptr = *itInv;
assert (lInv_ptr != NULL);
// Retrieve the inventory key (airline code)
const AirlineCode_T& lAirlineCode = lInv_ptr->getAirlineCode();
// Display only the requested inventories
if (iAirlineCode == "all" || iAirlineCode == lAirlineCode) {
// Get the list of flight-dates for that inventory
list (oStream, *lInv_ptr, invIdx, iFlightNumber);
}
}
}
// ////////////////////////////////////////////////////////////////////
void BomDisplay::list (std::ostream& oStream, const Inventory& iInventory,
const unsigned short iInventoryIndex,
const FlightNumber_T& iFlightNumber) {
// Save the formatting flags for the given STL output stream
FlagSaver flagSaver (oStream);
// Check whether there are FlightDate objects
if (BomManager::hasMap<FlightDate> (iInventory) == false) {
return;
}
//
const AirlineCode_T& lAirlineCode = iInventory.getAirlineCode();
oStream << iInventoryIndex << ". " << lAirlineCode << std::endl;
// Browse the flight-dates
unsigned short lCurrentFlightNumber = 0;
unsigned short flightNumberIdx = 0;
unsigned short departureDateIdx = 1;
const FlightDateMap_T& lFlightDateList =
BomManager::getMap<FlightDate> (iInventory);
for (FlightDateMap_T::const_iterator itFD = lFlightDateList.begin();
itFD != lFlightDateList.end(); ++itFD, ++departureDateIdx) {
const FlightDate* lFD_ptr = itFD->second;
assert (lFD_ptr != NULL);
// Retrieve the key of the flight-date
const FlightNumber_T& lFlightNumber = lFD_ptr->getFlightNumber();
const Date_T& lFlightDateDate = lFD_ptr->getDepartureDate();
// Display only the requested flight number
if (iFlightNumber == 0 || iFlightNumber == lFlightNumber) {
//
if (lCurrentFlightNumber != lFlightNumber) {
lCurrentFlightNumber = lFlightNumber;
++flightNumberIdx; departureDateIdx = 1;
oStream << " " << iInventoryIndex << "." << flightNumberIdx << ". "
<< lAirlineCode << lFlightNumber << std::endl;
}
oStream << " " << iInventoryIndex << "." << flightNumberIdx
<< "." << departureDateIdx << ". "
<< lAirlineCode << lFlightNumber << " / " << lFlightDateDate
<< std::endl;
}
}
}
// ////////////////////////////////////////////////////////////////////
void BomDisplay::listAirportPairDateRange (std::ostream& oStream,
const BomRoot& iBomRoot) {
// Save the formatting flags for the given STL output stream
FlagSaver flagSaver (oStream);
// Check whether there are AirportPair objects
if (BomManager::hasList<AirportPair> (iBomRoot) == false) {
return;
}
const AirportPairList_T& lAirportPairList =
BomManager::getList<AirportPair> (iBomRoot);
for (AirportPairList_T::const_iterator itAir = lAirportPairList.begin();
itAir != lAirportPairList.end(); ++itAir ) {
const AirportPair* lAir_ptr = *itAir;
assert (lAir_ptr != NULL);
// Check whether there are date-period objects
assert (BomManager::hasList<DatePeriod> (*lAir_ptr) == true);
// Browse the date-period objects
const DatePeriodList_T& lDatePeriodList =
BomManager::getList<DatePeriod> (*lAir_ptr);
for (DatePeriodList_T::const_iterator itDP = lDatePeriodList.begin();
itDP != lDatePeriodList.end(); ++itDP) {
const DatePeriod* lDP_ptr = *itDP;
assert (lDP_ptr != NULL);
// Display the date-period object
oStream << lAir_ptr->describeKey()
<<" / " << lDP_ptr->describeKey() << std::endl;
}
}
}
// ////////////////////////////////////////////////////////////////////
void BomDisplay::csvDisplay (std::ostream& oStream,

See the corresponding full program (C++ Utility Class Browsing and Dumping the StdAir BOM Tree) for more details.

Result of the Tutorial Program

When the stdair.cpp program is run (with the -b option), the output should look like:

[D]../../batches/stdair.cpp:243: Welcome to stdair
[D]../../../stdair/command/CmdBomManager.cpp:41: StdAir will build the BOM tree from built-in specifications.
[D]../../batches/stdair.cpp:286:
===============================================================
BomRoot: -- ROOT --
===============================================================
+++++++++++++++++++++++++++++++++++++++++++++++++
Inventory: BA
+++++++++++++++++++++++++++++++++++++++++++++++++
******************************************
FlightDate: BA9, 2011-Jun-10
******************************************
******************************************
Leg-Dates:
----------
Flight, Leg, BoardDate, BoardTime, OffDate, OffTime, Date Offset, Time Offset, Elapsed, Distance, Capacity,
BA9 2011-Jun-10, LHR-BKK, 2011-Jun-10, 21:45:00, 2011-Jun-11, 15:40:00, 11:05:00, 1, 06:50:00, 9900, 0,
BA9 2011-Jun-10, BKK-SYD, 2011-Jun-11, 17:05:00, 2011-Jun-12, 15:40:00, 09:05:00, 1, 13:30:00, 8100, 0,
******************************************
******************************************
LegCabins:
----------
Flight, Leg, Cabin, OffedCAP, PhyCAP, RgdADJ, AU, UPR, SS, Staff, WL, Group, CommSpace, AvPool, Avl, NAV, GAV, ACP, ETB, BidPrice,
BA9 2011-Jun-10, LHR-BKK 2011-Jun-10, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 3.52965e-319, 0, 0,
BA9 2011-Jun-10, BKK-SYD 2011-Jun-11, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
******************************************
******************************************
Buckets:
--------
Flight, Leg, Cabin, Yield, AU/SI, SS, AV,
******************************************
******************************************
SegmentCabins:
--------------
Flight, Segment, Cabin, FF, Bkgs, MIN, UPR, CommSpace, AvPool, BP,
BA9 2011-Jun-10, LHR-SYD 2011-Jun-10, Y, EcoSaver, 0, 0, 0, 0, 9, 0,
BA9 2011-Jun-10, LHR-BKK 2011-Jun-10, Y, EcoSaver, 0, 0, 0, 0, 9, 0,
BA9 2011-Jun-10, BKK-SYD 2011-Jun-11, Y, EcoSaver, 0, 0, 0, 0, 9, 0,
******************************************
******************************************
Subclasses:
-----------
Flight, Segment, Cabin, FF, Subclass, MIN/AU (Prot), Nego, NS%, OB%, Bkgs, GrpBks (pdg), StfBkgs, WLBkgs, ETB, ClassAvl, RevAvl, SegAvl,
BA9 2011-Jun-10, LHR-SYD 2011-Jun-10, Y, EcoSaver, Q, 0 (0), 0, 0, 0, 0, 0 (0), 0, 0, 0, 0, 0, 0,
+++++++++++++++++++++++++++++++++++++++++++++++++
Inventory: AF
+++++++++++++++++++++++++++++++++++++++++++++++++
******************************************
FlightDate: AF84, 2011-Mar-20
******************************************
******************************************
Leg-Dates:
----------
Flight, Leg, BoardDate, BoardTime, OffDate, OffTime, Date Offset, Time Offset, Elapsed, Distance, Capacity,
AF84 2011-Mar-20, CDG-SFO, 2011-Mar-20, 10:40:00, 2011-Mar-20, 12:50:00, 11:10:00, 0, -09:00:00, 9900, 0,
******************************************
******************************************
LegCabins:
----------
Flight, Leg, Cabin, OffedCAP, PhyCAP, RgdADJ, AU, UPR, SS, Staff, WL, Group, CommSpace, AvPool, Avl, NAV, GAV, ACP, ETB, BidPrice,
AF84 2011-Mar-20, CDG-SFO 2011-Mar-20, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
******************************************
******************************************
Buckets:
--------
Flight, Leg, Cabin, Yield, AU/SI, SS, AV,
******************************************
******************************************
SegmentCabins:
--------------
Flight, Segment, Cabin, FF, Bkgs, MIN, UPR, CommSpace, AvPool, BP,
AF84 2011-Mar-20, CDG-SFO 2011-Mar-20, Y, EcoSaver, 0, 0, 0, 0, 9, 0,
******************************************
******************************************
Subclasses:
-----------
Flight, Segment, Cabin, FF, Subclass, MIN/AU (Prot), Nego, NS%, OB%, Bkgs, GrpBks (pdg), StfBkgs, WLBkgs, ETB, ClassAvl, RevAvl, SegAvl,
AF84 2011-Mar-20, CDG-SFO 2011-Mar-20, Y, EcoSaver, Q, 0 (0), 0, 0, 0, 0, 0 (0), 0, 0, 0, 0, 0, 0,

See the corresponding full program (Command-Line Utility to Demonstrate Typical StdAir Usage) for more details.

Extend the Pre-Defined BOM Tree

Now that we master how to instantiate the pre-defined StdAir classes, let us see how to extend that BOM.

Extend an Airline Inventory Object

For instance, let us assume that some (IT) provider (e.g., you) would like to have a specific implementation of the Inventory object. The corresponding class has just to extend the stdair::Inventory class:

namespace myprovider {
class Inventory : public stdair::Inventory {

The STL containers have to be defined accordingly too:

typedef std::list<Inventory*> InventoryList_T;

See the full class definition (Specific Implementation of an Airline Inventory) and implementation (Specific Implementation of an Airline Inventory) for more details.

Build the Specific BOM Objects

The BOM root object (stdair::BomRoot) is instantiated the classical way:

const std::string& lBomRootKeyStr = lPersistentBomRoot.describeKey();

Then, the specific implementation of the airline inventory object (myprovider::Inventory) can be instantiated the same way as a standard Inventory (stdair::Inventory) would be:

const stdair::InventoryKey lBAKey (lBAAirlineCode);
myprovider::Inventory& lBAInv =

Then, the specific implementation of the airline inventory object (myprovider::Inventory) is linked to the root of the BOM tree (stdair::BomRoot) the same way as the standard Inventory (stdair::Inventory) would be:

Another specific airline inventory object is instantiated the same way:

const stdair::InventoryKey lAFKey (lAFAirlineCode);
myprovider::Inventory& lAFInv =

From the BomRoot (of type stdair::BomRoot) object instance, the list of specific airline inventories (of type stdair::Inventory) can then be retrieved...

const myprovider::InventoryList_T& lInventoryList =
stdair::BomManager::getList<myprovider::Inventory> (lBomRoot);

... and browsed:

for (myprovider::InventoryList_T::const_iterator itInv =
lInventoryList.begin(); itInv != lInventoryList.end();
++itInv, ++idx) {
const myprovider::Inventory* lInv_ptr = *itInv;
BOOST_REQUIRE (lInv_ptr != NULL);
BOOST_CHECK_EQUAL (lInventoryKeyArray[idx], lInv_ptr->describeKey());
BOOST_CHECK_MESSAGE (lInventoryKeyArray[idx] == lInv_ptr->describeKey(),
"They inventory key, '" << lInventoryKeyArray[idx]
<< "', does not match that of the Inventory object: '"
<< lInv_ptr->describeKey() << "'");
}

Result of the Tutorial Program

When this program is run, the output should look like:

Inventory: BA
Inventory: AF

See the corresponding full program (Command-Line Test to Demonstrate How To Extend StdAir BOM) for more details.