argv is now stored internally as a std::vector container
This commit is contained in:
parent
4acca85a13
commit
5a6644de98
|
@ -1,3 +1,6 @@
|
|||
2021-03-31 Markus Gans <guru.mail@muenster.de>
|
||||
* argv is now stored internally as a std::vector container
|
||||
|
||||
2021-03-30 Markus Gans <guru.mail@muenster.de>
|
||||
* Stops terminal refresh during dialog resizing until all
|
||||
child widgets have been redrawn
|
||||
|
|
|
@ -81,10 +81,9 @@ struct timeval FApplication::time_last_event {};
|
|||
|
||||
// constructors and destructor
|
||||
//----------------------------------------------------------------------
|
||||
FApplication::FApplication (const int& _argc, char* _argv[])
|
||||
: FWidget{processParameters(_argc, _argv)}
|
||||
, app_argc{_argc}
|
||||
, app_argv{_argv}
|
||||
FApplication::FApplication (const int& arg_c, char* arg_v[])
|
||||
: FWidget{processParameters(Args(arg_v, arg_v + arg_c))}
|
||||
, app_args{arg_v, arg_v + arg_c}
|
||||
{
|
||||
if ( quit_now )
|
||||
return;
|
||||
|
@ -101,14 +100,6 @@ FApplication::FApplication (const int& _argc, char* _argv[])
|
|||
// First define the application object
|
||||
internal::var::app_object = this;
|
||||
|
||||
if ( ! (_argc && _argv) )
|
||||
{
|
||||
using CString = char*;
|
||||
static std::array<CString, 1> empty{{CString("")}};
|
||||
app_argc = 0;
|
||||
app_argv = empty.data();
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -532,12 +523,22 @@ inline void FApplication::setCmdOptionsMap (CmdMap& cmd_map)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::cmdOptions (const int& argc, char* argv[])
|
||||
void FApplication::cmdOptions (const Args& args)
|
||||
{
|
||||
// Interpret the command line options
|
||||
|
||||
CmdMap cmd_map{};
|
||||
setCmdOptionsMap(cmd_map);
|
||||
auto argc = int(args.size());
|
||||
std::vector<const char*> argv(argc);
|
||||
std::transform ( args.begin()
|
||||
, args.end()
|
||||
, argv.begin()
|
||||
, [] (const std::string& str)
|
||||
{
|
||||
return str.data();
|
||||
}
|
||||
);
|
||||
|
||||
while ( true )
|
||||
{
|
||||
|
@ -546,7 +547,8 @@ void FApplication::cmdOptions (const int& argc, char* argv[])
|
|||
std::vector<CmdOption> long_options{};
|
||||
setLongOptions(long_options);
|
||||
auto p = reinterpret_cast<const struct option*>(long_options.data());
|
||||
const int opt = getopt_long (argc, argv, "", p, &idx);
|
||||
auto argv_data = const_cast<char**>(argv.data());
|
||||
const int opt = getopt_long (argc, argv_data, "", p, &idx);
|
||||
|
||||
if ( opt == -1 )
|
||||
break;
|
||||
|
@ -1228,16 +1230,15 @@ void FApplication::sendWheelEvent ( const FMouseData& md
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
FWidget* FApplication::processParameters (const int& argc, char* argv[])
|
||||
FWidget* FApplication::processParameters (const Args& args)
|
||||
{
|
||||
if ( argc > 0 && argv[1] && ( std::strcmp(argv[1], "--help") == 0
|
||||
|| std::strcmp(argv[1], "-h") == 0 ) )
|
||||
if ( args.size() > 1 && (args[1] == "--help" || args[1] == "-h") )
|
||||
{
|
||||
showParameterUsage();
|
||||
FApplication::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
cmdOptions (argc, argv);
|
||||
cmdOptions (args);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ class FApplication : public FWidget
|
|||
public:
|
||||
// Typedef
|
||||
using FLogPtr = std::shared_ptr<FLog>;
|
||||
using Args = std::vector<std::string>;
|
||||
|
||||
// Constructor
|
||||
FApplication (const int&, char*[]);
|
||||
|
@ -113,8 +114,7 @@ class FApplication : public FWidget
|
|||
|
||||
// Accessors
|
||||
FString getClassName() const override;
|
||||
int getArgc() const;
|
||||
char** getArgv() const;
|
||||
Args getArgs() const;
|
||||
static FApplication* getApplicationObject();
|
||||
static FWidget* getKeyboardWidget();
|
||||
static FLogPtr& getLog();
|
||||
|
@ -172,7 +172,7 @@ class FApplication : public FWidget
|
|||
static void setTerminalEncoding (const FString&);
|
||||
static void setLongOptions(std::vector<CmdOption>&);
|
||||
static void setCmdOptionsMap (CmdMap&);
|
||||
static void cmdOptions (const int&, char*[]);
|
||||
static void cmdOptions (const Args&);
|
||||
static FStartOptions& getStartOptions();
|
||||
static void showParameterUsage();
|
||||
void destroyLog();
|
||||
|
@ -221,7 +221,7 @@ class FApplication : public FWidget
|
|||
void sendWheelEvent ( const FMouseData&
|
||||
, const FPoint&
|
||||
, const FPoint& ) const;
|
||||
static FWidget* processParameters (const int&, char*[]);
|
||||
static FWidget* processParameters (const Args&);
|
||||
void processResizeEvent() const;
|
||||
void processCloseWidget();
|
||||
void processLogger() const;
|
||||
|
@ -231,8 +231,7 @@ class FApplication : public FWidget
|
|||
static bool isNextEventTimeout();
|
||||
|
||||
// Data members
|
||||
int app_argc{};
|
||||
char** app_argv{};
|
||||
Args app_args{};
|
||||
uInt64 key_timeout{100000}; // 100 ms
|
||||
uInt64 dblclick_interval{500000}; // 500 ms
|
||||
std::streambuf* default_clog_rdbuf{std::clog.rdbuf()};
|
||||
|
@ -258,12 +257,8 @@ inline FString FApplication::getClassName() const
|
|||
{ return "FApplication"; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline int FApplication::getArgc() const
|
||||
{ return app_argc; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline char** FApplication::getArgv() const
|
||||
{ return app_argv; }
|
||||
inline FApplication::Args FApplication::getArgs() const
|
||||
{ return app_args; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FApplication::cb_exitApp (FWidget* w) const
|
||||
|
|
Loading…
Reference in New Issue