7#ifndef BOOST_NOWIDE_ARGS_HPP_INCLUDED
8#define BOOST_NOWIDE_ARGS_HPP_INCLUDED
10#include <boost/config.hpp>
12#include <boost/nowide/stackstring.hpp>
13#include <boost/nowide/windows.hpp>
20#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
26 args(
int&,
char**&,
char**&)
62 args(
int& argc,
char**& argv) :
63 old_argc_(argc), old_argv_(argv), old_env_(0), old_argc_ptr_(&argc), old_argv_ptr_(&argv), old_env_ptr_(0)
70 args(
int& argc,
char**& argv,
char**& env) :
71 old_argc_(argc), old_argv_(argv), old_env_(env), old_argc_ptr_(&argc), old_argv_ptr_(&argv),
83 *old_argc_ptr_ = old_argc_;
85 *old_argv_ptr_ = old_argv_;
87 *old_env_ptr_ = old_env_;
99 p = CommandLineToArgvW(GetCommandLineW(), &argc);
106 wargv_ptr(
const wargv_ptr&) =
delete;
107 wargv_ptr& operator=(
const wargv_ptr&) =
delete;
113 operator bool()
const
117 const wchar_t* operator[](
size_t i)
const
127 wenv_ptr() : p(GetEnvironmentStringsW())
132 FreeEnvironmentStringsW(p);
134 wenv_ptr(
const wenv_ptr&) =
delete;
135 wenv_ptr& operator=(
const wenv_ptr&) =
delete;
137 operator const wchar_t*()
const
143 void fix_args(
int& argc,
char**& argv)
145 const wargv_ptr wargv;
147 throw std::runtime_error(
"Could not get command line!");
148 args_.resize(wargv.size() + 1, 0);
149 arg_values_.resize(wargv.size());
150 for(
int i = 0; i < wargv.size(); i++)
151 args_[i] = arg_values_[i].convert(wargv[i]);
155 void fix_env(
char**& env)
157 const wenv_ptr wstrings;
159 throw std::runtime_error(
"Could not get environment strings!");
160 const wchar_t* wstrings_end = 0;
162 for(wstrings_end = wstrings; *wstrings_end; wstrings_end += wcslen(wstrings_end) + 1)
164 env_.
convert(wstrings, wstrings_end);
165 envp_.resize(count + 1, 0);
166 char* p = env_.
get();
168 for(
int i = 0; i < count; i++)
177 std::vector<char*> args_;
178 std::vector<short_stackstring> arg_values_;
180 std::vector<char*> envp_;
187 char*** old_argv_ptr_;
188 char*** old_env_ptr_;
args is a class that temporarily replaces standard main() function arguments with their equal,...
Definition: args.hpp:57
args(int &argc, char **&argv)
Definition: args.hpp:62
~args()
Definition: args.hpp:80
args(int &argc, char **&argv, char **&env)
Definition: args.hpp:70
output_char * convert(const input_char *input)
Definition: stackstring.hpp:91
output_char * get()
Return the converted, NULL-terminated string or NULL if no string was converted.
Definition: stackstring.hpp:126
size_t strlen(const Char *s)
Definition: convert.hpp:25
basic_stackstring< char, wchar_t, 256 > stackstring
Definition: stackstring.hpp:198