US Statistical Report Suite: us_state_report_generator

us_state_report_generator serves as the base class for all of the derived report generating classes in the US Statistical Report Suite. The actual header and cpp files can be viewed below. An explanation of the class and member functions is detailed here.

This base class, as well as all classes in the report suite, is wrapped in the namespace Xport_report_suite. The base class, like all other classes in the suite, was made to generate reports for the xhtml strict document_type, since this is the default document type in Xport. All report files in the US Statistical Report Suite derive from us_state_report_generator.

As shown in the header file below, there are only a few public interface operations in the base class. The first, generate_report(), is the main operation for the base class. This is a template method, which calls needed virtual functions which are also declared, but not defined, in the base class. This function contains two formal parameters, the first for the document object to populate, the second for the stylesheet object to populate. Upon returning from this function, the document and stylesheet objects will contain the report (determined by the derived class object) and accompanied stylesheet.

The second public operations in the base class are used to obtain the output folders to place the report and stylesheet files. report_path() specifies the subfolder off the root folder in which to place the specific report. Each derived report generating classes overrides this operation to specifiy which subfolder it's associated report will be placed. The third public operation is called upon to insure that the appropriate report root and subfolders are created.

The protected member functions are functions that are used for various purposes by the derived report generating classes. The first three of these are used to retrieve the state data. The first of these, get_state_data() retrieves the data for all the states. The second, get_divisional_state_data() is used to get the data for states in a specific US division. The third, get_regional_state_data() retrieves the data for a specific US region . All three of these functions accept the following arguments.

  • A reference to a vector of state data, which is populated with the requested data. (output parameter)
  • An enumeration which specifies the state data field in which to sort the vector.
  • An enumerated value which specifies the sort order (ascending or descending)

The last two of the functions described above also accept as the first argument, an enumerated value which specifies the division/region in which to retrieve the state data.

The remaining protected functions are helper functions. get_region_name() returns the name of the region specified by the passed region enumerator. get_division_name() returns the name of the division specified by the passed division enumerator. numeric_format() formats an integer/double as a string value, and is overloaded for convienience.

The private member functions are all pure virtual, and need to be overridden by the derived classes to perform specific actions. create_header() is expected to create the main report header.

  • create_header() is expected to create the main report header.
  • create_report_body() is expected to create the body of the report.
  • create_footer() is expected to create the footer of the report.
  • create_stylesheet() is expected to create the external stylesheet for the report.
  • report_dir() is expected to return the directory path in which to save the report and stylesheet. It may call root_dir() and report_path() as needed.
  • report_name() is expected to return an appropriate name for the report.

There are two data members in the base class. Both are declared mutable for the sake of passing the derived class objects as const objects. The first data member, state_info_vec contains all the state data from the state data file. This vector is loaded in the base class's constructor. The second data member specifies the current state sort field.

There are also some auxiliary structures and enumerations declared in us_state_report_generator.h, and they are discussed in the helper constructs. The implementation of the base class can also be viewed below, in us_state_report_generator.cpp.

The implementation of the base class, in us_state_report_generator.cpp can also be viewed below. The implmentation of the base class functions are not overly complex, and can be understood by inspection. It's inportant to note, however, that there are two constant strings which are defined at the top of the cpp file. These two strings specify the location of the data file, states.txt, and the root drive/directory in which the reports and stylesheets will be placed. You may need to modify these two strings, depending on where you place the data file, and where you wish the reports to be placed.

  • area_reports
  • capital_reports
  • density_reports



Work Time Studio

Datasoft Solutions is proud to present their landmark product, Work Time Studio. Utilizing the tree container library, Work Time Studio provides unparalleled features in personal time, project and task management software. If you're looking for a way to increase your productivity, visit Work Time Studio's product website, and start being more productive today.