ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::camp::DevtimeResourceCompiler Class Reference

Description:

Manages the compilation of externalized resources from .alibrc files into C++ source code.

This class provides a development-time mechanism to:

  1. Parse human-readable .alibrc resource files
  2. Register the resources in a ALib Camp's resource pool
  3. Generate C++ source code that hard-codes the resources for production builds

This class operates only when the configuration macro ALIB_CAMP_RESOURCE_COMPILATION is set. Otherwise, the class is an almost empty stub. This approach allows a two-phase workflow:

Development Phase:

  • Resources are defined in editable .alibrc text files
  • The compiler parses these files at program startup
  • Generated C++ code is written to designated source files
  • Changes to resources are immediately reflected

Production Phase:

  • The symbol ALIB_CAMP_RESOURCE_COMPILATION is unset
  • Resources are loaded from the generated C++ code
  • No file I/O or parsing occurs at runtime
  • The .alibrc files are not needed for distribution

The compiler uses file modification timestamps to determine when re-compilation is needed. If the target C++ file is newer than the .alibrc file (with 10ms tolerance), no action is taken.

See also

Definition at line 201 of file resourcecompiler.hpp.

#include <resourcecompiler.hpp>

Collaboration diagram for alib::camp::DevtimeResourceCompiler:
[legend]

Public Method Index:

 ~DevtimeResourceCompiler ()
 Destructor. This is empty if the symbol ALIB_CAMP_RESOURCE_COMPILATION is not set.
bool Do (const NString &alibrcFileName, const NString &callingFile, Camp &campInstance, const NString &resourceCategory, bool allowReplacements, const NString &cppFileName)

Protected Field Index:

MonoAllocatorma =nullptr

Field Details:

◆ ma

MonoAllocator* alib::camp::DevtimeResourceCompiler::ma =nullptr
protected

The allocator to use. Created only in case resources are to be compiled (and a C++ file is to be patched).

Definition at line 206 of file resourcecompiler.hpp.

Constructor(s) / Destructor Details:

◆ ~DevtimeResourceCompiler()

alib::camp::DevtimeResourceCompiler::~DevtimeResourceCompiler ( )
inline

Destructor. This is empty if the symbol ALIB_CAMP_RESOURCE_COMPILATION is not set.

Definition at line 212 of file resourcecompiler.hpp.

Method Details:

◆ Do()

bool alib::camp::DevtimeResourceCompiler::Do ( const NString & alibrcFileName,
const NString & callingFile,
Camp & campInstance,
const NString & resourceCategory,
bool allowReplacements,
const NString & cppFileName )

Main entry point for resource compilation.

This method performs the complete resource compilation workflow:

  1. Resolves file paths (relative paths are resolved against CallingFile's directory)
  2. Checks file modification timestamps to avoid unnecessary recompilation
  3. Parses the .alibrc resource file
  4. Registers all resources in the given camp's resource pool
  5. Generates C++ code and patches the target source file

File Path Resolution:

  • Both AlibrcFileName and CppFileName may be relative or absolute paths
  • Relative paths are resolved against the directory containing CallingFile
  • Typically, pass FILE as CallingFile to resolve relative to the calling source

Timestamp-Based Compilation:

  • Compares modification times of .alibrc and .cpp files
  • If the C++ file is newer (with 10ms tolerance), no action is taken
  • Returns false to indicate no compilation occurred

Target File Requirements: The C++ file specified by CppFileName must contain two marker comments:

// ALIB-RESOURCE-COMPILER-REPLACEMENT-START
... generated code will replace this section ...
// ALIB-RESOURCE-COMPILER-REPLACEMENT-END

All lines between these markers are replaced with generated resource loading code. The markers themselves are preserved.

Conditional Compilation: When ALIB_CAMP_RESOURCE_COMPILATION is not set, this method becomes a no-op and always returns false.

Example Usage:

37void Sample::onBsPrepareConfig() {
38 // call parent's implementation. This bulk-loads the resources into the camps.
39 App::onBsPrepareConfig();
40
41 // now, we just add the resources that parent App did not define for us.
43 if(!rc.Do( "sample.alibrc", __FILE__, APP, APP.ResourceCategory, true,
44 // __FILE__ )
45 nullptr )
46 )
47 bulkloadResources();
48
53
54 // Read copyright string from resources and format to current version and year
55 Paragraphs buffer;
56 buffer.LineWidth= 70;
58 buffer.AddMarked( APP.GetResource( "AppInfo" ),
61 CalendarDateTime(DateTime()).Year );
62 }
63 cli.AppInfo.Allocate(cli.GetAllocator(), buffer.Buffer);
64}

For the corresponding .alibrc file format, see manual section 4.2 The .alibrc File Format..
For the generated output, see the replacement section in App/sample.cpp.

Parameters
alibrcFileNamePath to the input .alibrc resource file.
callingFileReference file for resolving relative paths (typically FILE).
campInstanceThe ALib Camp instance whose resource pool receives the resources.
resourceCategoryThe resource category name for registering resources.
allowReplacementsDetermines whether overriding existing resource-keys should raise an ALib Assertion.
cppFileNamePath to the target C++ source file to be patched. If an empty string is given, then the resource file will be loaded in any case and resources will be added.
Returns
true if resources were compiled and the C++ file was updated successfully, false if compilation was skipped (file already up-to-date), an error occurred, or ALIB_CAMP_RESOURCE_COMPILATION is not set.

The documentation for this class was generated from the following file: