10 "A second instance of the App-singleton was created, which is forbidden.")
13 machine.Program.reserve( 20 + 10 );
16 { States::SetCamps , &App::onBsSetCamps },
17 { States::PrepareResources , &App::onBsPrepareResources },
18 { States::SetNameVersionAndInfo , &App::onBsSetNameVersionAndInfo },
20 { States::PrepareConfig , &App::onBsPrepareConfig },
21 { States::PreloadVariables , &App::onBsPreloadVariables },
22 { States::CLIDefine , &App::onBsCLIDefine },
23 { States::CLIReadOptions , &App::onBsCLIReadOptions },
24 { States::ImportConfig , &App::onBsImportConfig },
25 { States::ConfigureCLI , &App::onBsConfigureCLI },
27 { States::FinalizeBootstrap , &App::onBsFinalizeBootstrap },
28 { States::ReadDryRunOption , &App::onBsReadDryRunOption },
29 { States::SetupALox , &App::onBsSetupALox },
31 { States::RunStart , &App::onRunStart },
32 { States::Run , &App::onRun },
33 { States::RunEnd , &App::onRunEnd },
35 { States::AnnounceShutdown , &App::onSdAnnounceShutdown },
36 { States::CleanALox , &App::onSdCleanALox },
37 { States::ExportConfig , &App::onSdExportConfig },
38 { States::Output , &App::onSdOutput },
39 { States::FinalizeShutdown , &App::onSdFinalizeShutdown },
45int App::Main(
int argc,
const char** argv,
const wchar_t** argvw ) {
53 return a.State.Integral<int>() < b.State.Integral<int>();
60 ALIB_ERROR(
"APP",
"Duplicate command ID {} found in program",
94 "Exceptions::ControlledEarlyExit thrown while not in States::RunStart/Run/RunEnd")
96 "Exceptions::ControlledEarlyExit thrown without having exit code set")
103 catch( std::runtime_error& e ) {
104 cErr->Add(
"Unhandled system exception: ", e.what());
109 "This should be done by the user of class ALib App.")
123 return machine.GetExitCode().Integral<
int>();
162 "<- Exceptions::ControlledEarlyExit was trown here!" );
163 machine.DbgDumpFurtherExitCodes(target);
173 cErr->Add(
"Exception occurred when executing command:\n"
175 "Exception details ({} item{}):",
176 cmdLine, exception.
Size(), (exception.
Size() > 1 ?
"s" :
"") )
178 .Add( exception.
Format() )
182 cErr->Add(
"Application exit-code will be: ",
machine.GetExitCode() );
185 machine.DbgDumpFurtherExitCodes(target);
193 if ( !files.size() ) {
199 p.
Add(
"Configuration file: {!ATab}:1\n", fileInfo.Pathname );
200 p.
Add(
" Existed: {!ATab}\n", fileInfo.WasEmpty ?
"no" :
"yes" );
202 if ( fileInfo.Exports.IsNotEmpty() ) {
205 p.
Add(
" Exports: {!ATab}\n" , tok.
Next() );
215 NString128 resourceName(
"CFGF_NAME_"); resourceName << (cnt+1);
216 String name=
APP.TryResource( resourceName );
219 files.emplace_back();
220 files.at(cnt).Pathname= name;
227 if ( fInfo.Comment.IsEmpty() ) {
228 NString128 resourceName(
"CFGF_CMT_"); resourceName << (cnt+1);
229 fInfo.Comment=
APP.TryResource( resourceName );
237 NString128 resourceName(
"CFGF_EXP_"); resourceName << (cnt+1);
238 fInfo.Exports=
APP.TryResource( resourceName );
246 NString128 resourceName(
"CFGF_EXP_"); resourceName << (cnt+1);
247 String exports=
APP.TryResource( resourceName );
248 if (exports.IsNull() )
250 additionalExports <<
',' << exports;
256 "Config-exports {!Q} found, but no config-file is created by the application",
262 last.
Exports.
Allocate(files.get_allocator().GetAllocator(), additionalExports );
271 if (fileInfo.Pathname.IsEmpty() || fileInfo.Pathname.IsAbsolute())
274 Path backup(fileInfo.Pathname);
276 if ( fileInfo.Pathname.StartsWith(
A_PATH(
"./" ))
277 || fileInfo.Pathname.StartsWith(
A_PATH(
"../" ))
278 || fileInfo.Pathname.StartsWith(
A_PATH(
".\\" ))
279 || fileInfo.Pathname.StartsWith(
A_PATH(
"..\\")) )
280 fileInfo.Pathname.Change( SystemFolders::Current, backup );
282 fileInfo.Pathname.Change( SystemFolders::HomeConfig );
289 if( optionConfig ==
nullptr )
292 Substring names= optionConfig->Args.front();
297 if (files.size() <= cnt)
298 files.emplace_back();
299 Path& path= files.at(cnt).Pathname;
301 && !
String(
A_CHAR(
"Default")).StartsWith<CHK,lang::Case::Ignore>( name ) )
312 while (files.size() && files.back().Pathname.IsEmpty())
321 #if ALIB_DEBUG_RESOURCES
330 if(
cOut->LineWidth == 0) {
343 String infoFmtString=
APP.TryResource(
"AppInfo");
369 for(
auto& arg :
cli.OptionArgsIgnored )
383 for (
size_t fileNo= 0; fileNo < files.size() ; ++fileNo ) {
405 if( dryOpt !=
nullptr ) {
407 if( dryOpt->Args.IsNotEmpty() ) {
418 "DEBUG_LOGGER already created. Obviously logging was used "
419 "prior to the invocation of bs30SetupALox. This can cause issues" )
468 if (fileInfo.Pathname.IsEmpty())
479 auto& tok= tknzr.
Next();
482 cntChanges+= changes;
488 && fileInfo.Comment.IsNotEmpty() ) {
493 .RemoveLastNewLine();
494 iniFile.FileComments.Allocate(iniFile.Allocator, buf);
504 if( cntChanges > 0 ) iniFileFeeder.
ExportEnd( fileInfo.Pathname );
512 if (
cOut->Buffer.IsNotEmpty() ) {
513 std::cout <<
cOut->Buffer;
515 std::cout << std::endl;
516 cOut->Buffer.Reset();
520 if (
cErr->Buffer.IsNotEmpty() ) {
521 std::cerr <<
cErr->Buffer;
523 std::cerr << std::endl;
524 cErr->Buffer.Reset();
532 #if ALIB_DEBUG_RESOURCES
533 std::cout << std::endl;
534 std::cout <<
"---------------- Resource Pool Dump ----------------" << std::endl;
535 auto resourceList=
APP.GetResourcePool().DbgGetList();
537 std::cout <<
"---------------- Resource Pool Dump (end) ----------" << std::endl;
541 #if ALIB_DEBUG_BOXING
542 std::cout << std::endl;
543 std::cout <<
"---------------- Debug Boxing ----------------" << std::endl;
547 std::cout <<
"---------------- Debug Boxing (end) ----------" << std::endl;
565 String resource=
APP.TryResource(
"AppStart" );
571 resource=
APP.TryResource(
"DryRunStart" );
582 option->
Args.front(),
595 if(
cli.ArgsLeft.size() == 0) {
602 cli.ReadNextCommands();
604 if(
cli.NextCommandIt ==
cli.CommandsParsed.end() ) {
613 if (
Command* actCmd=
cli.NextCommand(); actCmd !=
nullptr ) {
617 "Command \"{}\" recognized but not processed by the App.",
618 actCmd->Declaration->Identifier() )
630 String dryRunEnd=
APP.TryResource(
"DryRunEnd" );
632 cOut->AddMarked( dryRunEnd );
646 if ( cmd ==
nullptr )
669 cOut->Add(
"Configuration files:\n");
#define ALIB_CALLER_NULLED
#define ALIB_ASSERT(cond, domain)
#define ALIB_WARNING(domain,...)
#define ALIB_ERROR(domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define Log_SetVerbosityExport(...)
#define Lox_RemoveLogger(logger)
#define Lox_SetVerbosity(...)
#define Lox_SetVerbosityExport(...)
virtual void onRunStart()
virtual void onBsImportConfig()
virtual void onBsPreloadVariables()
virtual void onBsSetNameVersionAndInfo()
@ FinalizeBootstrap
Invokes the virtual method #"onBsFinalizeBootstrap".
@ RunStart
Invokes the virtual method #"onRunStart".
@ FinalizeShutdown
Invokes the virtual method #"onSdFinalizeShutdown".
@ ImportConfig
Invokes the virtual method #"onBsImportConfig".
@ RunEnd
Invokes the virtual method #"onRunEnd".
virtual void onSdFinalizeShutdown()
virtual void onBsSetCamps()
StateMachine machine
The state-machine singleton.
NString releaseLoggerName
virtual int Main(int argc, const char **argv, const wchar_t **argvw=nullptr)
virtual void onSdOutput()
virtual void onBsReadDryRunOption()
virtual void getConfigFilePathsFromResources(StdVectorMA< ConfigFileDescriptor > &files)
virtual void onBsPrepareConfig()
virtual ~App()
Virtual destructor.
Parameters
Built-in parameters of commands and options used with class #"App".
@ UseReleaseLoggerForDebugLogging
@ ALoxVerbosityExportAllAndWriteBackDbgLogger
@ ALoxVerbosityExportAllAndWriteBackRelLogger
virtual void onSdCleanALox()
virtual void onBsPrepareResources()
virtual void printConfigFileInfo(Paragraphs &target)
@ ErrUnknownCommand
Unknown command.
@ ErrUnknown
An unknown exception occurred. This should never happen.
@ ErrNoCmdGiven
No command given.
@ ErrParsingOption
Error when parsing an option.
@ ErrBadParamValue
Bad parameter value.
@ ErrParsingCommand
Error when parsing a command.
@ ErrConfigFileNotWritable
The configuration file(s) could not be written.
virtual void exitWithHelpOutput(Enum exitCode, const String &helpTopic=NULL_STRING, Box formatParam1=EMPTY_STRING, Box formatParam2=EMPTY_STRING)
virtual void exceptionDisplay(Exception &exception, AString &target)
virtual void getConfigFilePathsFromCLIParam(StdVectorMA< ConfigFileDescriptor > &files)
virtual void onBsSetupALox()
Flags flags
Various boolean flags used to configure the application.
Options
Built-in options used with class #"App".
@ DryRun
Sets the flag #"App::dryrun".
@ Config
Change the configured config file path(s).
virtual void onSdAnnounceShutdown()
virtual void getConfigFilePaths(StdVectorMA< ConfigFileDescriptor > &files)
virtual void getConfigFilePathsMakeAbsolutePaths(StdVectorMA< ConfigFileDescriptor > &files)
virtual bool processCLICmd(Command *cmd)
Commands
Built-in commands used with class #"App".
@ Version
Show version information.
@ Info
Show info and configuration details.
virtual void onBsConfigureCLI()
virtual void onBsCLIReadOptions()
virtual void onBsCLIDefine()
CommandLine cli
The command-line parser.
lox::textlogger::TextLogger * releaseLogger
virtual Enum exceptionToExitCode(Exception &exception)
bool cliStop
Flag to stop the CLI processing loop.
virtual void onBsFinalizeBootstrap()
Paragraphs * cErr
Same as #".cOut", but used for stream std::err.
virtual void onSdExportConfig()
static bool GetHelp(CommandLine &cmdLine, const String &topics, Paragraphs &text)
const Enum & Element() const
const String & Identifier()
const String & Identifier()
AString & Format(AString &target) const
const Enum & Type() const
static textlogger::TextLogger * DEBUG_LOGGER
The debug logger created by AddDebugLogger.
static void SetALibAssertionPlugin(Lox *lox)
static textlogger::TextLogger * CreateConsoleLogger(const NString &name=nullptr)
static std::ostream * DbgResourceLoadObserver
TAString & InsertAt(const TString< TChar > &src, integer pos)
TAString & DeleteStart(integer regionLength)
constexpr bool IsEmpty() const
void Allocate(TAllocator &allocator, const TString< TChar > ©)
constexpr bool IsNotEmpty() const
TSubstring & Trim(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
TString< TChar > ConsumeToken(TChar separator=',', lang::Inclusion includeSeparator=lang::Inclusion::Include)
TSubstring< TChar > & Next(lang::Whitespaces trimming=lang::Whitespaces::Trim, TChar newDelim='\0')
static int GetWidth(bool forceRedetect=false, int defaultWidth=80)
static const ProcessInfo & Current()
StringVectorMA DefaultCategories
StringVectorMA AlternativeArgs
int ImportStart(const Path &path)
void ExportEnd()
Closes and deletes the internal iniFile instance without writing an opened INI-file.
int AddResourcedSectionComments(ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceNamePrefix)
int ExportSubTree(Configuration::Cursor cursor, bool directChildrenOnly=false)
bool DidNotExistOrWasEmpty
void ImportEnd()
Closes and deletes the internal iniFile instance.
int ExportStart(const Path &path)
@ ParsingOptions
General option parse error. Adds option help text.
@ ParsingCommand
General parameter parse error. Adds command help text.
@ NoCommandGiven
Unknown command given.
@ UnknownCommand
Unknown command given.
void Raise(const lang::CallerInfo &ci, int type, std::string_view domain, TArgs &&... args)
std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
AString DumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, const String &headline, const String &indent)
AString DumpVTables(bool staticVtables, bool includeFunctions)
bool Parse(strings::TSubstring< TChar > &input, TEnum &result)
RecursiveLock GLOBAL_ALLOCATOR_LOCK
TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
AString DbgDump(std::vector< std::tuple< NString, NString, String, integer > > &list, const NString &catFilter, const String &format)
Exceptions
Exception codes of namespace #"alib::variables;2".
@ ErrorWritingFile
An error occurred writing the file .
@ ErrorOpeningFile
File not found when reading.
ListMA< camp::Camp * > CAMPS
void BootstrapAddDefaultCamps()
void Bootstrap(BootstrapPhases targetPhase, camp::Camp *targetCamp, int alibVersion, int alibRevision, TCompilationFlags compilationFlags)
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace #"%alib".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class #"ALoxCamp".
boxing::Box Box
Type alias in namespace #"%alib".
monomem::TLocalAllocator< 2 > LocalAllocator2K
Type alias in namespace #"%alib". Allocates 2kB of stack memory.
LocalString< 4096 > String4K
Type alias name for #"TLocalString;TLocalString<character,4096>".
strings::TString< character > String
Type alias in namespace #"%alib".
system::Path Path
Type alias in namespace #"%alib".
strings::TSubstring< character > Substring
Type alias in namespace #"%alib".
camp::Basecamp BASECAMP
The singleton instance of ALib Camp class #"Basecamp".
LocalString< 1024 > String1K
Type alias name for #"TLocalString;TLocalString<character,1024>".
exceptions::Exception Exception
Type alias in namespace #"%alib".
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace #"%alib".
app::AppCamp APP
The singleton instance of the camp class used by class #"App".
constexpr PathCharType DIRECTORY_SEPARATOR
The standard path separator character. Defaults to '\' on Windows OS, '/' else.
NLocalString< 128 > NString128
Type alias name for #"TLocalString;TLocalString<nchar,128>".
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace #"%alib".
format::Paragraphs Paragraphs
Type alias in namespace #"%alib".
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace #"%alib".
strings::TStringLengthResetter< character,lang::HeapAllocator > StringLengthResetter
Type alias in namespace #"%alib".
time::DateTime DateTime
Type alias in namespace #"%alib".
boxing::Enum Enum
Type alias in namespace #"%alib".
LocalString< 512 > String512
Type alias name for #"TLocalString;TLocalString<character,512>".
variables::IniFileFeeder IniFileFeeder
Type alias in namespace #"%alib".
Path Pathname
The resolved full path to the file.
bool WasEmpty
If set, the file did not exist or was empty at the start of the application.
A struct denoting the next state and the corresponding method to execute.
A command argument of the command-line.
CommandDecl * Declaration
The underlying declaration.
ListMA< String, Recycling::Shared > Args
Arguments belonging to this option.
OptionDecl * Declaration
The declaration struct.
integer ConsumedArguments
TIntegral Integral() const
CallerInfo CI
The source code location that this message relates to.
void(* Custom)(App &)
A pointer to a method of a custom derived type.
void(App::* BuiltIn)()
A pointer to a virtual method of class #"%App".