Import Geant4 10.3.0 source tree
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
#ifndef tools_args
|
||||
#define tools_args
|
||||
|
||||
#ifdef TOOLS_MEM
|
||||
#include "mem"
|
||||
#include "S_STRING"
|
||||
#endif
|
||||
|
||||
#include "sout"
|
||||
#include "strip"
|
||||
#include "words"
|
||||
@@ -16,11 +21,21 @@
|
||||
namespace tools {
|
||||
|
||||
class args {
|
||||
#ifdef TOOLS_MEM
|
||||
TOOLS_SCLASS(tools::args)
|
||||
#endif
|
||||
public:
|
||||
typedef std::pair<std::string,std::string> arg;
|
||||
public:
|
||||
args(){}
|
||||
args(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
args(int a_argc,char* a_argv[]){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
for(int index=0;index<a_argc;index++) {
|
||||
std::string s(a_argv[index]);
|
||||
std::string::size_type pos = s.find('=');
|
||||
@@ -34,17 +49,37 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
args(const std::vector<std::string>& a_args){add(a_args);}
|
||||
args(const std::vector<arg>& a_args):m_args(a_args){}
|
||||
args(const std::vector<std::string>& a_args){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
add(a_args);
|
||||
}
|
||||
args(const std::vector<arg>& a_args):m_args(a_args){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
//args(const std::string& a_args,const std::string& a_sep = " ",bool a_strip = false){
|
||||
args(const std::string& a_args,const std::string& a_sep,bool a_strip){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
std::vector<std::string> _args;
|
||||
words(a_args,a_sep,false,_args);
|
||||
add(_args,a_strip);
|
||||
}
|
||||
virtual ~args(){}
|
||||
virtual ~args(){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::decrement(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
args(const args& a_from):m_args(a_from.m_args){}
|
||||
args(const args& a_from):m_args(a_from.m_args){
|
||||
#ifdef TOOLS_MEM
|
||||
mem::increment(s_class().c_str());
|
||||
#endif
|
||||
}
|
||||
args& operator=(const args& a_from){
|
||||
m_args = a_from.m_args;
|
||||
return *this;
|
||||
@@ -59,8 +94,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
bool is_empty() const {return m_args.size()?false:true;}
|
||||
unsigned int size() const {return m_args.size();}
|
||||
unsigned int number() const {return m_args.size();} //back comp.
|
||||
size_t size() const {return m_args.size();}
|
||||
size_t number() const {return m_args.size();} //back comp.
|
||||
bool find(const std::string& a_key,std::string& a_value,const std::string& a_def = "") const {
|
||||
tools_vforcit(arg,m_args,it) {
|
||||
if((*it).first==a_key) {
|
||||
@@ -139,7 +174,7 @@ public:
|
||||
|
||||
void add_keyvals(const std::vector<std::string>& a_args,bool a_strip = false) {
|
||||
//a_args must contain an even number of strings.
|
||||
unsigned int sz_half = a_args.size()/2;
|
||||
size_t sz_half = a_args.size()/2;
|
||||
if((2*sz_half)!=a_args.size()) return;
|
||||
for(std::vector<std::string>::const_iterator it = a_args.begin();it!=a_args.end();it+=2) {
|
||||
if(a_strip) {
|
||||
@@ -159,7 +194,7 @@ public:
|
||||
}
|
||||
|
||||
int remove(const std::string& a_key){
|
||||
unsigned int nbeg = m_args.size();
|
||||
size_t nbeg = m_args.size();
|
||||
for(std::vector<arg>::iterator it = m_args.begin();it!=m_args.end();) {
|
||||
if(a_key==(*it).first) {
|
||||
it = m_args.erase(it);
|
||||
@@ -167,7 +202,7 @@ public:
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return nbeg - m_args.size();
|
||||
return int(nbeg) - int(m_args.size());
|
||||
}
|
||||
|
||||
void remove_first(){m_args.erase(m_args.begin());}
|
||||
@@ -202,25 +237,25 @@ public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> files(bool a_skip_first = true) const {
|
||||
|
||||
void files(std::vector<std::string>& a_files,bool a_skip_first = true) const {
|
||||
a_files.clear();
|
||||
// Get the serie of trailing args not beginning with '-'
|
||||
// and without a value (not of the form [-]xxx=yyy).
|
||||
// Note that an argument like that in between arguments
|
||||
// is NOT taken into account.
|
||||
std::vector<std::string> _files;
|
||||
if(m_args.empty()) return _files;
|
||||
if(m_args.empty()) return;
|
||||
std::vector<arg>::const_iterator it = m_args.begin();
|
||||
if(a_skip_first) it++;
|
||||
for(;it!=m_args.end();++it) {
|
||||
if( ((*it).first.find('-')==0) || (*it).second.size() ) {
|
||||
_files.clear();
|
||||
a_files.clear();
|
||||
} else {
|
||||
_files.push_back((*it).first);
|
||||
a_files.push_back((*it).first);
|
||||
}
|
||||
}
|
||||
return _files;
|
||||
}
|
||||
|
||||
bool argcv(int& a_argc,char**& a_argv) const {
|
||||
// If using with :
|
||||
// int argc;
|
||||
@@ -330,15 +365,11 @@ inline bool check_min(const std::vector<std::string>& a_args,unsigned int a_numb
|
||||
a_last.clear();
|
||||
} else {
|
||||
a_last = a_args[0];
|
||||
for(unsigned int index=1;index<a_args.size();index++) {
|
||||
a_last += " " + a_args[index];
|
||||
}
|
||||
for(size_t index=1;index<a_args.size();index++) a_last += " " + a_args[index];
|
||||
}
|
||||
} else {
|
||||
a_last = a_args[a_number-1];
|
||||
for(unsigned int index=a_number;index<a_args.size();index++) {
|
||||
a_last += " " + a_args[index];
|
||||
}
|
||||
for(size_t index=a_number;index<a_args.size();index++) a_last += " " + a_args[index];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -367,144 +398,6 @@ inline bool check_or_args(const std::vector<std::string>& aArgs,unsigned int a_1
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::string gui_toolkit(args& a_args,bool a_rm_in_args){
|
||||
std::string driver;
|
||||
a_args.find("-toolkit",driver);
|
||||
if(a_rm_in_args) a_args.remove("-toolkit");
|
||||
if(driver.empty()) {
|
||||
if(a_args.is_arg("-Xt")||
|
||||
a_args.is_arg("-xt")||
|
||||
a_args.is_arg("-Xm")||
|
||||
a_args.is_arg("-xm")||
|
||||
a_args.is_arg("-Motif")||
|
||||
a_args.is_arg("-motif")) {
|
||||
driver = "Xt";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-Xt");
|
||||
a_args.remove("-xt");
|
||||
a_args.remove("-Xm");
|
||||
a_args.remove("-xm");
|
||||
a_args.remove("-Motif");
|
||||
a_args.remove("-motif");
|
||||
}
|
||||
} else if(a_args.is_arg("-Win")||
|
||||
a_args.is_arg("-win")||
|
||||
a_args.is_arg("-Win32")||
|
||||
a_args.is_arg("-win32")) {
|
||||
driver = "Win";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-Win");
|
||||
a_args.remove("-win");
|
||||
a_args.remove("-Win32");
|
||||
a_args.remove("-win32");
|
||||
}
|
||||
} else if(a_args.is_arg("-NextStep")||
|
||||
a_args.is_arg("-nextstep")) {
|
||||
driver = "NextStep";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-NextStep");
|
||||
a_args.remove("-nextstep");
|
||||
}
|
||||
} else if(a_args.is_arg("-Gtk")||
|
||||
a_args.is_arg("-gtk")) {
|
||||
driver = "Gtk";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-Gtk");
|
||||
a_args.remove("-gtk");
|
||||
}
|
||||
} else if(a_args.is_arg("-Qt")||
|
||||
a_args.is_arg("-qt")) {
|
||||
driver = "Qt";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-Qt");
|
||||
a_args.remove("-qt");
|
||||
}
|
||||
} else if(a_args.is_arg("-SDL")||
|
||||
a_args.is_arg("-sdl")) {
|
||||
driver = "SDL";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-SDL");
|
||||
a_args.remove("-sdl");
|
||||
}
|
||||
} else if(a_args.is_arg("-Net")||
|
||||
a_args.is_arg("-net")) {
|
||||
driver = "Net";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-Net");
|
||||
a_args.remove("-net");
|
||||
}
|
||||
} else if(a_args.is_arg("-inex")) {
|
||||
driver = "inex";
|
||||
if(a_rm_in_args) {
|
||||
a_args.remove("-inex");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
inline void window_size_from_args(const args& a_args,unsigned int& a_ww,unsigned int& a_wh) {
|
||||
// return some common window size (in pixels).
|
||||
if(a_args.is_arg("-iPod")||a_args.is_arg("-iPhone")) {
|
||||
a_ww = 320;
|
||||
a_wh = 480;
|
||||
} else if(a_args.is_arg("-iPad")) {
|
||||
a_ww = 768;
|
||||
a_wh = 1024;
|
||||
} else if(a_args.is_arg("-iPhone4")) {
|
||||
a_ww = 640;
|
||||
a_wh = 960;
|
||||
} else if(a_args.is_arg("-wallino")) { //emulate LAL/wallino aspect ratio.
|
||||
a_ww = 1024;
|
||||
a_wh = 512;
|
||||
} else if(a_args.is_arg("-SGS")) { //Samsung Galaxy S
|
||||
//a_ww = 320;
|
||||
//a_wh = 533;
|
||||
a_ww = 480;
|
||||
a_wh = 800;
|
||||
} else {
|
||||
if(a_args.find<unsigned int>("-ww",a_ww)) {
|
||||
if(a_args.find<unsigned int>("-wh",a_wh)) return;
|
||||
//A4 : we have ww but not wh :
|
||||
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
|
||||
} else { //we don't have ww.
|
||||
if(a_args.find<unsigned int>("-wh",a_wh)) {
|
||||
//A4 : we have wh but not ww :
|
||||
a_ww = (unsigned int)(a_wh*(21.0f/29.7f));
|
||||
} else {
|
||||
//we have nothing. Take a ww of 700. With A4 wh is then 990.
|
||||
a_ww = 700;
|
||||
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
|
||||
}
|
||||
}
|
||||
}
|
||||
if(a_args.is_arg("-land")){
|
||||
unsigned int _ww = a_ww;
|
||||
unsigned int _wh = a_wh;
|
||||
a_ww = mx(_ww,_wh);
|
||||
a_wh = mn(_ww,_wh);
|
||||
}
|
||||
if(a_args.is_arg("-portrait")){
|
||||
unsigned int _ww = a_ww;
|
||||
unsigned int _wh = a_wh;
|
||||
a_ww = mn(_ww,_wh);
|
||||
a_wh = mx(_ww,_wh);
|
||||
}
|
||||
}
|
||||
|
||||
inline void remove_window_size_args(args& a_args) {
|
||||
//use with Wt apps.
|
||||
a_args.remove("-iPod");
|
||||
a_args.remove("-iPhone");
|
||||
a_args.remove("-iPad");
|
||||
a_args.remove("-iPhone4");
|
||||
a_args.remove("-SGS");
|
||||
a_args.remove("-ww");
|
||||
a_args.remove("-wh");
|
||||
a_args.remove("-land");
|
||||
}
|
||||
|
||||
inline std::vector<std::string> to(int a_argc,char** a_argv) {
|
||||
std::vector<std::string> v;
|
||||
for(int index=0;index<a_argc;index++) v.push_back(a_argv[index]);
|
||||
|
||||
Reference in New Issue
Block a user