Permalink
Browse files

Merge remote branch 'upstream/develop' into develop

  • Loading branch information...
2 parents 28cb253 + 7e8797f commit 7404c6547549ab50e6f3abfea498dcc3065f5f14 @pprindeville committed Jan 5, 2013
@@ -105,6 +105,8 @@ class Util_API Application: public Subsystem
/// Unicode command line arguments.
{
public:
+ typedef std::vector<std::string> ArgVec;
+
enum ExitCode
/// Commonly used exit status codes.
/// Based on the definitions in the 4.3BSD <sysexits.h> header file.
@@ -270,6 +272,15 @@ class Util_API Application: public Subsystem
/// "application.logger" configuration property. If that property
/// is not specified, the logger is "Application".
+ const ArgVec& argv() const;
+ /// Returns reference to vector of the application's arguments as
+ /// specified on the command line. If user overrides the
+ /// Application::main(const ArgVec&) function, it will receive
+ /// only the command line parameters that were not processed in
+ /// Application::processOptons(). This function returns the
+ /// full set of command line parameters as received in
+ /// main(argc, argv*).
+
const OptionSet& options() const;
/// Returns the application's option set.
@@ -388,7 +399,8 @@ class Util_API Application: public Subsystem
SubsystemVec _subsystems;
bool _initialized;
std::string _command;
- ArgVec _args;
+ ArgVec _argv;
+ ArgVec _unprocessedArgs;
OptionSet _options;
bool _unixOptions;
Poco::Logger* _pLogger;
@@ -442,6 +454,12 @@ inline Poco::Logger& Application::logger() const
}
+inline const Application::ArgVec& Application::argv() const
+{
+ return _argv;
+}
+
+
inline const OptionSet& Application::options() const
{
return _options;
@@ -39,6 +39,7 @@
#include "Poco/Util/AbstractConfiguration.h"
#include "Poco/AutoPtr.h"
#include <iostream>
+#include <sstream>
using Poco::Util::Application;
@@ -154,12 +155,20 @@ class SampleApp: public Application
config().setString(name, value);
}
- int main(const std::vector<std::string>& args)
+ int main(const ArgVec& args)
{
if (!_helpRequested)
{
+ logger().information("Command line:");
+ const ArgVec argVec = argv();
+ std::ostringstream ostr;
+ for (ArgVec::const_iterator it = argVec.begin(); it != argVec.end(); ++it)
+ {
+ ostr << *it << ' ';
+ }
+ logger().information(ostr.str());
logger().information("Arguments to main():");
- for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
+ for (ArgVec::const_iterator it = args.begin(); it != args.end(); ++it)
{
logger().information(*it);
}
@@ -123,7 +123,7 @@ class SampleServer: public ServerApplication
helpFormatter.format(std::cout);
}
- int main(const std::vector<std::string>& args)
+ int main(const ArgVec& args)
{
if (!_helpRequested)
{
View
@@ -167,7 +167,7 @@ void Application::init(int argc, wchar_t* argv[])
#endif
-void Application::init(const std::vector<std::string>& args)
+void Application::init(const ArgVec& args)
{
setArgs(args);
init();
@@ -337,7 +337,7 @@ int Application::run()
{
initialize(*this);
rc = EXIT_SOFTWARE;
- rc = main(_args);
+ rc = main(_unprocessedArgs);
uninitialize();
}
catch (Poco::Exception& exc)
@@ -356,7 +356,7 @@ int Application::run()
}
-int Application::main(const std::vector<std::string>& args)
+int Application::main(const ArgVec& args)
{
return EXIT_OK;
}
@@ -366,24 +366,24 @@ void Application::setArgs(int argc, char* argv[])
{
_command = argv[0];
_pConfig->setInt("application.argc", argc);
- _args.reserve(argc);
+ _unprocessedArgs.reserve(argc);
std::string argvKey = "application.argv[";
for (int i = 0; i < argc; ++i)
{
std::string arg(argv[i]);
_pConfig->setString(argvKey + NumberFormatter::format(i) + "]", arg);
- _args.push_back(arg);
+ _unprocessedArgs.push_back(arg);
}
}
-void Application::setArgs(const std::vector<std::string>& args)
+void Application::setArgs(const ArgVec& args)
{
poco_assert (!args.empty());
_command = args[0];
_pConfig->setInt("application.argc", (int) args.size());
- _args = args;
+ _unprocessedArgs = args;
std::string argvKey = "application.argv[";
for (int i = 0; i < args.size(); ++i)
{
@@ -397,9 +397,10 @@ void Application::processOptions()
defineOptions(_options);
OptionProcessor processor(_options);
processor.setUnixStyle(_unixOptions);
- _args.erase(_args.begin());
- ArgVec::iterator it = _args.begin();
- while (it != _args.end() && !_stopOptionsProcessing)
+ _argv = _unprocessedArgs;
+ _unprocessedArgs.erase(_unprocessedArgs.begin());
+ ArgVec::iterator it = _unprocessedArgs.begin();
+ while (it != _unprocessedArgs.end() && !_stopOptionsProcessing)
{
std::string name;
std::string value;
@@ -409,7 +410,7 @@ void Application::processOptions()
{
handleOption(name, value);
}
- it = _args.erase(it);
+ it = _unprocessedArgs.erase(it);
}
else ++it;
}

0 comments on commit 7404c65

Please sign in to comment.