mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 20:26:54 +08:00
Cleanup & indent .h files
This commit is contained in:
@@ -31,45 +31,67 @@ extern "C" {
|
||||
#include "trex.h"
|
||||
}
|
||||
|
||||
struct TRexParseException{TRexParseException(const TRexChar *c):desc(c){}const TRexChar *desc;};
|
||||
struct TRexParseException
|
||||
{
|
||||
TRexParseException(const TRexChar *c):desc(c) {} const TRexChar *desc;
|
||||
};
|
||||
|
||||
class TRexpp {
|
||||
public:
|
||||
TRexpp() { _exp = (TRex *)0; }
|
||||
~TRexpp() { CleanUp(); }
|
||||
// compiles a regular expression
|
||||
void Compile(const TRexChar *pattern) {
|
||||
const TRexChar *error;
|
||||
CleanUp();
|
||||
if(!(_exp = trex_compile(pattern,&error)))
|
||||
throw TRexParseException(error);
|
||||
}
|
||||
// return true if the given text match the expression
|
||||
bool Match(const TRexChar* text) {
|
||||
return _exp?(trex_match(_exp,text) != 0):false;
|
||||
}
|
||||
// Searches for the first match of the expression in a zero terminated string
|
||||
bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end) {
|
||||
return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false;
|
||||
}
|
||||
// Searches for the first match of the expression in a string sarting at text_begin and ending at text_end
|
||||
bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end) {
|
||||
return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false;
|
||||
}
|
||||
bool GetSubExp(int n, const TRexChar** out_begin, int *out_len)
|
||||
{
|
||||
TRexMatch match;
|
||||
TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False;
|
||||
if(res) {
|
||||
*out_begin = match.begin;
|
||||
*out_len = match.len;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int GetSubExpCount() { return _exp?trex_getsubexpcount(_exp):0; }
|
||||
private:
|
||||
void CleanUp() { if(_exp) trex_free(_exp); _exp = (TRex *)0; }
|
||||
TRex *_exp;
|
||||
class TRexpp
|
||||
{
|
||||
public:
|
||||
TRexpp()
|
||||
{
|
||||
_exp = (TRex *)0;
|
||||
}
|
||||
~TRexpp()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
// compiles a regular expression
|
||||
void Compile(const TRexChar *pattern)
|
||||
{
|
||||
const TRexChar *error;
|
||||
CleanUp();
|
||||
if(!(_exp = trex_compile(pattern,&error)))
|
||||
throw TRexParseException(error);
|
||||
}
|
||||
// return true if the given text match the expression
|
||||
bool Match(const TRexChar* text)
|
||||
{
|
||||
return _exp?(trex_match(_exp,text) != 0):false;
|
||||
}
|
||||
// Searches for the first match of the expression in a zero terminated string
|
||||
bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end)
|
||||
{
|
||||
return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false;
|
||||
}
|
||||
// Searches for the first match of the expression in a string sarting at text_begin and ending at text_end
|
||||
bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end)
|
||||
{
|
||||
return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false;
|
||||
}
|
||||
bool GetSubExp(int n, const TRexChar** out_begin, int *out_len)
|
||||
{
|
||||
TRexMatch match;
|
||||
TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False;
|
||||
if(res)
|
||||
{
|
||||
*out_begin = match.begin;
|
||||
*out_len = match.len;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int GetSubExpCount()
|
||||
{
|
||||
return _exp?trex_getsubexpcount(_exp):0;
|
||||
}
|
||||
private:
|
||||
void CleanUp()
|
||||
{
|
||||
if(_exp) trex_free(_exp);
|
||||
_exp = (TRex *)0;
|
||||
}
|
||||
TRex *_exp;
|
||||
};
|
||||
#endif //_TREXPP_H_
|
||||
|
@@ -37,8 +37,8 @@ struct AlprPlate
|
||||
|
||||
struct AlprCoordinate
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
class AlprResult
|
||||
|
@@ -32,9 +32,9 @@ using namespace cv;
|
||||
|
||||
enum NiblackVersion
|
||||
{
|
||||
NIBLACK=0,
|
||||
SAUVOLA,
|
||||
WOLFJOLION,
|
||||
NIBLACK=0,
|
||||
SAUVOLA,
|
||||
WOLFJOLION,
|
||||
};
|
||||
|
||||
#define BINARIZEWOLF_VERSION "2.3 (February 26th, 2013)"
|
||||
@@ -49,7 +49,7 @@ enum NiblackVersion
|
||||
|
||||
|
||||
void NiblackSauvolaWolfJolion (Mat im, Mat output, NiblackVersion version,
|
||||
int winx, int winy, float k);
|
||||
int winx, int winy, float k);
|
||||
|
||||
|
||||
|
||||
|
@@ -24,8 +24,7 @@
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* cJSON Types: */
|
||||
@@ -40,22 +39,24 @@ extern "C"
|
||||
#define cJSON_IsReference 256
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON {
|
||||
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
typedef struct cJSON
|
||||
{
|
||||
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
|
||||
int type; /* The type of the item, as above. */
|
||||
int type; /* The type of the item, as above. */
|
||||
|
||||
char *valuestring; /* The item's string, if type==cJSON_String */
|
||||
int valueint; /* The item's number, if type==cJSON_Number */
|
||||
double valuedouble; /* The item's number, if type==cJSON_Number */
|
||||
char *valuestring; /* The item's string, if type==cJSON_String */
|
||||
int valueint; /* The item's number, if type==cJSON_Number */
|
||||
double valuedouble; /* The item's number, if type==cJSON_Number */
|
||||
|
||||
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks {
|
||||
void *(*malloc_fn)(size_t sz);
|
||||
void (*free_fn)(void *ptr);
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
void *(*malloc_fn)(size_t sz);
|
||||
void (*free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
|
@@ -110,7 +110,7 @@ class Config
|
||||
string getPostProcessRuntimeDir();
|
||||
string getTessdataPrefix();
|
||||
|
||||
private:
|
||||
private:
|
||||
CSimpleIniA* ini;
|
||||
|
||||
string runtimeBaseDir;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#define POSTPROCESS_DIR "/postprocess"
|
||||
|
||||
#ifndef DEFAULT_RUNTIME_DIR
|
||||
#define DEFAULT_RUNTIME_DIR "/default_runtime_data_dir/"
|
||||
#define DEFAULT_RUNTIME_DIR "/default_runtime_data_dir/"
|
||||
#endif
|
||||
|
||||
#define ENV_VARIABLE_RUNTIME_DIR "OPENALPR_RUNTIME_DIR"
|
||||
|
@@ -38,7 +38,8 @@ using namespace std;
|
||||
|
||||
|
||||
|
||||
struct RecognitionResult {
|
||||
struct RecognitionResult
|
||||
{
|
||||
bool haswinner;
|
||||
string winner;
|
||||
int confidence;
|
||||
@@ -54,7 +55,7 @@ class FeatureMatcher
|
||||
|
||||
|
||||
RecognitionResult recognize( const Mat& queryImg, bool drawOnImage, Mat* outputImage,
|
||||
bool debug_on, vector<int> debug_matches_array );
|
||||
bool debug_on, vector<int> debug_matches_array );
|
||||
|
||||
|
||||
bool loadRecognitionSet(string country);
|
||||
@@ -83,7 +84,7 @@ class FeatureMatcher
|
||||
|
||||
|
||||
void surfStyleMatching( const Mat& queryDescriptors, vector<KeyPoint> queryKeypoints,
|
||||
vector<DMatch>& matches12 );
|
||||
vector<DMatch>& matches12 );
|
||||
|
||||
};
|
||||
|
||||
|
@@ -23,8 +23,8 @@
|
||||
#ifndef OCR_H
|
||||
#define OCR_H
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utility.h"
|
||||
#include "postprocess.h"
|
||||
|
@@ -21,13 +21,13 @@
|
||||
#ifndef POSTPROCESS_H
|
||||
#define POSTPROCESS_H
|
||||
|
||||
#include "TRexpp.h"
|
||||
#include "constants.h"
|
||||
#include "utility.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include "TRexpp.h"
|
||||
#include "constants.h"
|
||||
#include "utility.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include "config.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -37,17 +37,17 @@ using namespace std;
|
||||
|
||||
struct Letter
|
||||
{
|
||||
char letter;
|
||||
int charposition;
|
||||
float totalscore;
|
||||
int occurences;
|
||||
char letter;
|
||||
int charposition;
|
||||
float totalscore;
|
||||
int occurences;
|
||||
};
|
||||
|
||||
struct PPResult
|
||||
{
|
||||
string letters;
|
||||
float totalscore;
|
||||
bool matchesTemplate;
|
||||
string letters;
|
||||
float totalscore;
|
||||
bool matchesTemplate;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -99,16 +99,18 @@ typedef unsigned char Boolean; /* 0 or 1 */
|
||||
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
||||
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
||||
|
||||
typedef enum {
|
||||
conversionOK, /* conversion successful */
|
||||
sourceExhausted, /* partial character in source, but hit end */
|
||||
targetExhausted, /* insuff. room in target for conversion */
|
||||
sourceIllegal /* source sequence is illegal/malformed */
|
||||
typedef enum
|
||||
{
|
||||
conversionOK, /* conversion successful */
|
||||
sourceExhausted, /* partial character in source, but hit end */
|
||||
targetExhausted, /* insuff. room in target for conversion */
|
||||
sourceIllegal /* source sequence is illegal/malformed */
|
||||
} ConversionResult;
|
||||
|
||||
typedef enum {
|
||||
strictConversion = 0,
|
||||
lenientConversion
|
||||
typedef enum
|
||||
{
|
||||
strictConversion = 0,
|
||||
lenientConversion
|
||||
} ConversionFlags;
|
||||
|
||||
/* This is for C++ and does no harm in C */
|
||||
@@ -117,28 +119,28 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
ConversionResult ConvertUTF8toUTF16 (
|
||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
||||
|
||||
ConversionResult ConvertUTF16toUTF8 (
|
||||
const UTF16** sourceStart, const UTF16* sourceEnd,
|
||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||
const UTF16** sourceStart, const UTF16* sourceEnd,
|
||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||
|
||||
ConversionResult ConvertUTF8toUTF32 (
|
||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
||||
const UTF8** sourceStart, const UTF8* sourceEnd,
|
||||
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
||||
|
||||
ConversionResult ConvertUTF32toUTF8 (
|
||||
const UTF32** sourceStart, const UTF32* sourceEnd,
|
||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||
const UTF32** sourceStart, const UTF32* sourceEnd,
|
||||
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
|
||||
|
||||
ConversionResult ConvertUTF16toUTF32 (
|
||||
const UTF16** sourceStart, const UTF16* sourceEnd,
|
||||
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
||||
const UTF16** sourceStart, const UTF16* sourceEnd,
|
||||
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
|
||||
|
||||
ConversionResult ConvertUTF32toUTF16 (
|
||||
const UTF32** sourceStart, const UTF32* sourceEnd,
|
||||
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
||||
const UTF32** sourceStart, const UTF32* sourceEnd,
|
||||
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
|
||||
|
||||
Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -4,12 +4,12 @@
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include "windows/dirent.h"
|
||||
#include "windows/utils.h"
|
||||
#include "windows/unistd_partial.h"
|
||||
#include "windows/dirent.h"
|
||||
#include "windows/utils.h"
|
||||
#include "windows/unistd_partial.h"
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
bool hasEnding (std::string const &fullString, std::string const &ending);
|
||||
bool DirectoryExists( const char* pzPath );
|
||||
bool fileExists( const char* pzPath );
|
||||
std::vector<std::string> getFilesInDir(const char* dirPath);
|
||||
bool hasEnding (std::string const &fullString, std::string const &ending);
|
||||
bool DirectoryExists( const char* pzPath );
|
||||
bool fileExists( const char* pzPath );
|
||||
std::vector<std::string> getFilesInDir(const char* dirPath);
|
||||
|
||||
bool stringCompare( const std::string &left, const std::string &right );
|
||||
bool stringCompare( const std::string &left, const std::string &right );
|
||||
|
||||
|
||||
#endif // FILESYSTEM_H
|
||||
|
@@ -11,13 +11,13 @@
|
||||
|
||||
// Support for Windows
|
||||
#ifdef WINDOWS
|
||||
#include <windows.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define timespec timeval
|
||||
#define timespec timeval
|
||||
#endif
|
||||
|
||||
void getTime(timespec* time);
|
||||
double diffclock(timespec time1,timespec time2);
|
||||
void getTime(timespec* time);
|
||||
double diffclock(timespec time1,timespec time2);
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -61,30 +61,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
char name[_TINYDIR_FILENAME_MAX];
|
||||
int is_dir;
|
||||
int is_reg;
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
char name[_TINYDIR_FILENAME_MAX];
|
||||
int is_dir;
|
||||
int is_reg;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
struct stat _s;
|
||||
struct stat _s;
|
||||
#endif
|
||||
} tinydir_file;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
int has_next;
|
||||
int n_files;
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
int has_next;
|
||||
int n_files;
|
||||
|
||||
tinydir_file *_files;
|
||||
tinydir_file *_files;
|
||||
#ifdef _MSC_VER
|
||||
HANDLE _h;
|
||||
WIN32_FIND_DATA _f;
|
||||
HANDLE _h;
|
||||
WIN32_FIND_DATA _f;
|
||||
#else
|
||||
DIR *_d;
|
||||
struct dirent *_e;
|
||||
DIR *_d;
|
||||
struct dirent *_e;
|
||||
#endif
|
||||
} tinydir_dir;
|
||||
|
||||
@@ -116,308 +116,288 @@ int _tinydir_file_cmp(const void *a, const void *b);
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_open(tinydir_dir *dir, const char *path)
|
||||
{
|
||||
if (dir == NULL || path == NULL || strlen(path) == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* initialise dir */
|
||||
dir->_files = NULL;
|
||||
if (dir == NULL || path == NULL || strlen(path) == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
/* initialise dir */
|
||||
dir->_files = NULL;
|
||||
#ifdef _MSC_VER
|
||||
dir->_h = INVALID_HANDLE_VALUE;
|
||||
dir->_h = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
dir->_d = NULL;
|
||||
dir->_d = NULL;
|
||||
#endif
|
||||
tinydir_close(dir);
|
||||
|
||||
strcpy(dir->path, path);
|
||||
tinydir_close(dir);
|
||||
strcpy(dir->path, path);
|
||||
#ifdef _MSC_VER
|
||||
strcat(dir->path, "\\*");
|
||||
dir->_h = FindFirstFile(dir->path, &dir->_f);
|
||||
dir->path[strlen(dir->path) - 2] = '\0';
|
||||
if (dir->_h == INVALID_HANDLE_VALUE)
|
||||
strcat(dir->path, "\\*");
|
||||
dir->_h = FindFirstFile(dir->path, &dir->_f);
|
||||
dir->path[strlen(dir->path) - 2] = '\0';
|
||||
if (dir->_h == INVALID_HANDLE_VALUE)
|
||||
#else
|
||||
dir->_d = opendir(path);
|
||||
if (dir->_d == NULL)
|
||||
dir->_d = opendir(path);
|
||||
if (dir->_d == NULL)
|
||||
#endif
|
||||
{
|
||||
errno = ENOENT;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* read first file */
|
||||
dir->has_next = 1;
|
||||
{
|
||||
errno = ENOENT;
|
||||
goto bail;
|
||||
}
|
||||
/* read first file */
|
||||
dir->has_next = 1;
|
||||
#ifndef _MSC_VER
|
||||
dir->_e = readdir(dir->_d);
|
||||
if (dir->_e == NULL)
|
||||
{
|
||||
dir->has_next = 0;
|
||||
}
|
||||
dir->_e = readdir(dir->_d);
|
||||
if (dir->_e == NULL)
|
||||
{
|
||||
dir->has_next = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
bail:
|
||||
tinydir_close(dir);
|
||||
return -1;
|
||||
tinydir_close(dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_open_sorted(tinydir_dir *dir, const char *path)
|
||||
{
|
||||
if (tinydir_open(dir, path) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
dir->n_files = 0;
|
||||
while (dir->has_next)
|
||||
{
|
||||
tinydir_file *p_file;
|
||||
dir->n_files++;
|
||||
dir->_files = (tinydir_file *)realloc(dir->_files, sizeof(tinydir_file)*dir->n_files);
|
||||
if (dir->_files == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
p_file = &dir->_files[dir->n_files - 1];
|
||||
if (tinydir_readfile(dir, p_file) == -1)
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (tinydir_next(dir) == -1)
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp);
|
||||
|
||||
return 0;
|
||||
|
||||
if (tinydir_open(dir, path) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
dir->n_files = 0;
|
||||
while (dir->has_next)
|
||||
{
|
||||
tinydir_file *p_file;
|
||||
dir->n_files++;
|
||||
dir->_files = (tinydir_file *)realloc(dir->_files, sizeof(tinydir_file)*dir->n_files);
|
||||
if (dir->_files == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
goto bail;
|
||||
}
|
||||
p_file = &dir->_files[dir->n_files - 1];
|
||||
if (tinydir_readfile(dir, p_file) == -1)
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
if (tinydir_next(dir) == -1)
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp);
|
||||
return 0;
|
||||
bail:
|
||||
tinydir_close(dir);
|
||||
return -1;
|
||||
tinydir_close(dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
void tinydir_close(tinydir_dir *dir)
|
||||
{
|
||||
if (dir == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(dir->path, 0, sizeof(dir->path));
|
||||
dir->has_next = 0;
|
||||
dir->n_files = -1;
|
||||
if (dir->_files != NULL)
|
||||
{
|
||||
free(dir->_files);
|
||||
}
|
||||
dir->_files = NULL;
|
||||
if (dir == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
memset(dir->path, 0, sizeof(dir->path));
|
||||
dir->has_next = 0;
|
||||
dir->n_files = -1;
|
||||
if (dir->_files != NULL)
|
||||
{
|
||||
free(dir->_files);
|
||||
}
|
||||
dir->_files = NULL;
|
||||
#ifdef _MSC_VER
|
||||
if (dir->_h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose(dir->_h);
|
||||
}
|
||||
dir->_h = INVALID_HANDLE_VALUE;
|
||||
if (dir->_h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose(dir->_h);
|
||||
}
|
||||
dir->_h = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
if (dir->_d)
|
||||
{
|
||||
closedir(dir->_d);
|
||||
}
|
||||
dir->_d = NULL;
|
||||
dir->_e = NULL;
|
||||
if (dir->_d)
|
||||
{
|
||||
closedir(dir->_d);
|
||||
}
|
||||
dir->_d = NULL;
|
||||
dir->_e = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_next(tinydir_dir *dir)
|
||||
{
|
||||
if (dir == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!dir->has_next)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!dir->has_next)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
if (FindNextFile(dir->_h, &dir->_f) == 0)
|
||||
if (FindNextFile(dir->_h, &dir->_f) == 0)
|
||||
#else
|
||||
dir->_e = readdir(dir->_d);
|
||||
if (dir->_e == NULL)
|
||||
dir->_e = readdir(dir->_d);
|
||||
if (dir->_e == NULL)
|
||||
#endif
|
||||
{
|
||||
dir->has_next = 0;
|
||||
{
|
||||
dir->has_next = 0;
|
||||
#ifdef _MSC_VER
|
||||
if (GetLastError() != ERROR_SUCCESS &&
|
||||
GetLastError() != ERROR_NO_MORE_FILES)
|
||||
{
|
||||
tinydir_close(dir);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
if (GetLastError() != ERROR_SUCCESS &&
|
||||
GetLastError() != ERROR_NO_MORE_FILES)
|
||||
{
|
||||
tinydir_close(dir);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
||||
{
|
||||
if (dir == NULL || file == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (dir == NULL || file == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
if (dir->_h == INVALID_HANDLE_VALUE)
|
||||
if (dir->_h == INVALID_HANDLE_VALUE)
|
||||
#else
|
||||
if (dir->_e == NULL)
|
||||
if (dir->_e == NULL)
|
||||
#endif
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(dir->path) +
|
||||
strlen(
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(dir->path) +
|
||||
strlen(
|
||||
#ifdef _MSC_VER
|
||||
dir->_f.cFileName
|
||||
dir->_f.cFileName
|
||||
#else
|
||||
dir->_e->d_name
|
||||
dir->_e->d_name
|
||||
#endif
|
||||
) + 1 + _TINYDIR_PATH_EXTRA >=
|
||||
_TINYDIR_PATH_MAX)
|
||||
{
|
||||
/* the path for the file will be too long */
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(
|
||||
) + 1 + _TINYDIR_PATH_EXTRA >=
|
||||
_TINYDIR_PATH_MAX)
|
||||
{
|
||||
/* the path for the file will be too long */
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(
|
||||
#ifdef _MSC_VER
|
||||
dir->_f.cFileName
|
||||
dir->_f.cFileName
|
||||
#else
|
||||
dir->_e->d_name
|
||||
dir->_e->d_name
|
||||
#endif
|
||||
) >= _TINYDIR_FILENAME_MAX)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(file->path, dir->path);
|
||||
strcat(file->path, "/");
|
||||
strcpy(file->name,
|
||||
) >= _TINYDIR_FILENAME_MAX)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
strcpy(file->path, dir->path);
|
||||
strcat(file->path, "/");
|
||||
strcpy(file->name,
|
||||
#ifdef _MSC_VER
|
||||
dir->_f.cFileName
|
||||
dir->_f.cFileName
|
||||
#else
|
||||
dir->_e->d_name
|
||||
dir->_e->d_name
|
||||
#endif
|
||||
);
|
||||
strcat(file->path, file->name);
|
||||
);
|
||||
strcat(file->path, file->name);
|
||||
#ifndef _MSC_VER
|
||||
if (stat(file->path, &file->_s) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (stat(file->path, &file->_s) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
file->is_dir =
|
||||
file->is_dir =
|
||||
#ifdef _MSC_VER
|
||||
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
#else
|
||||
S_ISDIR(file->_s.st_mode);
|
||||
S_ISDIR(file->_s.st_mode);
|
||||
#endif
|
||||
file->is_reg =
|
||||
file->is_reg =
|
||||
#ifdef _MSC_VER
|
||||
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ||
|
||||
(
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) &&
|
||||
!!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ||
|
||||
(
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) &&
|
||||
#ifdef FILE_ATTRIBUTE_INTEGRITY_STREAM
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_INTEGRITY_STREAM) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_INTEGRITY_STREAM) &&
|
||||
#endif
|
||||
#ifdef FILE_ATTRIBUTE_NO_SCRUB_DATA
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NO_SCRUB_DATA) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NO_SCRUB_DATA) &&
|
||||
#endif
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY));
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) &&
|
||||
!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY));
|
||||
#else
|
||||
S_ISREG(file->_s.st_mode);
|
||||
S_ISREG(file->_s.st_mode);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, int i)
|
||||
{
|
||||
if (dir == NULL || file == NULL || i < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (i >= dir->n_files)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
|
||||
|
||||
return 0;
|
||||
if (dir == NULL || file == NULL || i < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (i >= dir->n_files)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
|
||||
return 0;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int tinydir_open_subdir_n(tinydir_dir *dir, int i)
|
||||
{
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
if (dir == NULL || i < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (i >= dir->n_files || !dir->_files[i].is_dir)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(path, dir->_files[i].path);
|
||||
tinydir_close(dir);
|
||||
if (tinydir_open_sorted(dir, path) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
char path[_TINYDIR_PATH_MAX];
|
||||
if (dir == NULL || i < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (i >= dir->n_files || !dir->_files[i].is_dir)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
strcpy(path, dir->_files[i].path);
|
||||
tinydir_close(dir);
|
||||
if (tinydir_open_sorted(dir, path) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_TINYDIR_FUNC
|
||||
int _tinydir_file_cmp(const void *a, const void *b)
|
||||
{
|
||||
const tinydir_file *fa = (const tinydir_file *)a;
|
||||
const tinydir_file *fb = (const tinydir_file *)b;
|
||||
if (fa->is_dir != fb->is_dir)
|
||||
{
|
||||
return -(fa->is_dir - fb->is_dir);
|
||||
}
|
||||
return strncasecmp(fa->name, fb->name, _TINYDIR_FILENAME_MAX);
|
||||
const tinydir_file *fa = (const tinydir_file *)a;
|
||||
const tinydir_file *fb = (const tinydir_file *)b;
|
||||
if (fa->is_dir != fb->is_dir)
|
||||
{
|
||||
return -(fa->is_dir - fb->is_dir);
|
||||
}
|
||||
return strncasecmp(fa->name, fb->name, _TINYDIR_FILENAME_MAX);
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@@ -3,5 +3,5 @@
|
||||
|
||||
static inline double round(double val)
|
||||
{
|
||||
return floor(val + 0.5);
|
||||
return floor(val + 0.5);
|
||||
}
|
||||
|
@@ -51,9 +51,10 @@
|
||||
typedef unsigned int TRexBool;
|
||||
typedef struct TRex TRex;
|
||||
|
||||
typedef struct {
|
||||
const TRexChar *begin;
|
||||
int len;
|
||||
typedef struct
|
||||
{
|
||||
const TRexChar *begin;
|
||||
int len;
|
||||
} TRexMatch;
|
||||
|
||||
TREX_API TRex *trex_compile(const TRexChar *pattern,const TRexChar **error);
|
||||
|
@@ -32,8 +32,8 @@
|
||||
|
||||
#include "constants.h"
|
||||
#include "support/timing.h"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "binarize_wolf.h"
|
||||
#include <vector>
|
||||
@@ -41,13 +41,13 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
struct LineSegment
|
||||
{
|
||||
float x1;
|
||||
float y1;
|
||||
float x2;
|
||||
float y2;
|
||||
float x1;
|
||||
float y1;
|
||||
float x2;
|
||||
float y2;
|
||||
};
|
||||
*/
|
||||
|
||||
@@ -61,7 +61,7 @@ class LineSegment
|
||||
float length;
|
||||
float angle;
|
||||
|
||||
// LineSegment(Point point1, Point point2);
|
||||
// LineSegment(Point point1, Point point2);
|
||||
LineSegment();
|
||||
LineSegment(int x1, int y1, int x2, int y2);
|
||||
LineSegment(Point p1, Point p2);
|
||||
@@ -90,30 +90,30 @@ class LineSegment
|
||||
|
||||
};
|
||||
|
||||
double median(int array[], int arraySize);
|
||||
double median(int array[], int arraySize);
|
||||
|
||||
vector<Mat> produceThresholds(const Mat img_gray, Config* config);
|
||||
vector<Mat> produceThresholds(const Mat img_gray, Config* config);
|
||||
|
||||
Mat drawImageDashboard(vector<Mat> images, int imageType, int numColumns);
|
||||
Mat drawImageDashboard(vector<Mat> images, int imageType, int numColumns);
|
||||
|
||||
void displayImage(Config* config, string windowName, cv::Mat frame);
|
||||
void drawAndWait(cv::Mat* frame);
|
||||
void displayImage(Config* config, string windowName, cv::Mat frame);
|
||||
void drawAndWait(cv::Mat* frame);
|
||||
|
||||
double distanceBetweenPoints(Point p1, Point p2);
|
||||
double distanceBetweenPoints(Point p1, Point p2);
|
||||
|
||||
void drawRotatedRect(Mat* img, RotatedRect rect, Scalar color, int thickness);
|
||||
void drawRotatedRect(Mat* img, RotatedRect rect, Scalar color, int thickness);
|
||||
|
||||
void drawX(Mat img, Rect rect, Scalar color, int thickness);
|
||||
void fillMask(Mat img, const Mat mask, Scalar color);
|
||||
void drawX(Mat img, Rect rect, Scalar color, int thickness);
|
||||
void fillMask(Mat img, const Mat mask, Scalar color);
|
||||
|
||||
float angleBetweenPoints(Point p1, Point p2);
|
||||
float angleBetweenPoints(Point p1, Point p2);
|
||||
|
||||
Size getSizeMaintainingAspect(Mat inputImg, int maxWidth, int maxHeight);
|
||||
Size getSizeMaintainingAspect(Mat inputImg, int maxWidth, int maxHeight);
|
||||
|
||||
Mat equalizeBrightness(Mat img);
|
||||
Mat equalizeBrightness(Mat img);
|
||||
|
||||
Rect expandRect(Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
|
||||
Rect expandRect(Rect original, int expandXPixels, int expandYPixels, int maxX, int maxY);
|
||||
|
||||
Mat addLabel(Mat input, string label);
|
||||
Mat addLabel(Mat input, string label);
|
||||
|
||||
#endif // UTILITY_H
|
||||
|
@@ -29,10 +29,10 @@ using namespace std;
|
||||
|
||||
struct Valley
|
||||
{
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
int width;
|
||||
int pixelsWithin;
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
int width;
|
||||
int pixelsWithin;
|
||||
};
|
||||
|
||||
enum HistogramDirection { RISING, FALLING, FLAT };
|
||||
|
854
src/tclap/Arg.h
854
src/tclap/Arg.h
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,8 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A simple class that defines and argument exception. Should be caught
|
||||
@@ -35,82 +36,85 @@ namespace TCLAP {
|
||||
*/
|
||||
class ArgException : public std::exception
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source.
|
||||
* \param td - Text describing the type of ArgException it is.
|
||||
* of the exception.
|
||||
*/
|
||||
ArgException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined",
|
||||
const std::string& td = "Generic ArgException")
|
||||
: std::exception(),
|
||||
_errorText(text),
|
||||
_argId( id ),
|
||||
_typeDescription(td)
|
||||
{ }
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source.
|
||||
* \param td - Text describing the type of ArgException it is.
|
||||
* of the exception.
|
||||
*/
|
||||
ArgException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined",
|
||||
const std::string& td = "Generic ArgException")
|
||||
: std::exception(),
|
||||
_errorText(text),
|
||||
_argId( id ),
|
||||
_typeDescription(td)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~ArgException() throw() { }
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~ArgException() throw() { }
|
||||
|
||||
/**
|
||||
* Returns the error text.
|
||||
*/
|
||||
std::string error() const { return ( _errorText ); }
|
||||
/**
|
||||
* Returns the error text.
|
||||
*/
|
||||
std::string error() const
|
||||
{
|
||||
return ( _errorText );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument id.
|
||||
*/
|
||||
std::string argId() const
|
||||
{
|
||||
if ( _argId == "undefined" )
|
||||
return " ";
|
||||
else
|
||||
return ( "Argument: " + _argId );
|
||||
}
|
||||
/**
|
||||
* Returns the argument id.
|
||||
*/
|
||||
std::string argId() const
|
||||
{
|
||||
if ( _argId == "undefined" )
|
||||
return " ";
|
||||
else
|
||||
return ( "Argument: " + _argId );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arg id and error text.
|
||||
*/
|
||||
const char* what() const throw()
|
||||
{
|
||||
static std::string ex;
|
||||
ex = _argId + " -- " + _errorText;
|
||||
return ex.c_str();
|
||||
}
|
||||
/**
|
||||
* Returns the arg id and error text.
|
||||
*/
|
||||
const char* what() const throw()
|
||||
{
|
||||
static std::string ex;
|
||||
ex = _argId + " -- " + _errorText;
|
||||
return ex.c_str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the exception. Used to explain and distinguish
|
||||
* between different child exceptions.
|
||||
*/
|
||||
std::string typeDescription() const
|
||||
{
|
||||
return _typeDescription;
|
||||
}
|
||||
/**
|
||||
* Returns the type of the exception. Used to explain and distinguish
|
||||
* between different child exceptions.
|
||||
*/
|
||||
std::string typeDescription() const
|
||||
{
|
||||
return _typeDescription;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/**
|
||||
* The text of the exception message.
|
||||
*/
|
||||
std::string _errorText;
|
||||
/**
|
||||
* The text of the exception message.
|
||||
*/
|
||||
std::string _errorText;
|
||||
|
||||
/**
|
||||
* The argument related to this exception.
|
||||
*/
|
||||
std::string _argId;
|
||||
/**
|
||||
* The argument related to this exception.
|
||||
*/
|
||||
std::string _argId;
|
||||
|
||||
/**
|
||||
* Describes the type of the exception. Used to distinguish
|
||||
* between different child exceptions.
|
||||
*/
|
||||
std::string _typeDescription;
|
||||
/**
|
||||
* Describes the type of the exception. Used to distinguish
|
||||
* between different child exceptions.
|
||||
*/
|
||||
std::string _typeDescription;
|
||||
|
||||
};
|
||||
|
||||
@@ -120,20 +124,20 @@ class ArgException : public std::exception
|
||||
*/
|
||||
class ArgParseException : public ArgException
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
ArgParseException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string( "Exception found while parsing " ) +
|
||||
std::string( "the value the Arg has been passed." ))
|
||||
{ }
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
ArgParseException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string( "Exception found while parsing " ) +
|
||||
std::string( "the value the Arg has been passed." ))
|
||||
{ }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -142,22 +146,22 @@ class ArgParseException : public ArgException
|
||||
*/
|
||||
class CmdLineParseException : public ArgException
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
CmdLineParseException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string( "Exception found when the values ") +
|
||||
std::string( "on the command line do not meet ") +
|
||||
std::string( "the requirements of the defined ") +
|
||||
std::string( "Args." ))
|
||||
{ }
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
CmdLineParseException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string( "Exception found when the values ") +
|
||||
std::string( "on the command line do not meet ") +
|
||||
std::string( "the requirements of the defined ") +
|
||||
std::string( "Args." ))
|
||||
{ }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -166,32 +170,36 @@ class CmdLineParseException : public ArgException
|
||||
*/
|
||||
class SpecificationException : public ArgException
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
SpecificationException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string("Exception found when an Arg object ")+
|
||||
std::string("is improperly defined by the ") +
|
||||
std::string("developer." ))
|
||||
{ }
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* \param text - The text of the exception.
|
||||
* \param id - The text identifying the argument source
|
||||
* of the exception.
|
||||
*/
|
||||
SpecificationException( const std::string& text = "undefined exception",
|
||||
const std::string& id = "undefined" )
|
||||
: ArgException( text,
|
||||
id,
|
||||
std::string("Exception found when an Arg object ")+
|
||||
std::string("is improperly defined by the ") +
|
||||
std::string("developer." ))
|
||||
{ }
|
||||
|
||||
};
|
||||
|
||||
class ExitException {
|
||||
public:
|
||||
ExitException(int estat) : _estat(estat) {}
|
||||
class ExitException
|
||||
{
|
||||
public:
|
||||
ExitException(int estat) : _estat(estat) {}
|
||||
|
||||
int getExitStatus() const { return _estat; }
|
||||
int getExitStatus() const
|
||||
{
|
||||
return _estat;
|
||||
}
|
||||
|
||||
private:
|
||||
int _estat;
|
||||
private:
|
||||
int _estat;
|
||||
};
|
||||
|
||||
} // namespace TCLAP
|
||||
|
@@ -26,7 +26,8 @@
|
||||
#ifndef TCLAP_ARGTRAITS_H
|
||||
#define TCLAP_ARGTRAITS_H
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
// We use two empty structs to get compile type specialization
|
||||
// function to work
|
||||
@@ -35,9 +36,10 @@ namespace TCLAP {
|
||||
* A value like argument value type is a value that can be set using
|
||||
* operator>>. This is the default value type.
|
||||
*/
|
||||
struct ValueLike {
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLike() {}
|
||||
struct ValueLike
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLike() {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -45,8 +47,9 @@ struct ValueLike {
|
||||
* operator=(string). Usefull if the value type contains spaces which
|
||||
* will be broken up into individual tokens by operator>>.
|
||||
*/
|
||||
struct StringLike {
|
||||
virtual ~StringLike() {}
|
||||
struct StringLike
|
||||
{
|
||||
virtual ~StringLike() {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -54,9 +57,10 @@ struct StringLike {
|
||||
* traits. This is a compile time thing and does not add any overhead
|
||||
* to the inherenting class.
|
||||
*/
|
||||
struct StringLikeTrait {
|
||||
typedef StringLike ValueCategory;
|
||||
virtual ~StringLikeTrait() {}
|
||||
struct StringLikeTrait
|
||||
{
|
||||
typedef StringLike ValueCategory;
|
||||
virtual ~StringLikeTrait() {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -64,9 +68,10 @@ struct StringLikeTrait {
|
||||
* traits. This is a compile time thing and does not add any overhead
|
||||
* to the inherenting class.
|
||||
*/
|
||||
struct ValueLikeTrait {
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLikeTrait() {}
|
||||
struct ValueLikeTrait
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLikeTrait() {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -76,10 +81,11 @@ struct ValueLikeTrait {
|
||||
* supported types are StringLike and ValueLike.
|
||||
*/
|
||||
template<typename T>
|
||||
struct ArgTraits {
|
||||
typedef typename T::ValueCategory ValueCategory;
|
||||
virtual ~ArgTraits() {}
|
||||
//typedef ValueLike ValueCategory;
|
||||
struct ArgTraits
|
||||
{
|
||||
typedef typename T::ValueCategory ValueCategory;
|
||||
virtual ~ArgTraits() {}
|
||||
//typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -48,18 +48,19 @@
|
||||
#include <algorithm>
|
||||
#include <stdlib.h> // Needed for exit(), which isn't defined in some envs.
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
template<typename T> void DelPtr(T ptr)
|
||||
{
|
||||
delete ptr;
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
template<typename C> void ClearContainer(C &c)
|
||||
{
|
||||
typedef typename C::value_type value_type;
|
||||
std::for_each(c.begin(), c.end(), DelPtr<value_type>);
|
||||
c.clear();
|
||||
typedef typename C::value_type value_type;
|
||||
std::for_each(c.begin(), c.end(), DelPtr<value_type>);
|
||||
c.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,249 +70,249 @@ template<typename C> void ClearContainer(C &c)
|
||||
*/
|
||||
class CmdLine : public CmdLineInterface
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The list of arguments that will be tested against the
|
||||
* command line.
|
||||
*/
|
||||
std::list<Arg*> _argList;
|
||||
/**
|
||||
* The list of arguments that will be tested against the
|
||||
* command line.
|
||||
*/
|
||||
std::list<Arg*> _argList;
|
||||
|
||||
/**
|
||||
* The name of the program. Set to argv[0].
|
||||
*/
|
||||
std::string _progName;
|
||||
/**
|
||||
* The name of the program. Set to argv[0].
|
||||
*/
|
||||
std::string _progName;
|
||||
|
||||
/**
|
||||
* A message used to describe the program. Used in the usage output.
|
||||
*/
|
||||
std::string _message;
|
||||
/**
|
||||
* A message used to describe the program. Used in the usage output.
|
||||
*/
|
||||
std::string _message;
|
||||
|
||||
/**
|
||||
* The version to be displayed with the --version switch.
|
||||
*/
|
||||
std::string _version;
|
||||
/**
|
||||
* The version to be displayed with the --version switch.
|
||||
*/
|
||||
std::string _version;
|
||||
|
||||
/**
|
||||
* The number of arguments that are required to be present on
|
||||
* the command line. This is set dynamically, based on the
|
||||
* Args added to the CmdLine object.
|
||||
*/
|
||||
int _numRequired;
|
||||
/**
|
||||
* The number of arguments that are required to be present on
|
||||
* the command line. This is set dynamically, based on the
|
||||
* Args added to the CmdLine object.
|
||||
*/
|
||||
int _numRequired;
|
||||
|
||||
/**
|
||||
* The character that is used to separate the argument flag/name
|
||||
* from the value. Defaults to ' ' (space).
|
||||
*/
|
||||
char _delimiter;
|
||||
/**
|
||||
* The character that is used to separate the argument flag/name
|
||||
* from the value. Defaults to ' ' (space).
|
||||
*/
|
||||
char _delimiter;
|
||||
|
||||
/**
|
||||
* The handler that manages xoring lists of args.
|
||||
*/
|
||||
XorHandler _xorHandler;
|
||||
/**
|
||||
* The handler that manages xoring lists of args.
|
||||
*/
|
||||
XorHandler _xorHandler;
|
||||
|
||||
/**
|
||||
* A list of Args to be explicitly deleted when the destructor
|
||||
* is called. At the moment, this only includes the three default
|
||||
* Args.
|
||||
*/
|
||||
std::list<Arg*> _argDeleteOnExitList;
|
||||
/**
|
||||
* A list of Args to be explicitly deleted when the destructor
|
||||
* is called. At the moment, this only includes the three default
|
||||
* Args.
|
||||
*/
|
||||
std::list<Arg*> _argDeleteOnExitList;
|
||||
|
||||
/**
|
||||
* A list of Visitors to be explicitly deleted when the destructor
|
||||
* is called. At the moment, these are the Vistors created for the
|
||||
* default Args.
|
||||
*/
|
||||
std::list<Visitor*> _visitorDeleteOnExitList;
|
||||
/**
|
||||
* A list of Visitors to be explicitly deleted when the destructor
|
||||
* is called. At the moment, these are the Vistors created for the
|
||||
* default Args.
|
||||
*/
|
||||
std::list<Visitor*> _visitorDeleteOnExitList;
|
||||
|
||||
/**
|
||||
* Object that handles all output for the CmdLine.
|
||||
*/
|
||||
CmdLineOutput* _output;
|
||||
/**
|
||||
* Object that handles all output for the CmdLine.
|
||||
*/
|
||||
CmdLineOutput* _output;
|
||||
|
||||
/**
|
||||
* Should CmdLine handle parsing exceptions internally?
|
||||
*/
|
||||
bool _handleExceptions;
|
||||
/**
|
||||
* Should CmdLine handle parsing exceptions internally?
|
||||
*/
|
||||
bool _handleExceptions;
|
||||
|
||||
/**
|
||||
* Throws an exception listing the missing args.
|
||||
*/
|
||||
void missingArgsException();
|
||||
/**
|
||||
* Throws an exception listing the missing args.
|
||||
*/
|
||||
void missingArgsException();
|
||||
|
||||
/**
|
||||
* Checks whether a name/flag string matches entirely matches
|
||||
* the Arg::blankChar. Used when multiple switches are combined
|
||||
* into a single argument.
|
||||
* \param s - The message to be used in the usage.
|
||||
*/
|
||||
bool _emptyCombined(const std::string& s);
|
||||
/**
|
||||
* Checks whether a name/flag string matches entirely matches
|
||||
* the Arg::blankChar. Used when multiple switches are combined
|
||||
* into a single argument.
|
||||
* \param s - The message to be used in the usage.
|
||||
*/
|
||||
bool _emptyCombined(const std::string& s);
|
||||
|
||||
/**
|
||||
* Perform a delete ptr; operation on ptr when this object is deleted.
|
||||
*/
|
||||
void deleteOnExit(Arg* ptr);
|
||||
/**
|
||||
* Perform a delete ptr; operation on ptr when this object is deleted.
|
||||
*/
|
||||
void deleteOnExit(Arg* ptr);
|
||||
|
||||
/**
|
||||
* Perform a delete ptr; operation on ptr when this object is deleted.
|
||||
*/
|
||||
void deleteOnExit(Visitor* ptr);
|
||||
/**
|
||||
* Perform a delete ptr; operation on ptr when this object is deleted.
|
||||
*/
|
||||
void deleteOnExit(Visitor* ptr);
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/**
|
||||
* Prevent accidental copying.
|
||||
*/
|
||||
CmdLine(const CmdLine& rhs);
|
||||
CmdLine& operator=(const CmdLine& rhs);
|
||||
/**
|
||||
* Prevent accidental copying.
|
||||
*/
|
||||
CmdLine(const CmdLine& rhs);
|
||||
CmdLine& operator=(const CmdLine& rhs);
|
||||
|
||||
/**
|
||||
* Encapsulates the code common to the constructors
|
||||
* (which is all of it).
|
||||
*/
|
||||
void _constructor();
|
||||
/**
|
||||
* Encapsulates the code common to the constructors
|
||||
* (which is all of it).
|
||||
*/
|
||||
void _constructor();
|
||||
|
||||
|
||||
/**
|
||||
* Is set to true when a user sets the output object. We use this so
|
||||
* that we don't delete objects that are created outside of this lib.
|
||||
*/
|
||||
bool _userSetOutput;
|
||||
/**
|
||||
* Is set to true when a user sets the output object. We use this so
|
||||
* that we don't delete objects that are created outside of this lib.
|
||||
*/
|
||||
bool _userSetOutput;
|
||||
|
||||
/**
|
||||
* Whether or not to automatically create help and version switches.
|
||||
*/
|
||||
bool _helpAndVersion;
|
||||
/**
|
||||
* Whether or not to automatically create help and version switches.
|
||||
*/
|
||||
bool _helpAndVersion;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Command line constructor. Defines how the arguments will be
|
||||
* parsed.
|
||||
* \param message - The message to be used in the usage
|
||||
* output.
|
||||
* \param delimiter - The character that is used to separate
|
||||
* the argument flag/name from the value. Defaults to ' ' (space).
|
||||
* \param version - The version number to be used in the
|
||||
* --version switch.
|
||||
* \param helpAndVersion - Whether or not to create the Help and
|
||||
* Version switches. Defaults to true.
|
||||
*/
|
||||
CmdLine(const std::string& message,
|
||||
const char delimiter = ' ',
|
||||
const std::string& version = "none",
|
||||
bool helpAndVersion = true);
|
||||
/**
|
||||
* Command line constructor. Defines how the arguments will be
|
||||
* parsed.
|
||||
* \param message - The message to be used in the usage
|
||||
* output.
|
||||
* \param delimiter - The character that is used to separate
|
||||
* the argument flag/name from the value. Defaults to ' ' (space).
|
||||
* \param version - The version number to be used in the
|
||||
* --version switch.
|
||||
* \param helpAndVersion - Whether or not to create the Help and
|
||||
* Version switches. Defaults to true.
|
||||
*/
|
||||
CmdLine(const std::string& message,
|
||||
const char delimiter = ' ',
|
||||
const std::string& version = "none",
|
||||
bool helpAndVersion = true);
|
||||
|
||||
/**
|
||||
* Deletes any resources allocated by a CmdLine object.
|
||||
*/
|
||||
virtual ~CmdLine();
|
||||
/**
|
||||
* Deletes any resources allocated by a CmdLine object.
|
||||
*/
|
||||
virtual ~CmdLine();
|
||||
|
||||
/**
|
||||
* Adds an argument to the list of arguments to be parsed.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
void add( Arg& a );
|
||||
/**
|
||||
* Adds an argument to the list of arguments to be parsed.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
void add( Arg& a );
|
||||
|
||||
/**
|
||||
* An alternative add. Functionally identical.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
void add( Arg* a );
|
||||
/**
|
||||
* An alternative add. Functionally identical.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
void add( Arg* a );
|
||||
|
||||
/**
|
||||
* Add two Args that will be xor'd. If this method is used, add does
|
||||
* not need to be called.
|
||||
* \param a - Argument to be added and xor'd.
|
||||
* \param b - Argument to be added and xor'd.
|
||||
*/
|
||||
void xorAdd( Arg& a, Arg& b );
|
||||
/**
|
||||
* Add two Args that will be xor'd. If this method is used, add does
|
||||
* not need to be called.
|
||||
* \param a - Argument to be added and xor'd.
|
||||
* \param b - Argument to be added and xor'd.
|
||||
*/
|
||||
void xorAdd( Arg& a, Arg& b );
|
||||
|
||||
/**
|
||||
* Add a list of Args that will be xor'd. If this method is used,
|
||||
* add does not need to be called.
|
||||
* \param xors - List of Args to be added and xor'd.
|
||||
*/
|
||||
void xorAdd( std::vector<Arg*>& xors );
|
||||
/**
|
||||
* Add a list of Args that will be xor'd. If this method is used,
|
||||
* add does not need to be called.
|
||||
* \param xors - List of Args to be added and xor'd.
|
||||
*/
|
||||
void xorAdd( std::vector<Arg*>& xors );
|
||||
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param argc - Number of arguments.
|
||||
* \param argv - Array of arguments.
|
||||
*/
|
||||
void parse(int argc, const char * const * argv);
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param argc - Number of arguments.
|
||||
* \param argv - Array of arguments.
|
||||
*/
|
||||
void parse(int argc, const char * const * argv);
|
||||
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param args - A vector of strings representing the args.
|
||||
* args[0] is still the program name.
|
||||
*/
|
||||
void parse(std::vector<std::string>& args);
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param args - A vector of strings representing the args.
|
||||
* args[0] is still the program name.
|
||||
*/
|
||||
void parse(std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CmdLineOutput* getOutput();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CmdLineOutput* getOutput();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void setOutput(CmdLineOutput* co);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void setOutput(CmdLineOutput* co);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getVersion();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getVersion();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getProgramName();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getProgramName();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::list<Arg*>& getArgList();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::list<Arg*>& getArgList();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
XorHandler& getXorHandler();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
XorHandler& getXorHandler();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
char getDelimiter();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
char getDelimiter();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getMessage();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
std::string& getMessage();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
bool hasHelpAndVersion();
|
||||
/**
|
||||
*
|
||||
*/
|
||||
bool hasHelpAndVersion();
|
||||
|
||||
/**
|
||||
* Disables or enables CmdLine's internal parsing exception handling.
|
||||
*
|
||||
* @param state Should CmdLine handle parsing exceptions internally?
|
||||
*/
|
||||
void setExceptionHandling(const bool state);
|
||||
/**
|
||||
* Disables or enables CmdLine's internal parsing exception handling.
|
||||
*
|
||||
* @param state Should CmdLine handle parsing exceptions internally?
|
||||
*/
|
||||
void setExceptionHandling(const bool state);
|
||||
|
||||
/**
|
||||
* Returns the current state of the internal exception handling.
|
||||
*
|
||||
* @retval true Parsing exceptions are handled internally.
|
||||
* @retval false Parsing exceptions are propagated to the caller.
|
||||
*/
|
||||
bool getExceptionHandling() const;
|
||||
/**
|
||||
* Returns the current state of the internal exception handling.
|
||||
*
|
||||
* @retval true Parsing exceptions are handled internally.
|
||||
* @retval false Parsing exceptions are propagated to the caller.
|
||||
*/
|
||||
bool getExceptionHandling() const;
|
||||
|
||||
/**
|
||||
* Allows the CmdLine object to be reused.
|
||||
*/
|
||||
void reset();
|
||||
/**
|
||||
* Allows the CmdLine object to be reused.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
};
|
||||
|
||||
@@ -324,7 +325,7 @@ inline CmdLine::CmdLine(const std::string& m,
|
||||
char delim,
|
||||
const std::string& v,
|
||||
bool help )
|
||||
:
|
||||
:
|
||||
_argList(std::list<Arg*>()),
|
||||
_progName("not_set_yet"),
|
||||
_message(m),
|
||||
@@ -339,288 +340,272 @@ inline CmdLine::CmdLine(const std::string& m,
|
||||
_userSetOutput(false),
|
||||
_helpAndVersion(help)
|
||||
{
|
||||
_constructor();
|
||||
_constructor();
|
||||
}
|
||||
|
||||
inline CmdLine::~CmdLine()
|
||||
{
|
||||
ClearContainer(_argDeleteOnExitList);
|
||||
ClearContainer(_visitorDeleteOnExitList);
|
||||
|
||||
if ( !_userSetOutput ) {
|
||||
delete _output;
|
||||
_output = 0;
|
||||
}
|
||||
ClearContainer(_argDeleteOnExitList);
|
||||
ClearContainer(_visitorDeleteOnExitList);
|
||||
if ( !_userSetOutput )
|
||||
{
|
||||
delete _output;
|
||||
_output = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void CmdLine::_constructor()
|
||||
{
|
||||
_output = new StdOutput;
|
||||
|
||||
Arg::setDelimiter( _delimiter );
|
||||
|
||||
Visitor* v;
|
||||
|
||||
if ( _helpAndVersion )
|
||||
{
|
||||
v = new HelpVisitor( this, &_output );
|
||||
SwitchArg* help = new SwitchArg("h","help",
|
||||
"Displays usage information and exits.",
|
||||
false, v);
|
||||
add( help );
|
||||
deleteOnExit(help);
|
||||
deleteOnExit(v);
|
||||
|
||||
v = new VersionVisitor( this, &_output );
|
||||
SwitchArg* vers = new SwitchArg("","version",
|
||||
"Displays version information and exits.",
|
||||
false, v);
|
||||
add( vers );
|
||||
deleteOnExit(vers);
|
||||
deleteOnExit(v);
|
||||
}
|
||||
|
||||
v = new IgnoreRestVisitor();
|
||||
SwitchArg* ignore = new SwitchArg(Arg::flagStartString(),
|
||||
Arg::ignoreNameString(),
|
||||
"Ignores the rest of the labeled arguments following this flag.",
|
||||
false, v);
|
||||
add( ignore );
|
||||
deleteOnExit(ignore);
|
||||
deleteOnExit(v);
|
||||
_output = new StdOutput;
|
||||
Arg::setDelimiter( _delimiter );
|
||||
Visitor* v;
|
||||
if ( _helpAndVersion )
|
||||
{
|
||||
v = new HelpVisitor( this, &_output );
|
||||
SwitchArg* help = new SwitchArg("h","help",
|
||||
"Displays usage information and exits.",
|
||||
false, v);
|
||||
add( help );
|
||||
deleteOnExit(help);
|
||||
deleteOnExit(v);
|
||||
v = new VersionVisitor( this, &_output );
|
||||
SwitchArg* vers = new SwitchArg("","version",
|
||||
"Displays version information and exits.",
|
||||
false, v);
|
||||
add( vers );
|
||||
deleteOnExit(vers);
|
||||
deleteOnExit(v);
|
||||
}
|
||||
v = new IgnoreRestVisitor();
|
||||
SwitchArg* ignore = new SwitchArg(Arg::flagStartString(),
|
||||
Arg::ignoreNameString(),
|
||||
"Ignores the rest of the labeled arguments following this flag.",
|
||||
false, v);
|
||||
add( ignore );
|
||||
deleteOnExit(ignore);
|
||||
deleteOnExit(v);
|
||||
}
|
||||
|
||||
inline void CmdLine::xorAdd( std::vector<Arg*>& ors )
|
||||
{
|
||||
_xorHandler.add( ors );
|
||||
|
||||
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++)
|
||||
{
|
||||
(*it)->forceRequired();
|
||||
(*it)->setRequireLabel( "OR required" );
|
||||
add( *it );
|
||||
}
|
||||
_xorHandler.add( ors );
|
||||
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++)
|
||||
{
|
||||
(*it)->forceRequired();
|
||||
(*it)->setRequireLabel( "OR required" );
|
||||
add( *it );
|
||||
}
|
||||
}
|
||||
|
||||
inline void CmdLine::xorAdd( Arg& a, Arg& b )
|
||||
{
|
||||
std::vector<Arg*> ors;
|
||||
ors.push_back( &a );
|
||||
ors.push_back( &b );
|
||||
xorAdd( ors );
|
||||
std::vector<Arg*> ors;
|
||||
ors.push_back( &a );
|
||||
ors.push_back( &b );
|
||||
xorAdd( ors );
|
||||
}
|
||||
|
||||
inline void CmdLine::add( Arg& a )
|
||||
{
|
||||
add( &a );
|
||||
add( &a );
|
||||
}
|
||||
|
||||
inline void CmdLine::add( Arg* a )
|
||||
{
|
||||
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
||||
if ( *a == *(*it) )
|
||||
throw( SpecificationException(
|
||||
"Argument with same flag/name already exists!",
|
||||
a->longID() ) );
|
||||
|
||||
a->addToList( _argList );
|
||||
|
||||
if ( a->isRequired() )
|
||||
_numRequired++;
|
||||
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
||||
if ( *a == *(*it) )
|
||||
throw( SpecificationException(
|
||||
"Argument with same flag/name already exists!",
|
||||
a->longID() ) );
|
||||
a->addToList( _argList );
|
||||
if ( a->isRequired() )
|
||||
_numRequired++;
|
||||
}
|
||||
|
||||
|
||||
inline void CmdLine::parse(int argc, const char * const * argv)
|
||||
{
|
||||
// this step is necessary so that we have easy access to
|
||||
// mutable strings.
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; i++)
|
||||
args.push_back(argv[i]);
|
||||
|
||||
parse(args);
|
||||
// this step is necessary so that we have easy access to
|
||||
// mutable strings.
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; i++)
|
||||
args.push_back(argv[i]);
|
||||
parse(args);
|
||||
}
|
||||
|
||||
inline void CmdLine::parse(std::vector<std::string>& args)
|
||||
{
|
||||
bool shouldExit = false;
|
||||
int estat = 0;
|
||||
|
||||
try {
|
||||
_progName = args.front();
|
||||
args.erase(args.begin());
|
||||
|
||||
int requiredCount = 0;
|
||||
|
||||
for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++)
|
||||
{
|
||||
bool matched = false;
|
||||
for (ArgListIterator it = _argList.begin();
|
||||
it != _argList.end(); it++) {
|
||||
if ( (*it)->processArg( &i, args ) )
|
||||
{
|
||||
requiredCount += _xorHandler.check( *it );
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// checks to see if the argument is an empty combined
|
||||
// switch and if so, then we've actually matched it
|
||||
if ( !matched && _emptyCombined( args[i] ) )
|
||||
matched = true;
|
||||
|
||||
if ( !matched && !Arg::ignoreRest() )
|
||||
throw(CmdLineParseException("Couldn't find match "
|
||||
"for argument",
|
||||
args[i]));
|
||||
}
|
||||
|
||||
if ( requiredCount < _numRequired )
|
||||
missingArgsException();
|
||||
|
||||
if ( requiredCount > _numRequired )
|
||||
throw(CmdLineParseException("Too many arguments!"));
|
||||
|
||||
} catch ( ArgException& e ) {
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions) {
|
||||
throw;
|
||||
}
|
||||
|
||||
try {
|
||||
_output->failure(*this,e);
|
||||
} catch ( ExitException &ee ) {
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
} catch (ExitException &ee) {
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions) {
|
||||
throw;
|
||||
}
|
||||
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
|
||||
if (shouldExit)
|
||||
exit(estat);
|
||||
bool shouldExit = false;
|
||||
int estat = 0;
|
||||
try
|
||||
{
|
||||
_progName = args.front();
|
||||
args.erase(args.begin());
|
||||
int requiredCount = 0;
|
||||
for (int i = 0; static_cast<unsigned int>(i) < args.size(); i++)
|
||||
{
|
||||
bool matched = false;
|
||||
for (ArgListIterator it = _argList.begin();
|
||||
it != _argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->processArg( &i, args ) )
|
||||
{
|
||||
requiredCount += _xorHandler.check( *it );
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// checks to see if the argument is an empty combined
|
||||
// switch and if so, then we've actually matched it
|
||||
if ( !matched && _emptyCombined( args[i] ) )
|
||||
matched = true;
|
||||
if ( !matched && !Arg::ignoreRest() )
|
||||
throw(CmdLineParseException("Couldn't find match "
|
||||
"for argument",
|
||||
args[i]));
|
||||
}
|
||||
if ( requiredCount < _numRequired )
|
||||
missingArgsException();
|
||||
if ( requiredCount > _numRequired )
|
||||
throw(CmdLineParseException("Too many arguments!"));
|
||||
}
|
||||
catch ( ArgException& e )
|
||||
{
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
_output->failure(*this,e);
|
||||
}
|
||||
catch ( ExitException &ee )
|
||||
{
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
}
|
||||
catch (ExitException &ee)
|
||||
{
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
if (shouldExit)
|
||||
exit(estat);
|
||||
}
|
||||
|
||||
inline bool CmdLine::_emptyCombined(const std::string& s)
|
||||
{
|
||||
if ( s.length() > 0 && s[0] != Arg::flagStartChar() )
|
||||
return false;
|
||||
|
||||
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
||||
if ( s[i] != Arg::blankChar() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
if ( s.length() > 0 && s[0] != Arg::flagStartChar() )
|
||||
return false;
|
||||
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
||||
if ( s[i] != Arg::blankChar() )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void CmdLine::missingArgsException()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
std::string missingArgList;
|
||||
for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->isRequired() && !(*it)->isSet() )
|
||||
{
|
||||
missingArgList += (*it)->getName();
|
||||
missingArgList += ", ";
|
||||
count++;
|
||||
}
|
||||
}
|
||||
missingArgList = missingArgList.substr(0,missingArgList.length()-2);
|
||||
|
||||
std::string msg;
|
||||
if ( count > 1 )
|
||||
msg = "Required arguments missing: ";
|
||||
else
|
||||
msg = "Required argument missing: ";
|
||||
|
||||
msg += missingArgList;
|
||||
|
||||
throw(CmdLineParseException(msg));
|
||||
int count = 0;
|
||||
std::string missingArgList;
|
||||
for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->isRequired() && !(*it)->isSet() )
|
||||
{
|
||||
missingArgList += (*it)->getName();
|
||||
missingArgList += ", ";
|
||||
count++;
|
||||
}
|
||||
}
|
||||
missingArgList = missingArgList.substr(0,missingArgList.length()-2);
|
||||
std::string msg;
|
||||
if ( count > 1 )
|
||||
msg = "Required arguments missing: ";
|
||||
else
|
||||
msg = "Required argument missing: ";
|
||||
msg += missingArgList;
|
||||
throw(CmdLineParseException(msg));
|
||||
}
|
||||
|
||||
inline void CmdLine::deleteOnExit(Arg* ptr)
|
||||
{
|
||||
_argDeleteOnExitList.push_back(ptr);
|
||||
_argDeleteOnExitList.push_back(ptr);
|
||||
}
|
||||
|
||||
inline void CmdLine::deleteOnExit(Visitor* ptr)
|
||||
{
|
||||
_visitorDeleteOnExitList.push_back(ptr);
|
||||
_visitorDeleteOnExitList.push_back(ptr);
|
||||
}
|
||||
|
||||
inline CmdLineOutput* CmdLine::getOutput()
|
||||
{
|
||||
return _output;
|
||||
return _output;
|
||||
}
|
||||
|
||||
inline void CmdLine::setOutput(CmdLineOutput* co)
|
||||
{
|
||||
if ( !_userSetOutput )
|
||||
delete _output;
|
||||
_userSetOutput = true;
|
||||
_output = co;
|
||||
if ( !_userSetOutput )
|
||||
delete _output;
|
||||
_userSetOutput = true;
|
||||
_output = co;
|
||||
}
|
||||
|
||||
inline std::string& CmdLine::getVersion()
|
||||
{
|
||||
return _version;
|
||||
return _version;
|
||||
}
|
||||
|
||||
inline std::string& CmdLine::getProgramName()
|
||||
{
|
||||
return _progName;
|
||||
return _progName;
|
||||
}
|
||||
|
||||
inline std::list<Arg*>& CmdLine::getArgList()
|
||||
{
|
||||
return _argList;
|
||||
return _argList;
|
||||
}
|
||||
|
||||
inline XorHandler& CmdLine::getXorHandler()
|
||||
{
|
||||
return _xorHandler;
|
||||
return _xorHandler;
|
||||
}
|
||||
|
||||
inline char CmdLine::getDelimiter()
|
||||
{
|
||||
return _delimiter;
|
||||
return _delimiter;
|
||||
}
|
||||
|
||||
inline std::string& CmdLine::getMessage()
|
||||
{
|
||||
return _message;
|
||||
return _message;
|
||||
}
|
||||
|
||||
inline bool CmdLine::hasHelpAndVersion()
|
||||
{
|
||||
return _helpAndVersion;
|
||||
return _helpAndVersion;
|
||||
}
|
||||
|
||||
inline void CmdLine::setExceptionHandling(const bool state)
|
||||
{
|
||||
_handleExceptions = state;
|
||||
_handleExceptions = state;
|
||||
}
|
||||
|
||||
inline bool CmdLine::getExceptionHandling() const
|
||||
{
|
||||
return _handleExceptions;
|
||||
return _handleExceptions;
|
||||
}
|
||||
|
||||
inline void CmdLine::reset()
|
||||
{
|
||||
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
||||
(*it)->reset();
|
||||
|
||||
_progName.clear();
|
||||
for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ )
|
||||
(*it)->reset();
|
||||
_progName.clear();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -30,7 +30,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
class Arg;
|
||||
class CmdLineOutput;
|
||||
@@ -42,106 +43,106 @@ class XorHandler;
|
||||
*/
|
||||
class CmdLineInterface
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~CmdLineInterface() {}
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~CmdLineInterface() {}
|
||||
|
||||
/**
|
||||
* Adds an argument to the list of arguments to be parsed.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
virtual void add( Arg& a )=0;
|
||||
/**
|
||||
* Adds an argument to the list of arguments to be parsed.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
virtual void add( Arg& a )=0;
|
||||
|
||||
/**
|
||||
* An alternative add. Functionally identical.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
virtual void add( Arg* a )=0;
|
||||
/**
|
||||
* An alternative add. Functionally identical.
|
||||
* \param a - Argument to be added.
|
||||
*/
|
||||
virtual void add( Arg* a )=0;
|
||||
|
||||
/**
|
||||
* Add two Args that will be xor'd.
|
||||
* If this method is used, add does
|
||||
* not need to be called.
|
||||
* \param a - Argument to be added and xor'd.
|
||||
* \param b - Argument to be added and xor'd.
|
||||
*/
|
||||
virtual void xorAdd( Arg& a, Arg& b )=0;
|
||||
/**
|
||||
* Add two Args that will be xor'd.
|
||||
* If this method is used, add does
|
||||
* not need to be called.
|
||||
* \param a - Argument to be added and xor'd.
|
||||
* \param b - Argument to be added and xor'd.
|
||||
*/
|
||||
virtual void xorAdd( Arg& a, Arg& b )=0;
|
||||
|
||||
/**
|
||||
* Add a list of Args that will be xor'd. If this method is used,
|
||||
* add does not need to be called.
|
||||
* \param xors - List of Args to be added and xor'd.
|
||||
*/
|
||||
virtual void xorAdd( std::vector<Arg*>& xors )=0;
|
||||
/**
|
||||
* Add a list of Args that will be xor'd. If this method is used,
|
||||
* add does not need to be called.
|
||||
* \param xors - List of Args to be added and xor'd.
|
||||
*/
|
||||
virtual void xorAdd( std::vector<Arg*>& xors )=0;
|
||||
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param argc - Number of arguments.
|
||||
* \param argv - Array of arguments.
|
||||
*/
|
||||
virtual void parse(int argc, const char * const * argv)=0;
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param argc - Number of arguments.
|
||||
* \param argv - Array of arguments.
|
||||
*/
|
||||
virtual void parse(int argc, const char * const * argv)=0;
|
||||
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param args - A vector of strings representing the args.
|
||||
* args[0] is still the program name.
|
||||
*/
|
||||
void parse(std::vector<std::string>& args);
|
||||
/**
|
||||
* Parses the command line.
|
||||
* \param args - A vector of strings representing the args.
|
||||
* args[0] is still the program name.
|
||||
*/
|
||||
void parse(std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Returns the CmdLineOutput object.
|
||||
*/
|
||||
virtual CmdLineOutput* getOutput()=0;
|
||||
/**
|
||||
* Returns the CmdLineOutput object.
|
||||
*/
|
||||
virtual CmdLineOutput* getOutput()=0;
|
||||
|
||||
/**
|
||||
* \param co - CmdLineOutput object that we want to use instead.
|
||||
*/
|
||||
virtual void setOutput(CmdLineOutput* co)=0;
|
||||
/**
|
||||
* \param co - CmdLineOutput object that we want to use instead.
|
||||
*/
|
||||
virtual void setOutput(CmdLineOutput* co)=0;
|
||||
|
||||
/**
|
||||
* Returns the version string.
|
||||
*/
|
||||
virtual std::string& getVersion()=0;
|
||||
/**
|
||||
* Returns the version string.
|
||||
*/
|
||||
virtual std::string& getVersion()=0;
|
||||
|
||||
/**
|
||||
* Returns the program name string.
|
||||
*/
|
||||
virtual std::string& getProgramName()=0;
|
||||
/**
|
||||
* Returns the program name string.
|
||||
*/
|
||||
virtual std::string& getProgramName()=0;
|
||||
|
||||
/**
|
||||
* Returns the argList.
|
||||
*/
|
||||
virtual std::list<Arg*>& getArgList()=0;
|
||||
/**
|
||||
* Returns the argList.
|
||||
*/
|
||||
virtual std::list<Arg*>& getArgList()=0;
|
||||
|
||||
/**
|
||||
* Returns the XorHandler.
|
||||
*/
|
||||
virtual XorHandler& getXorHandler()=0;
|
||||
/**
|
||||
* Returns the XorHandler.
|
||||
*/
|
||||
virtual XorHandler& getXorHandler()=0;
|
||||
|
||||
/**
|
||||
* Returns the delimiter string.
|
||||
*/
|
||||
virtual char getDelimiter()=0;
|
||||
/**
|
||||
* Returns the delimiter string.
|
||||
*/
|
||||
virtual char getDelimiter()=0;
|
||||
|
||||
/**
|
||||
* Returns the message string.
|
||||
*/
|
||||
virtual std::string& getMessage()=0;
|
||||
/**
|
||||
* Returns the message string.
|
||||
*/
|
||||
virtual std::string& getMessage()=0;
|
||||
|
||||
/**
|
||||
* Indicates whether or not the help and version switches were created
|
||||
* automatically.
|
||||
*/
|
||||
virtual bool hasHelpAndVersion()=0;
|
||||
/**
|
||||
* Indicates whether or not the help and version switches were created
|
||||
* automatically.
|
||||
*/
|
||||
virtual bool hasHelpAndVersion()=0;
|
||||
|
||||
/**
|
||||
* Resets the instance as if it had just been constructed so that the
|
||||
* instance can be reused.
|
||||
*/
|
||||
virtual void reset()=0;
|
||||
/**
|
||||
* Resets the instance as if it had just been constructed so that the
|
||||
* instance can be reused.
|
||||
*/
|
||||
virtual void reset()=0;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
@@ -30,7 +30,8 @@
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
class CmdLineInterface;
|
||||
class ArgException;
|
||||
@@ -41,32 +42,32 @@ class ArgException;
|
||||
class CmdLineOutput
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Virtual destructor.
|
||||
*/
|
||||
virtual ~CmdLineOutput() {}
|
||||
/**
|
||||
* Virtual destructor.
|
||||
*/
|
||||
virtual ~CmdLineOutput() {}
|
||||
|
||||
/**
|
||||
* Generates some sort of output for the USAGE.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c)=0;
|
||||
/**
|
||||
* Generates some sort of output for the USAGE.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c)=0;
|
||||
|
||||
/**
|
||||
* Generates some sort of output for the version.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c)=0;
|
||||
/**
|
||||
* Generates some sort of output for the version.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c)=0;
|
||||
|
||||
/**
|
||||
* Generates some sort of output for a failure.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure( CmdLineInterface& c,
|
||||
ArgException& e )=0;
|
||||
/**
|
||||
* Generates some sort of output for a failure.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure( CmdLineInterface& c,
|
||||
ArgException& e )=0;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The interface that defines the interaction between the Arg and Constraint.
|
||||
@@ -38,30 +39,33 @@ template<class T>
|
||||
class Constraint
|
||||
{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns a description of the Constraint.
|
||||
*/
|
||||
virtual std::string description() const =0;
|
||||
public:
|
||||
/**
|
||||
* Returns a description of the Constraint.
|
||||
*/
|
||||
virtual std::string description() const =0;
|
||||
|
||||
/**
|
||||
* Returns the short ID for the Constraint.
|
||||
*/
|
||||
virtual std::string shortID() const =0;
|
||||
/**
|
||||
* Returns the short ID for the Constraint.
|
||||
*/
|
||||
virtual std::string shortID() const =0;
|
||||
|
||||
/**
|
||||
* The method used to verify that the value parsed from the command
|
||||
* line meets the constraint.
|
||||
* \param value - The value that will be checked.
|
||||
*/
|
||||
virtual bool check(const T& value) const =0;
|
||||
/**
|
||||
* The method used to verify that the value parsed from the command
|
||||
* line meets the constraint.
|
||||
* \param value - The value that will be checked.
|
||||
*/
|
||||
virtual bool check(const T& value) const =0;
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* Silences warnings about Constraint being a base class with virtual
|
||||
* functions but without a virtual destructor.
|
||||
*/
|
||||
virtual ~Constraint() { ; }
|
||||
/**
|
||||
* Destructor.
|
||||
* Silences warnings about Constraint being a base class with virtual
|
||||
* functions but without a virtual destructor.
|
||||
*/
|
||||
virtual ~Constraint()
|
||||
{
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace TCLAP
|
||||
|
@@ -34,7 +34,8 @@
|
||||
#include <tclap/XorHandler.h>
|
||||
#include <tclap/Arg.h>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A class that generates DocBook output for usage() method for the
|
||||
@@ -43,256 +44,226 @@ namespace TCLAP {
|
||||
class DocBookOutput : public CmdLineOutput
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Substitutes the char r for string x in string s.
|
||||
* \param s - The string to operate on.
|
||||
* \param r - The char to replace.
|
||||
* \param x - What to replace r with.
|
||||
*/
|
||||
void substituteSpecialChars( std::string& s, char r, std::string& x );
|
||||
void removeChar( std::string& s, char r);
|
||||
void basename( std::string& s );
|
||||
/**
|
||||
* Substitutes the char r for string x in string s.
|
||||
* \param s - The string to operate on.
|
||||
* \param r - The char to replace.
|
||||
* \param x - What to replace r with.
|
||||
*/
|
||||
void substituteSpecialChars( std::string& s, char r, std::string& x );
|
||||
void removeChar( std::string& s, char r);
|
||||
void basename( std::string& s );
|
||||
|
||||
void printShortArg(Arg* it);
|
||||
void printLongArg(Arg* it);
|
||||
void printShortArg(Arg* it);
|
||||
void printLongArg(Arg* it);
|
||||
|
||||
char theDelimiter;
|
||||
char theDelimiter;
|
||||
};
|
||||
|
||||
|
||||
inline void DocBookOutput::version(CmdLineInterface& _cmd)
|
||||
{
|
||||
std::cout << _cmd.getVersion() << std::endl;
|
||||
std::cout << _cmd.getVersion() << std::endl;
|
||||
}
|
||||
|
||||
inline void DocBookOutput::usage(CmdLineInterface& _cmd )
|
||||
{
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
theDelimiter = _cmd.getDelimiter();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
basename(progName);
|
||||
|
||||
std::cout << "<?xml version='1.0'?>" << std::endl;
|
||||
std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
|
||||
std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
|
||||
|
||||
std::cout << "<refentry>" << std::endl;
|
||||
|
||||
std::cout << "<refmeta>" << std::endl;
|
||||
std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl;
|
||||
std::cout << "<manvolnum>1</manvolnum>" << std::endl;
|
||||
std::cout << "</refmeta>" << std::endl;
|
||||
|
||||
std::cout << "<refnamediv>" << std::endl;
|
||||
std::cout << "<refname>" << progName << "</refname>" << std::endl;
|
||||
std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl;
|
||||
std::cout << "</refnamediv>" << std::endl;
|
||||
|
||||
std::cout << "<refsynopsisdiv>" << std::endl;
|
||||
std::cout << "<cmdsynopsis>" << std::endl;
|
||||
|
||||
std::cout << "<command>" << progName << "</command>" << std::endl;
|
||||
|
||||
// xor
|
||||
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
||||
{
|
||||
std::cout << "<group choice='req'>" << std::endl;
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end(); it++ )
|
||||
printShortArg((*it));
|
||||
|
||||
std::cout << "</group>" << std::endl;
|
||||
}
|
||||
|
||||
// rest of args
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
printShortArg((*it));
|
||||
|
||||
std::cout << "</cmdsynopsis>" << std::endl;
|
||||
std::cout << "</refsynopsisdiv>" << std::endl;
|
||||
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Description</title>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << _cmd.getMessage() << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Options</title>" << std::endl;
|
||||
|
||||
std::cout << "<variablelist>" << std::endl;
|
||||
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
printLongArg((*it));
|
||||
|
||||
std::cout << "</variablelist>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Version</title>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << xversion << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
|
||||
std::cout << "</refentry>" << std::endl;
|
||||
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
theDelimiter = _cmd.getDelimiter();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
basename(progName);
|
||||
std::cout << "<?xml version='1.0'?>" << std::endl;
|
||||
std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl;
|
||||
std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
|
||||
std::cout << "<refentry>" << std::endl;
|
||||
std::cout << "<refmeta>" << std::endl;
|
||||
std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl;
|
||||
std::cout << "<manvolnum>1</manvolnum>" << std::endl;
|
||||
std::cout << "</refmeta>" << std::endl;
|
||||
std::cout << "<refnamediv>" << std::endl;
|
||||
std::cout << "<refname>" << progName << "</refname>" << std::endl;
|
||||
std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl;
|
||||
std::cout << "</refnamediv>" << std::endl;
|
||||
std::cout << "<refsynopsisdiv>" << std::endl;
|
||||
std::cout << "<cmdsynopsis>" << std::endl;
|
||||
std::cout << "<command>" << progName << "</command>" << std::endl;
|
||||
// xor
|
||||
for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
|
||||
{
|
||||
std::cout << "<group choice='req'>" << std::endl;
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end(); it++ )
|
||||
printShortArg((*it));
|
||||
std::cout << "</group>" << std::endl;
|
||||
}
|
||||
// rest of args
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
printShortArg((*it));
|
||||
std::cout << "</cmdsynopsis>" << std::endl;
|
||||
std::cout << "</refsynopsisdiv>" << std::endl;
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Description</title>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << _cmd.getMessage() << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Options</title>" << std::endl;
|
||||
std::cout << "<variablelist>" << std::endl;
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
printLongArg((*it));
|
||||
std::cout << "</variablelist>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
std::cout << "<refsect1>" << std::endl;
|
||||
std::cout << "<title>Version</title>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << xversion << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</refsect1>" << std::endl;
|
||||
std::cout << "</refentry>" << std::endl;
|
||||
}
|
||||
|
||||
inline void DocBookOutput::failure( CmdLineInterface& _cmd,
|
||||
ArgException& e )
|
||||
ArgException& e )
|
||||
{
|
||||
static_cast<void>(_cmd); // unused
|
||||
std::cout << e.what() << std::endl;
|
||||
throw ExitException(1);
|
||||
static_cast<void>(_cmd); // unused
|
||||
std::cout << e.what() << std::endl;
|
||||
throw ExitException(1);
|
||||
}
|
||||
|
||||
inline void DocBookOutput::substituteSpecialChars( std::string& s,
|
||||
char r,
|
||||
std::string& x )
|
||||
char r,
|
||||
std::string& x )
|
||||
{
|
||||
size_t p;
|
||||
while ( (p = s.find_first_of(r)) != std::string::npos )
|
||||
{
|
||||
s.erase(p,1);
|
||||
s.insert(p,x);
|
||||
}
|
||||
size_t p;
|
||||
while ( (p = s.find_first_of(r)) != std::string::npos )
|
||||
{
|
||||
s.erase(p,1);
|
||||
s.insert(p,x);
|
||||
}
|
||||
}
|
||||
|
||||
inline void DocBookOutput::removeChar( std::string& s, char r)
|
||||
{
|
||||
size_t p;
|
||||
while ( (p = s.find_first_of(r)) != std::string::npos )
|
||||
{
|
||||
s.erase(p,1);
|
||||
}
|
||||
size_t p;
|
||||
while ( (p = s.find_first_of(r)) != std::string::npos )
|
||||
{
|
||||
s.erase(p,1);
|
||||
}
|
||||
}
|
||||
|
||||
inline void DocBookOutput::basename( std::string& s )
|
||||
{
|
||||
size_t p = s.find_last_of('/');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
s.erase(0, p + 1);
|
||||
}
|
||||
size_t p = s.find_last_of('/');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
s.erase(0, p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline void DocBookOutput::printShortArg(Arg* a)
|
||||
{
|
||||
std::string lt = "<";
|
||||
std::string gt = ">";
|
||||
|
||||
std::string id = a->shortID();
|
||||
substituteSpecialChars(id,'<',lt);
|
||||
substituteSpecialChars(id,'>',gt);
|
||||
removeChar(id,'[');
|
||||
removeChar(id,']');
|
||||
|
||||
std::string choice = "opt";
|
||||
if ( a->isRequired() )
|
||||
choice = "plain";
|
||||
|
||||
std::cout << "<arg choice='" << choice << '\'';
|
||||
if ( a->acceptsMultipleValues() )
|
||||
std::cout << " rep='repeat'";
|
||||
|
||||
|
||||
std::cout << '>';
|
||||
if ( !a->getFlag().empty() )
|
||||
std::cout << a->flagStartChar() << a->getFlag();
|
||||
else
|
||||
std::cout << a->nameStartString() << a->getName();
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
removeChar(arg,'[');
|
||||
removeChar(arg,']');
|
||||
removeChar(arg,'<');
|
||||
removeChar(arg,'>');
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
std::cout << theDelimiter;
|
||||
std::cout << "<replaceable>" << arg << "</replaceable>";
|
||||
}
|
||||
std::cout << "</arg>" << std::endl;
|
||||
|
||||
std::string lt = "<";
|
||||
std::string gt = ">";
|
||||
std::string id = a->shortID();
|
||||
substituteSpecialChars(id,'<',lt);
|
||||
substituteSpecialChars(id,'>',gt);
|
||||
removeChar(id,'[');
|
||||
removeChar(id,']');
|
||||
std::string choice = "opt";
|
||||
if ( a->isRequired() )
|
||||
choice = "plain";
|
||||
std::cout << "<arg choice='" << choice << '\'';
|
||||
if ( a->acceptsMultipleValues() )
|
||||
std::cout << " rep='repeat'";
|
||||
std::cout << '>';
|
||||
if ( !a->getFlag().empty() )
|
||||
std::cout << a->flagStartChar() << a->getFlag();
|
||||
else
|
||||
std::cout << a->nameStartString() << a->getName();
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
removeChar(arg,'[');
|
||||
removeChar(arg,']');
|
||||
removeChar(arg,'<');
|
||||
removeChar(arg,'>');
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
std::cout << theDelimiter;
|
||||
std::cout << "<replaceable>" << arg << "</replaceable>";
|
||||
}
|
||||
std::cout << "</arg>" << std::endl;
|
||||
}
|
||||
|
||||
inline void DocBookOutput::printLongArg(Arg* a)
|
||||
{
|
||||
std::string lt = "<";
|
||||
std::string gt = ">";
|
||||
|
||||
std::string desc = a->getDescription();
|
||||
substituteSpecialChars(desc,'<',lt);
|
||||
substituteSpecialChars(desc,'>',gt);
|
||||
|
||||
std::cout << "<varlistentry>" << std::endl;
|
||||
|
||||
if ( !a->getFlag().empty() )
|
||||
{
|
||||
std::cout << "<term>" << std::endl;
|
||||
std::cout << "<option>";
|
||||
std::cout << a->flagStartChar() << a->getFlag();
|
||||
std::cout << "</option>" << std::endl;
|
||||
std::cout << "</term>" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "<term>" << std::endl;
|
||||
std::cout << "<option>";
|
||||
std::cout << a->nameStartString() << a->getName();
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
removeChar(arg,'[');
|
||||
removeChar(arg,']');
|
||||
removeChar(arg,'<');
|
||||
removeChar(arg,'>');
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
std::cout << theDelimiter;
|
||||
std::cout << "<replaceable>" << arg << "</replaceable>";
|
||||
}
|
||||
std::cout << "</option>" << std::endl;
|
||||
std::cout << "</term>" << std::endl;
|
||||
|
||||
std::cout << "<listitem>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << desc << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</listitem>" << std::endl;
|
||||
|
||||
std::cout << "</varlistentry>" << std::endl;
|
||||
std::string lt = "<";
|
||||
std::string gt = ">";
|
||||
std::string desc = a->getDescription();
|
||||
substituteSpecialChars(desc,'<',lt);
|
||||
substituteSpecialChars(desc,'>',gt);
|
||||
std::cout << "<varlistentry>" << std::endl;
|
||||
if ( !a->getFlag().empty() )
|
||||
{
|
||||
std::cout << "<term>" << std::endl;
|
||||
std::cout << "<option>";
|
||||
std::cout << a->flagStartChar() << a->getFlag();
|
||||
std::cout << "</option>" << std::endl;
|
||||
std::cout << "</term>" << std::endl;
|
||||
}
|
||||
std::cout << "<term>" << std::endl;
|
||||
std::cout << "<option>";
|
||||
std::cout << a->nameStartString() << a->getName();
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
removeChar(arg,'[');
|
||||
removeChar(arg,']');
|
||||
removeChar(arg,'<');
|
||||
removeChar(arg,'>');
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
std::cout << theDelimiter;
|
||||
std::cout << "<replaceable>" << arg << "</replaceable>";
|
||||
}
|
||||
std::cout << "</option>" << std::endl;
|
||||
std::cout << "</term>" << std::endl;
|
||||
std::cout << "<listitem>" << std::endl;
|
||||
std::cout << "<para>" << std::endl;
|
||||
std::cout << desc << std::endl;
|
||||
std::cout << "</para>" << std::endl;
|
||||
std::cout << "</listitem>" << std::endl;
|
||||
std::cout << "</varlistentry>" << std::endl;
|
||||
}
|
||||
|
||||
} //namespace TCLAP
|
||||
|
@@ -26,7 +26,8 @@
|
||||
#include "CmdLineOutput.h"
|
||||
#include "Visitor.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A Visitor object that calls the usage method of the given CmdLineOutput
|
||||
@@ -34,40 +35,44 @@ namespace TCLAP {
|
||||
*/
|
||||
class HelpVisitor: public Visitor
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying.
|
||||
*/
|
||||
HelpVisitor(const HelpVisitor& rhs);
|
||||
HelpVisitor& operator=(const HelpVisitor& rhs);
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying.
|
||||
*/
|
||||
HelpVisitor(const HelpVisitor& rhs);
|
||||
HelpVisitor& operator=(const HelpVisitor& rhs);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The CmdLine the output will be generated for.
|
||||
*/
|
||||
CmdLineInterface* _cmd;
|
||||
/**
|
||||
* The CmdLine the output will be generated for.
|
||||
*/
|
||||
CmdLineInterface* _cmd;
|
||||
|
||||
/**
|
||||
* The output object.
|
||||
*/
|
||||
CmdLineOutput** _out;
|
||||
/**
|
||||
* The output object.
|
||||
*/
|
||||
CmdLineOutput** _out;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param cmd - The CmdLine the output will be generated for.
|
||||
* \param out - The type of output.
|
||||
*/
|
||||
HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out)
|
||||
: Visitor(), _cmd( cmd ), _out( out ) { }
|
||||
/**
|
||||
* Constructor.
|
||||
* \param cmd - The CmdLine the output will be generated for.
|
||||
* \param out - The type of output.
|
||||
*/
|
||||
HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out)
|
||||
: Visitor(), _cmd( cmd ), _out( out ) { }
|
||||
|
||||
/**
|
||||
* Calls the usage method of the CmdLineOutput for the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit() { (*_out)->usage(*_cmd); throw ExitException(0); }
|
||||
/**
|
||||
* Calls the usage method of the CmdLineOutput for the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit()
|
||||
{
|
||||
(*_out)->usage(*_cmd);
|
||||
throw ExitException(0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@@ -26,7 +26,8 @@
|
||||
#include "Visitor.h"
|
||||
#include "Arg.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A Vistor that tells the CmdLine to begin ignoring arguments after
|
||||
@@ -34,17 +35,20 @@ namespace TCLAP {
|
||||
*/
|
||||
class IgnoreRestVisitor: public Visitor
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
IgnoreRestVisitor() : Visitor() {}
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
IgnoreRestVisitor() : Visitor() {}
|
||||
|
||||
/**
|
||||
* Sets Arg::_ignoreRest.
|
||||
*/
|
||||
void visit() { Arg::beginIgnoring(); }
|
||||
/**
|
||||
* Sets Arg::_ignoreRest.
|
||||
*/
|
||||
void visit()
|
||||
{
|
||||
Arg::beginIgnoring();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include "Arg.h"
|
||||
#include "Constraint.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
/**
|
||||
* An argument that allows multiple values of type T to be specified. Very
|
||||
* similar to a ValueArg, except a vector of values will be returned
|
||||
@@ -38,195 +39,201 @@ namespace TCLAP {
|
||||
template<class T>
|
||||
class MultiArg : public Arg
|
||||
{
|
||||
public:
|
||||
typedef std::vector<T> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
typedef typename container_type::const_iterator const_iterator;
|
||||
public:
|
||||
typedef std::vector<T> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
typedef typename container_type::const_iterator const_iterator;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The list of values parsed from the CmdLine.
|
||||
*/
|
||||
std::vector<T> _values;
|
||||
/**
|
||||
* The list of values parsed from the CmdLine.
|
||||
*/
|
||||
std::vector<T> _values;
|
||||
|
||||
/**
|
||||
* The description of type T to be used in the usage.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
/**
|
||||
* The description of type T to be used in the usage.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
|
||||
/**
|
||||
* A list of constraint on this Arg.
|
||||
*/
|
||||
Constraint<T>* _constraint;
|
||||
/**
|
||||
* A list of constraint on this Arg.
|
||||
*/
|
||||
Constraint<T>* _constraint;
|
||||
|
||||
/**
|
||||
* Extracts the value from the string.
|
||||
* Attempts to parse string as type T, if this fails an exception
|
||||
* is thrown.
|
||||
* \param val - The string to be read.
|
||||
*/
|
||||
void _extractValue( const std::string& val );
|
||||
/**
|
||||
* Extracts the value from the string.
|
||||
* Attempts to parse string as type T, if this fails an exception
|
||||
* is thrown.
|
||||
* \param val - The string to be read.
|
||||
*/
|
||||
void _extractValue( const std::string& val );
|
||||
|
||||
/**
|
||||
* Used by XorHandler to decide whether to keep parsing for this arg.
|
||||
*/
|
||||
bool _allowMore;
|
||||
/**
|
||||
* Used by XorHandler to decide whether to keep parsing for this arg.
|
||||
*/
|
||||
bool _allowMore;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v = NULL);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Returns a vector of type T containing the values parsed from
|
||||
* the command line.
|
||||
*/
|
||||
const std::vector<T>& getValue();
|
||||
/**
|
||||
* Returns a vector of type T containing the values parsed from
|
||||
* the command line.
|
||||
*/
|
||||
const std::vector<T>& getValue();
|
||||
|
||||
/**
|
||||
* Returns an iterator over the values parsed from the command
|
||||
* line.
|
||||
*/
|
||||
const_iterator begin() const { return _values.begin(); }
|
||||
/**
|
||||
* Returns an iterator over the values parsed from the command
|
||||
* line.
|
||||
*/
|
||||
const_iterator begin() const
|
||||
{
|
||||
return _values.begin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the end of the values parsed from the command
|
||||
* line.
|
||||
*/
|
||||
const_iterator end() const { return _values.end(); }
|
||||
/**
|
||||
* Returns the end of the values parsed from the command
|
||||
* line.
|
||||
*/
|
||||
const_iterator end() const
|
||||
{
|
||||
return _values.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the a short id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
/**
|
||||
* Returns the a short id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Returns the a long id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
/**
|
||||
* Returns the a long id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Once we've matched the first value, then the arg is no longer
|
||||
* required.
|
||||
*/
|
||||
virtual bool isRequired() const;
|
||||
/**
|
||||
* Once we've matched the first value, then the arg is no longer
|
||||
* required.
|
||||
*/
|
||||
virtual bool isRequired() const;
|
||||
|
||||
virtual bool allowMore();
|
||||
virtual bool allowMore();
|
||||
|
||||
virtual void reset();
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
MultiArg<T>(const MultiArg<T>& rhs);
|
||||
MultiArg<T>& operator=(const MultiArg<T>& rhs);
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
MultiArg<T>(const MultiArg<T>& rhs);
|
||||
MultiArg<T>& operator=(const MultiArg<T>& rhs);
|
||||
|
||||
};
|
||||
|
||||
@@ -237,13 +244,13 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v) :
|
||||
Arg( flag, name, desc, req, true, v ),
|
||||
Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL ),
|
||||
_allowMore(false)
|
||||
{
|
||||
_acceptsMultipleValues = true;
|
||||
_acceptsMultipleValues = true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -254,14 +261,14 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL ),
|
||||
_allowMore(false)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL ),
|
||||
_allowMore(false)
|
||||
{
|
||||
parser.add( this );
|
||||
_acceptsMultipleValues = true;
|
||||
parser.add( this );
|
||||
_acceptsMultipleValues = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,13 +281,13 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
_allowMore(false)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
_allowMore(false)
|
||||
{
|
||||
_acceptsMultipleValues = true;
|
||||
_acceptsMultipleValues = true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -291,68 +298,63 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
_allowMore(false)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
_allowMore(false)
|
||||
{
|
||||
parser.add( this );
|
||||
_acceptsMultipleValues = true;
|
||||
parser.add( this );
|
||||
_acceptsMultipleValues = true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const std::vector<T>& MultiArg<T>::getValue() { return _values; }
|
||||
const std::vector<T>& MultiArg<T>::getValue()
|
||||
{
|
||||
return _values;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
|
||||
std::string flag = args[*i];
|
||||
std::string value = "";
|
||||
|
||||
trimFlag( flag, value );
|
||||
|
||||
if ( argMatches( flag ) )
|
||||
{
|
||||
if ( Arg::delimiter() != ' ' && value == "" )
|
||||
throw( ArgParseException(
|
||||
"Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
|
||||
// always take the first one, regardless of start string
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
if ( static_cast<unsigned int>(*i) < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgParseException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
/*
|
||||
// continuing taking the args until we hit one with a start string
|
||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||
args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
|
||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
std::string flag = args[*i];
|
||||
std::string value = "";
|
||||
trimFlag( flag, value );
|
||||
if ( argMatches( flag ) )
|
||||
{
|
||||
if ( Arg::delimiter() != ' ' && value == "" )
|
||||
throw( ArgParseException(
|
||||
"Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
// always take the first one, regardless of start string
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
if ( static_cast<unsigned int>(*i) < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgParseException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
/*
|
||||
// continuing taking the args until we hit one with a start string
|
||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||
args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
|
||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,8 +363,8 @@ bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
template<class T>
|
||||
std::string MultiArg<T>::shortID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::shortID(_typeDesc) + " ... ";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::shortID(_typeDesc) + " ... ";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,8 +373,8 @@ std::string MultiArg<T>::shortID(const std::string& val) const
|
||||
template<class T>
|
||||
std::string MultiArg<T>::longID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::longID(_typeDesc) + " (accepted multiple times)";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::longID(_typeDesc) + " (accepted multiple times)";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,50 +384,51 @@ std::string MultiArg<T>::longID(const std::string& val) const
|
||||
template<class T>
|
||||
bool MultiArg<T>::isRequired() const
|
||||
{
|
||||
if ( _required )
|
||||
{
|
||||
if ( _values.size() > 1 )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
if ( _required )
|
||||
{
|
||||
if ( _values.size() > 1 )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void MultiArg<T>::_extractValue( const std::string& val )
|
||||
{
|
||||
try {
|
||||
T tmp;
|
||||
ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory());
|
||||
_values.push_back(tmp);
|
||||
} catch( ArgParseException &e) {
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _values.back() ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
"' does not meet constraint: " +
|
||||
_constraint->description(),
|
||||
toString() ) );
|
||||
try
|
||||
{
|
||||
T tmp;
|
||||
ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory());
|
||||
_values.push_back(tmp);
|
||||
}
|
||||
catch( ArgParseException &e)
|
||||
{
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _values.back() ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
"' does not meet constraint: " +
|
||||
_constraint->description(),
|
||||
toString() ) );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool MultiArg<T>::allowMore()
|
||||
{
|
||||
bool am = _allowMore;
|
||||
_allowMore = true;
|
||||
return am;
|
||||
bool am = _allowMore;
|
||||
_allowMore = true;
|
||||
return am;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void MultiArg<T>::reset()
|
||||
{
|
||||
Arg::reset();
|
||||
_values.clear();
|
||||
Arg::reset();
|
||||
_values.clear();
|
||||
}
|
||||
|
||||
} // namespace TCLAP
|
||||
|
@@ -30,7 +30,8 @@
|
||||
|
||||
#include "SwitchArg.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A multiple switch argument. If the switch is set on the command line, then
|
||||
@@ -38,89 +39,89 @@ namespace TCLAP {
|
||||
*/
|
||||
class MultiSwitchArg : public SwitchArg
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The value of the switch.
|
||||
*/
|
||||
int _value;
|
||||
/**
|
||||
* The value of the switch.
|
||||
*/
|
||||
int _value;
|
||||
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
int _default;
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
int _default;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* MultiSwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param init - Optional. The initial/default value of this Arg.
|
||||
* Defaults to 0.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
int init = 0,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* MultiSwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param init - Optional. The initial/default value of this Arg.
|
||||
* Defaults to 0.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
int init = 0,
|
||||
Visitor* v = NULL);
|
||||
|
||||
|
||||
/**
|
||||
* MultiSwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param init - Optional. The initial/default value of this Arg.
|
||||
* Defaults to 0.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
int init = 0,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* MultiSwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param init - Optional. The initial/default value of this Arg.
|
||||
* Defaults to 0.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
int init = 0,
|
||||
Visitor* v = NULL);
|
||||
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the SwitchArg version of this method to set the
|
||||
* _value of the argument appropriately.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the SwitchArg version of this method to set the
|
||||
* _value of the argument appropriately.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Returns int, the number of times the switch has been set.
|
||||
*/
|
||||
int getValue();
|
||||
/**
|
||||
* Returns int, the number of times the switch has been set.
|
||||
*/
|
||||
int getValue();
|
||||
|
||||
/**
|
||||
* Returns the shortID for this Arg.
|
||||
*/
|
||||
std::string shortID(const std::string& val) const;
|
||||
/**
|
||||
* Returns the shortID for this Arg.
|
||||
*/
|
||||
std::string shortID(const std::string& val) const;
|
||||
|
||||
/**
|
||||
* Returns the longID for this Arg.
|
||||
*/
|
||||
std::string longID(const std::string& val) const;
|
||||
/**
|
||||
* Returns the longID for this Arg.
|
||||
*/
|
||||
std::string longID(const std::string& val) const;
|
||||
|
||||
void reset();
|
||||
void reset();
|
||||
|
||||
};
|
||||
|
||||
@@ -128,83 +129,78 @@ class MultiSwitchArg : public SwitchArg
|
||||
//BEGIN MultiSwitchArg.cpp
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
{ }
|
||||
|
||||
inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
{
|
||||
parser.add( this );
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
inline int MultiSwitchArg::getValue() { return _value; }
|
||||
inline int MultiSwitchArg::getValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
|
||||
if ( argMatches( args[*i] ))
|
||||
{
|
||||
// so the isSet() method will work
|
||||
_alreadySet = true;
|
||||
|
||||
// Matched argument: increment value.
|
||||
++_value;
|
||||
|
||||
_checkWithVisitor();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||
{
|
||||
// so the isSet() method will work
|
||||
_alreadySet = true;
|
||||
|
||||
// Matched argument: increment value.
|
||||
++_value;
|
||||
|
||||
// Check for more in argument and increment value.
|
||||
while ( combinedSwitchesMatch( args[*i] ) )
|
||||
++_value;
|
||||
|
||||
_checkWithVisitor();
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
if ( argMatches( args[*i] ))
|
||||
{
|
||||
// so the isSet() method will work
|
||||
_alreadySet = true;
|
||||
// Matched argument: increment value.
|
||||
++_value;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
}
|
||||
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||
{
|
||||
// so the isSet() method will work
|
||||
_alreadySet = true;
|
||||
// Matched argument: increment value.
|
||||
++_value;
|
||||
// Check for more in argument and increment value.
|
||||
while ( combinedSwitchesMatch( args[*i] ) )
|
||||
++_value;
|
||||
_checkWithVisitor();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::string
|
||||
MultiSwitchArg::shortID(const std::string& val) const
|
||||
{
|
||||
return Arg::shortID(val) + " ... ";
|
||||
return Arg::shortID(val) + " ... ";
|
||||
}
|
||||
|
||||
inline std::string
|
||||
MultiSwitchArg::longID(const std::string& val) const
|
||||
{
|
||||
return Arg::longID(val) + " (accepted multiple times)";
|
||||
return Arg::longID(val) + " (accepted multiple times)";
|
||||
}
|
||||
|
||||
inline void
|
||||
MultiSwitchArg::reset()
|
||||
{
|
||||
MultiSwitchArg::_value = MultiSwitchArg::_default;
|
||||
MultiSwitchArg::_value = MultiSwitchArg::_default;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@@ -26,34 +26,44 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
class OptionalUnlabeledTracker
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
static void check( bool req, const std::string& argName );
|
||||
static void check( bool req, const std::string& argName );
|
||||
|
||||
static void gotOptional() { alreadyOptionalRef() = true; }
|
||||
static void gotOptional()
|
||||
{
|
||||
alreadyOptionalRef() = true;
|
||||
}
|
||||
|
||||
static bool& alreadyOptional() { return alreadyOptionalRef(); }
|
||||
static bool& alreadyOptional()
|
||||
{
|
||||
return alreadyOptionalRef();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
static bool& alreadyOptionalRef() { static bool ct = false; return ct; }
|
||||
static bool& alreadyOptionalRef()
|
||||
{
|
||||
static bool ct = false;
|
||||
return ct;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName )
|
||||
{
|
||||
if ( OptionalUnlabeledTracker::alreadyOptional() )
|
||||
throw( SpecificationException(
|
||||
"You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
|
||||
argName ) );
|
||||
|
||||
if ( !req )
|
||||
OptionalUnlabeledTracker::gotOptional();
|
||||
if ( OptionalUnlabeledTracker::alreadyOptional() )
|
||||
throw( SpecificationException(
|
||||
"You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
|
||||
argName ) );
|
||||
if ( !req )
|
||||
OptionalUnlabeledTracker::gotOptional();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -39,7 +39,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
// ======================================================================
|
||||
// Integer types
|
||||
@@ -49,32 +50,36 @@ namespace TCLAP {
|
||||
* longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<long> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* ints have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<int> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<int>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* shorts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<short> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<short>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* chars have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<char> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<char>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
@@ -82,8 +87,9 @@ struct ArgTraits<char> {
|
||||
* long longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<long long> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<long long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -95,32 +101,36 @@ struct ArgTraits<long long> {
|
||||
* unsigned longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned long> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<unsigned long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* unsigned ints have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned int> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<unsigned int>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* unsigned shorts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned short> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<unsigned short>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* unsigned chars have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned char> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<unsigned char>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
// Microsoft implements size_t awkwardly.
|
||||
@@ -129,8 +139,9 @@ struct ArgTraits<unsigned char> {
|
||||
* size_ts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<size_t> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<size_t>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -140,8 +151,9 @@ struct ArgTraits<size_t> {
|
||||
* unsigned long longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned long long> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<unsigned long long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -153,16 +165,18 @@ struct ArgTraits<unsigned long long> {
|
||||
* floats have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<float> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<float>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
/**
|
||||
* doubles have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<double> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<double>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
// ======================================================================
|
||||
@@ -173,8 +187,9 @@ struct ArgTraits<double> {
|
||||
* bools have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<bool> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<bool>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
|
||||
@@ -183,8 +198,9 @@ struct ArgTraits<bool> {
|
||||
*/
|
||||
#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
|
||||
template<>
|
||||
struct ArgTraits<wchar_t> {
|
||||
typedef ValueLike ValueCategory;
|
||||
struct ArgTraits<wchar_t>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -192,14 +208,15 @@ struct ArgTraits<wchar_t> {
|
||||
* Strings have string like argument traits.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<std::string> {
|
||||
typedef StringLike ValueCategory;
|
||||
struct ArgTraits<std::string>
|
||||
{
|
||||
typedef StringLike ValueCategory;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void SetString(T &dst, const std::string &src)
|
||||
{
|
||||
dst = src;
|
||||
dst = src;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@@ -34,7 +34,8 @@
|
||||
#include "XorHandler.h"
|
||||
#include "Arg.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A class that isolates any output from the CmdLine object so that it
|
||||
@@ -43,255 +44,223 @@ namespace TCLAP {
|
||||
class StdOutput : public CmdLineOutput
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Writes a brief usage message with short args.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param os - The stream to write the message to.
|
||||
*/
|
||||
void _shortUsage( CmdLineInterface& c, std::ostream& os ) const;
|
||||
/**
|
||||
* Writes a brief usage message with short args.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param os - The stream to write the message to.
|
||||
*/
|
||||
void _shortUsage( CmdLineInterface& c, std::ostream& os ) const;
|
||||
|
||||
/**
|
||||
* Writes a longer usage message with long and short args,
|
||||
* provides descriptions and prints message.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param os - The stream to write the message to.
|
||||
*/
|
||||
void _longUsage( CmdLineInterface& c, std::ostream& os ) const;
|
||||
/**
|
||||
* Writes a longer usage message with long and short args,
|
||||
* provides descriptions and prints message.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param os - The stream to write the message to.
|
||||
*/
|
||||
void _longUsage( CmdLineInterface& c, std::ostream& os ) const;
|
||||
|
||||
/**
|
||||
* This function inserts line breaks and indents long strings
|
||||
* according the params input. It will only break lines at spaces,
|
||||
* commas and pipes.
|
||||
* \param os - The stream to be printed to.
|
||||
* \param s - The string to be printed.
|
||||
* \param maxWidth - The maxWidth allowed for the output line.
|
||||
* \param indentSpaces - The number of spaces to indent the first line.
|
||||
* \param secondLineOffset - The number of spaces to indent the second
|
||||
* and all subsequent lines in addition to indentSpaces.
|
||||
*/
|
||||
void spacePrint( std::ostream& os,
|
||||
const std::string& s,
|
||||
int maxWidth,
|
||||
int indentSpaces,
|
||||
int secondLineOffset ) const;
|
||||
/**
|
||||
* This function inserts line breaks and indents long strings
|
||||
* according the params input. It will only break lines at spaces,
|
||||
* commas and pipes.
|
||||
* \param os - The stream to be printed to.
|
||||
* \param s - The string to be printed.
|
||||
* \param maxWidth - The maxWidth allowed for the output line.
|
||||
* \param indentSpaces - The number of spaces to indent the first line.
|
||||
* \param secondLineOffset - The number of spaces to indent the second
|
||||
* and all subsequent lines in addition to indentSpaces.
|
||||
*/
|
||||
void spacePrint( std::ostream& os,
|
||||
const std::string& s,
|
||||
int maxWidth,
|
||||
int indentSpaces,
|
||||
int secondLineOffset ) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline void StdOutput::version(CmdLineInterface& _cmd)
|
||||
{
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
|
||||
std::cout << std::endl << progName << " version: "
|
||||
<< xversion << std::endl << std::endl;
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
std::cout << std::endl << progName << " version: "
|
||||
<< xversion << std::endl << std::endl;
|
||||
}
|
||||
|
||||
inline void StdOutput::usage(CmdLineInterface& _cmd )
|
||||
{
|
||||
std::cout << std::endl << "USAGE: " << std::endl << std::endl;
|
||||
|
||||
_shortUsage( _cmd, std::cout );
|
||||
|
||||
std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl;
|
||||
|
||||
_longUsage( _cmd, std::cout );
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << std::endl << "USAGE: " << std::endl << std::endl;
|
||||
_shortUsage( _cmd, std::cout );
|
||||
std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl;
|
||||
_longUsage( _cmd, std::cout );
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
inline void StdOutput::failure( CmdLineInterface& _cmd,
|
||||
ArgException& e )
|
||||
ArgException& e )
|
||||
{
|
||||
std::string progName = _cmd.getProgramName();
|
||||
|
||||
std::cerr << "PARSE ERROR: " << e.argId() << std::endl
|
||||
<< " " << e.error() << std::endl << std::endl;
|
||||
|
||||
if ( _cmd.hasHelpAndVersion() )
|
||||
{
|
||||
std::cerr << "Brief USAGE: " << std::endl;
|
||||
|
||||
_shortUsage( _cmd, std::cerr );
|
||||
|
||||
std::cerr << std::endl << "For complete USAGE and HELP type: "
|
||||
<< std::endl << " " << progName << " --help"
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
else
|
||||
usage(_cmd);
|
||||
|
||||
throw ExitException(1);
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::cerr << "PARSE ERROR: " << e.argId() << std::endl
|
||||
<< " " << e.error() << std::endl << std::endl;
|
||||
if ( _cmd.hasHelpAndVersion() )
|
||||
{
|
||||
std::cerr << "Brief USAGE: " << std::endl;
|
||||
_shortUsage( _cmd, std::cerr );
|
||||
std::cerr << std::endl << "For complete USAGE and HELP type: "
|
||||
<< std::endl << " " << progName << " --help"
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
else
|
||||
usage(_cmd);
|
||||
throw ExitException(1);
|
||||
}
|
||||
|
||||
inline void
|
||||
StdOutput::_shortUsage( CmdLineInterface& _cmd,
|
||||
std::ostream& os ) const
|
||||
std::ostream& os ) const
|
||||
{
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
|
||||
std::string s = progName + " ";
|
||||
|
||||
// first the xor
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
s += " {";
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end(); it++ )
|
||||
s += (*it)->shortID() + "|";
|
||||
|
||||
s[s.length()-1] = '}';
|
||||
}
|
||||
|
||||
// then the rest
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
s += " " + (*it)->shortID();
|
||||
|
||||
// if the program name is too long, then adjust the second line offset
|
||||
int secondLineOffset = static_cast<int>(progName.length()) + 2;
|
||||
if ( secondLineOffset > 75/2 )
|
||||
secondLineOffset = static_cast<int>(75/2);
|
||||
|
||||
spacePrint( os, s, 75, 3, secondLineOffset );
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
std::string s = progName + " ";
|
||||
// first the xor
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
s += " {";
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end(); it++ )
|
||||
s += (*it)->shortID() + "|";
|
||||
s[s.length()-1] = '}';
|
||||
}
|
||||
// then the rest
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
s += " " + (*it)->shortID();
|
||||
// if the program name is too long, then adjust the second line offset
|
||||
int secondLineOffset = static_cast<int>(progName.length()) + 2;
|
||||
if ( secondLineOffset > 75/2 )
|
||||
secondLineOffset = static_cast<int>(75/2);
|
||||
spacePrint( os, s, 75, 3, secondLineOffset );
|
||||
}
|
||||
|
||||
inline void
|
||||
StdOutput::_longUsage( CmdLineInterface& _cmd,
|
||||
std::ostream& os ) const
|
||||
std::ostream& os ) const
|
||||
{
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string message = _cmd.getMessage();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
|
||||
// first the xor
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end();
|
||||
it++ )
|
||||
{
|
||||
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||
|
||||
if ( it+1 != xorList[i].end() )
|
||||
spacePrint(os, "-- OR --", 75, 9, 0);
|
||||
}
|
||||
os << std::endl << std::endl;
|
||||
}
|
||||
|
||||
// then the rest
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
{
|
||||
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
os << std::endl;
|
||||
|
||||
spacePrint( os, message, 75, 3, 0 );
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string message = _cmd.getMessage();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
// first the xor
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end();
|
||||
it++ )
|
||||
{
|
||||
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||
if ( it+1 != xorList[i].end() )
|
||||
spacePrint(os, "-- OR --", 75, 9, 0);
|
||||
}
|
||||
os << std::endl << std::endl;
|
||||
}
|
||||
// then the rest
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
if ( !xorHandler.contains( (*it) ) )
|
||||
{
|
||||
spacePrint( os, (*it)->longID(), 75, 3, 3 );
|
||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||
os << std::endl;
|
||||
}
|
||||
os << std::endl;
|
||||
spacePrint( os, message, 75, 3, 0 );
|
||||
}
|
||||
|
||||
inline void StdOutput::spacePrint( std::ostream& os,
|
||||
const std::string& s,
|
||||
int maxWidth,
|
||||
int indentSpaces,
|
||||
int secondLineOffset ) const
|
||||
const std::string& s,
|
||||
int maxWidth,
|
||||
int indentSpaces,
|
||||
int secondLineOffset ) const
|
||||
{
|
||||
int len = static_cast<int>(s.length());
|
||||
|
||||
if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
|
||||
{
|
||||
int allowedLen = maxWidth - indentSpaces;
|
||||
int start = 0;
|
||||
while ( start < len )
|
||||
{
|
||||
// find the substring length
|
||||
// int stringLen = std::min<int>( len - start, allowedLen );
|
||||
// doing it this way to support a VisualC++ 2005 bug
|
||||
using namespace std;
|
||||
int stringLen = min<int>( len - start, allowedLen );
|
||||
|
||||
// trim the length so it doesn't end in middle of a word
|
||||
if ( stringLen == allowedLen )
|
||||
while ( stringLen >= 0 &&
|
||||
s[stringLen+start] != ' ' &&
|
||||
s[stringLen+start] != ',' &&
|
||||
s[stringLen+start] != '|' )
|
||||
stringLen--;
|
||||
|
||||
// ok, the word is longer than the line, so just split
|
||||
// wherever the line ends
|
||||
if ( stringLen <= 0 )
|
||||
stringLen = allowedLen;
|
||||
|
||||
// check for newlines
|
||||
for ( int i = 0; i < stringLen; i++ )
|
||||
if ( s[start+i] == '\n' )
|
||||
stringLen = i+1;
|
||||
|
||||
// print the indent
|
||||
for ( int i = 0; i < indentSpaces; i++ )
|
||||
os << " ";
|
||||
|
||||
if ( start == 0 )
|
||||
{
|
||||
// handle second line offsets
|
||||
indentSpaces += secondLineOffset;
|
||||
|
||||
// adjust allowed len
|
||||
allowedLen -= secondLineOffset;
|
||||
}
|
||||
|
||||
os << s.substr(start,stringLen) << std::endl;
|
||||
|
||||
// so we don't start a line with a space
|
||||
while ( s[stringLen+start] == ' ' && start < len )
|
||||
start++;
|
||||
|
||||
start += stringLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0; i < indentSpaces; i++ )
|
||||
os << " ";
|
||||
os << s << std::endl;
|
||||
}
|
||||
int len = static_cast<int>(s.length());
|
||||
if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
|
||||
{
|
||||
int allowedLen = maxWidth - indentSpaces;
|
||||
int start = 0;
|
||||
while ( start < len )
|
||||
{
|
||||
// find the substring length
|
||||
// int stringLen = std::min<int>( len - start, allowedLen );
|
||||
// doing it this way to support a VisualC++ 2005 bug
|
||||
using namespace std;
|
||||
int stringLen = min<int>( len - start, allowedLen );
|
||||
// trim the length so it doesn't end in middle of a word
|
||||
if ( stringLen == allowedLen )
|
||||
while ( stringLen >= 0 &&
|
||||
s[stringLen+start] != ' ' &&
|
||||
s[stringLen+start] != ',' &&
|
||||
s[stringLen+start] != '|' )
|
||||
stringLen--;
|
||||
// ok, the word is longer than the line, so just split
|
||||
// wherever the line ends
|
||||
if ( stringLen <= 0 )
|
||||
stringLen = allowedLen;
|
||||
// check for newlines
|
||||
for ( int i = 0; i < stringLen; i++ )
|
||||
if ( s[start+i] == '\n' )
|
||||
stringLen = i+1;
|
||||
// print the indent
|
||||
for ( int i = 0; i < indentSpaces; i++ )
|
||||
os << " ";
|
||||
if ( start == 0 )
|
||||
{
|
||||
// handle second line offsets
|
||||
indentSpaces += secondLineOffset;
|
||||
// adjust allowed len
|
||||
allowedLen -= secondLineOffset;
|
||||
}
|
||||
os << s.substr(start,stringLen) << std::endl;
|
||||
// so we don't start a line with a space
|
||||
while ( s[stringLen+start] == ' ' && start < len )
|
||||
start++;
|
||||
start += stringLen;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = 0; i < indentSpaces; i++ )
|
||||
os << " ";
|
||||
os << s << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace TCLAP
|
||||
|
@@ -29,7 +29,8 @@
|
||||
|
||||
#include "Arg.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A simple switch argument. If the switch is set on the command line, then
|
||||
@@ -38,95 +39,95 @@ namespace TCLAP {
|
||||
*/
|
||||
class SwitchArg : public Arg
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The value of the switch.
|
||||
*/
|
||||
bool _value;
|
||||
/**
|
||||
* The value of the switch.
|
||||
*/
|
||||
bool _value;
|
||||
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
bool _default;
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
bool _default;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* SwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param def - The default value for this Switch.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
SwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool def = false,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* SwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param def - The default value for this Switch.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
SwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool def = false,
|
||||
Visitor* v = NULL);
|
||||
|
||||
|
||||
/**
|
||||
* SwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param def - The default value for this Switch.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
SwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
bool def = false,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* SwitchArg constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param def - The default value for this Switch.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
SwitchArg(const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
CmdLineInterface& parser,
|
||||
bool def = false,
|
||||
Visitor* v = NULL);
|
||||
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Checks a string to see if any of the chars in the string
|
||||
* match the flag for this Switch.
|
||||
*/
|
||||
bool combinedSwitchesMatch(std::string& combined);
|
||||
/**
|
||||
* Checks a string to see if any of the chars in the string
|
||||
* match the flag for this Switch.
|
||||
*/
|
||||
bool combinedSwitchesMatch(std::string& combined);
|
||||
|
||||
/**
|
||||
* Returns bool, whether or not the switch has been set.
|
||||
*/
|
||||
bool getValue();
|
||||
/**
|
||||
* Returns bool, whether or not the switch has been set.
|
||||
*/
|
||||
bool getValue();
|
||||
|
||||
virtual void reset();
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Checks to see if we've found the last match in
|
||||
* a combined string.
|
||||
*/
|
||||
bool lastCombined(std::string& combined);
|
||||
private:
|
||||
/**
|
||||
* Checks to see if we've found the last match in
|
||||
* a combined string.
|
||||
*/
|
||||
bool lastCombined(std::string& combined);
|
||||
|
||||
/**
|
||||
* Does the common processing of processArg.
|
||||
*/
|
||||
void commonProcessing();
|
||||
/**
|
||||
* Does the common processing of processArg.
|
||||
*/
|
||||
void commonProcessing();
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -137,9 +138,9 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
||||
const std::string& desc,
|
||||
bool default_val,
|
||||
Visitor* v )
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default( default_val )
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default( default_val )
|
||||
{ }
|
||||
|
||||
inline SwitchArg::SwitchArg(const std::string& flag,
|
||||
@@ -148,114 +149,104 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
||||
CmdLineInterface& parser,
|
||||
bool default_val,
|
||||
Visitor* v )
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default(default_val)
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default(default_val)
|
||||
{
|
||||
parser.add( this );
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
inline bool SwitchArg::getValue() { return _value; }
|
||||
inline bool SwitchArg::getValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
||||
{
|
||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||
if ( combinedSwitches[i] != Arg::blankChar() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||
if ( combinedSwitches[i] != Arg::blankChar() )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
||||
{
|
||||
// make sure this is actually a combined switch
|
||||
if ( combinedSwitches.length() > 0 &&
|
||||
combinedSwitches[0] != Arg::flagStartString()[0] )
|
||||
return false;
|
||||
|
||||
// make sure it isn't a long name
|
||||
if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
|
||||
Arg::nameStartString() )
|
||||
return false;
|
||||
|
||||
// make sure the delimiter isn't in the string
|
||||
if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos )
|
||||
return false;
|
||||
|
||||
// ok, we're not specifying a ValueArg, so we know that we have
|
||||
// a combined switch list.
|
||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||
if ( _flag.length() > 0 &&
|
||||
combinedSwitches[i] == _flag[0] &&
|
||||
_flag[0] != Arg::flagStartString()[0] )
|
||||
{
|
||||
// update the combined switches so this one is no longer present
|
||||
// this is necessary so that no unlabeled args are matched
|
||||
// later in the processing.
|
||||
//combinedSwitches.erase(i,1);
|
||||
combinedSwitches[i] = Arg::blankChar();
|
||||
return true;
|
||||
}
|
||||
|
||||
// none of the switches passed in the list match.
|
||||
return false;
|
||||
// make sure this is actually a combined switch
|
||||
if ( combinedSwitches.length() > 0 &&
|
||||
combinedSwitches[0] != Arg::flagStartString()[0] )
|
||||
return false;
|
||||
// make sure it isn't a long name
|
||||
if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
|
||||
Arg::nameStartString() )
|
||||
return false;
|
||||
// make sure the delimiter isn't in the string
|
||||
if ( combinedSwitches.find_first_of( Arg::delimiter() ) != std::string::npos )
|
||||
return false;
|
||||
// ok, we're not specifying a ValueArg, so we know that we have
|
||||
// a combined switch list.
|
||||
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||
if ( _flag.length() > 0 &&
|
||||
combinedSwitches[i] == _flag[0] &&
|
||||
_flag[0] != Arg::flagStartString()[0] )
|
||||
{
|
||||
// update the combined switches so this one is no longer present
|
||||
// this is necessary so that no unlabeled args are matched
|
||||
// later in the processing.
|
||||
//combinedSwitches.erase(i,1);
|
||||
combinedSwitches[i] = Arg::blankChar();
|
||||
return true;
|
||||
}
|
||||
// none of the switches passed in the list match.
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void SwitchArg::commonProcessing()
|
||||
{
|
||||
if ( _xorSet )
|
||||
throw(CmdLineParseException(
|
||||
"Mutually exclusive argument already set!", toString()));
|
||||
|
||||
if ( _alreadySet )
|
||||
throw(CmdLineParseException("Argument already set!", toString()));
|
||||
|
||||
_alreadySet = true;
|
||||
|
||||
if ( _value == true )
|
||||
_value = false;
|
||||
else
|
||||
_value = true;
|
||||
|
||||
_checkWithVisitor();
|
||||
if ( _xorSet )
|
||||
throw(CmdLineParseException(
|
||||
"Mutually exclusive argument already set!", toString()));
|
||||
if ( _alreadySet )
|
||||
throw(CmdLineParseException("Argument already set!", toString()));
|
||||
_alreadySet = true;
|
||||
if ( _value == true )
|
||||
_value = false;
|
||||
else
|
||||
_value = true;
|
||||
_checkWithVisitor();
|
||||
}
|
||||
|
||||
inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
|
||||
// if the whole string matches the flag or name string
|
||||
if ( argMatches( args[*i] ) )
|
||||
{
|
||||
commonProcessing();
|
||||
|
||||
return true;
|
||||
}
|
||||
// if a substring matches the flag as part of a combination
|
||||
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||
{
|
||||
// check again to ensure we don't misinterpret
|
||||
// this as a MultiSwitchArg
|
||||
if ( combinedSwitchesMatch( args[*i] ) )
|
||||
throw(CmdLineParseException("Argument already set!",
|
||||
toString()));
|
||||
|
||||
commonProcessing();
|
||||
|
||||
// We only want to return true if we've found the last combined
|
||||
// match in the string, otherwise we return true so that other
|
||||
// switches in the combination will have a chance to match.
|
||||
return lastCombined( args[*i] );
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
// if the whole string matches the flag or name string
|
||||
if ( argMatches( args[*i] ) )
|
||||
{
|
||||
commonProcessing();
|
||||
return true;
|
||||
}
|
||||
// if a substring matches the flag as part of a combination
|
||||
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||
{
|
||||
// check again to ensure we don't misinterpret
|
||||
// this as a MultiSwitchArg
|
||||
if ( combinedSwitchesMatch( args[*i] ) )
|
||||
throw(CmdLineParseException("Argument already set!",
|
||||
toString()));
|
||||
commonProcessing();
|
||||
// We only want to return true if we've found the last combined
|
||||
// match in the string, otherwise we return true so that other
|
||||
// switches in the combination will have a chance to match.
|
||||
return lastCombined( args[*i] );
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void SwitchArg::reset()
|
||||
{
|
||||
Arg::reset();
|
||||
_value = _default;
|
||||
Arg::reset();
|
||||
_value = _default;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//End SwitchArg.cpp
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include "MultiArg.h"
|
||||
#include "OptionalUnlabeledTracker.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* Just like a MultiArg, except that the arguments are unlabeled. Basically,
|
||||
@@ -40,260 +41,253 @@ template<class T>
|
||||
class UnlabeledMultiArg : public MultiArg<T>
|
||||
{
|
||||
|
||||
// If compiler has two stage name lookup (as gcc >= 3.4 does)
|
||||
// this is requried to prevent undef. symbols
|
||||
using MultiArg<T>::_ignoreable;
|
||||
using MultiArg<T>::_hasBlanks;
|
||||
using MultiArg<T>::_extractValue;
|
||||
using MultiArg<T>::_typeDesc;
|
||||
using MultiArg<T>::_name;
|
||||
using MultiArg<T>::_description;
|
||||
using MultiArg<T>::_alreadySet;
|
||||
using MultiArg<T>::toString;
|
||||
// If compiler has two stage name lookup (as gcc >= 3.4 does)
|
||||
// this is requried to prevent undef. symbols
|
||||
using MultiArg<T>::_ignoreable;
|
||||
using MultiArg<T>::_hasBlanks;
|
||||
using MultiArg<T>::_extractValue;
|
||||
using MultiArg<T>::_typeDesc;
|
||||
using MultiArg<T>::_name;
|
||||
using MultiArg<T>::_description;
|
||||
using MultiArg<T>::_alreadySet;
|
||||
using MultiArg<T>::toString;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Constructor.
|
||||
* \param name - The name of the Arg. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Whether or not this argument can be ignored
|
||||
* using the "--" flag.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
UnlabeledMultiArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Returns the a short id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
/**
|
||||
* Returns the a short id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Returns the a long id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
/**
|
||||
* Returns the a long id string. Used in the usage.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Opertor ==.
|
||||
* \param a - The Arg to be compared to this.
|
||||
*/
|
||||
virtual bool operator==(const Arg& a) const;
|
||||
/**
|
||||
* Opertor ==.
|
||||
* \param a - The Arg to be compared to this.
|
||||
*/
|
||||
virtual bool operator==(const Arg& a) const;
|
||||
|
||||
/**
|
||||
* Pushes this to back of list rather than front.
|
||||
* \param argList - The list this should be added to.
|
||||
*/
|
||||
virtual void addToList( std::list<Arg*>& argList ) const;
|
||||
/**
|
||||
* Pushes this to back of list rather than front.
|
||||
* \param argList - The list this should be added to.
|
||||
*/
|
||||
virtual void addToList( std::list<Arg*>& argList ) const;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
parser.add( this );
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
parser.add( this );
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
|
||||
// never ignore an unlabeled multi arg
|
||||
|
||||
|
||||
// always take the first value, regardless of the start string
|
||||
_extractValue( args[(*i)] );
|
||||
|
||||
/*
|
||||
// continue taking args until we hit the end or a start string
|
||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||
args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
// never ignore an unlabeled multi arg
|
||||
// always take the first value, regardless of the start string
|
||||
_extractValue( args[(*i)] );
|
||||
/*
|
||||
// continue taking args until we hit the end or a start string
|
||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||
args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
|
||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
|
||||
_alreadySet = true;
|
||||
|
||||
return true;
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
_alreadySet = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + "> ...";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + "> ...";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + "> (accepted multiple times)";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + "> (accepted multiple times)";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
|
||||
{
|
||||
if ( _name == a.getName() || _description == a.getDescription() )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
if ( _name == a.getName() || _description == a.getDescription() )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
|
||||
{
|
||||
argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
|
||||
argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,7 +31,8 @@
|
||||
#include "OptionalUnlabeledTracker.h"
|
||||
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The basic unlabeled argument that parses a value.
|
||||
@@ -43,166 +44,166 @@ template<class T>
|
||||
class UnlabeledValueArg : public ValueArg<T>
|
||||
{
|
||||
|
||||
// If compiler has two stage name lookup (as gcc >= 3.4 does)
|
||||
// this is requried to prevent undef. symbols
|
||||
using ValueArg<T>::_ignoreable;
|
||||
using ValueArg<T>::_hasBlanks;
|
||||
using ValueArg<T>::_extractValue;
|
||||
using ValueArg<T>::_typeDesc;
|
||||
using ValueArg<T>::_name;
|
||||
using ValueArg<T>::_description;
|
||||
using ValueArg<T>::_alreadySet;
|
||||
using ValueArg<T>::toString;
|
||||
// If compiler has two stage name lookup (as gcc >= 3.4 does)
|
||||
// this is requried to prevent undef. symbols
|
||||
using ValueArg<T>::_ignoreable;
|
||||
using ValueArg<T>::_hasBlanks;
|
||||
using ValueArg<T>::_extractValue;
|
||||
using ValueArg<T>::_typeDesc;
|
||||
using ValueArg<T>::_name;
|
||||
using ValueArg<T>::_description;
|
||||
using ValueArg<T>::_alreadySet;
|
||||
using ValueArg<T>::toString;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL);
|
||||
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL );
|
||||
|
||||
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* UnlabeledValueArg constructor.
|
||||
* \param name - A one word name for the argument. Note that this is used for
|
||||
* identification, not as a long flag.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param ignoreable - Allows you to specify that this argument can be
|
||||
* ignored if the '--' flag is set. This defaults to false (cannot
|
||||
* be ignored) and should generally stay that way unless you have
|
||||
* some special need for certain arguments to be ignored.
|
||||
* \param v - Optional Vistor. You should leave this blank unless
|
||||
* you have a very good reason.
|
||||
*/
|
||||
UnlabeledValueArg( const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable = false,
|
||||
Visitor* v = NULL);
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. Handling specific to
|
||||
* unlabled arguments.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings.
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. Handling specific to
|
||||
* unlabled arguments.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings.
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Overrides shortID for specific behavior.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
/**
|
||||
* Overrides shortID for specific behavior.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Overrides longID for specific behavior.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
/**
|
||||
* Overrides longID for specific behavior.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val="val") const;
|
||||
|
||||
/**
|
||||
* Overrides operator== for specific behavior.
|
||||
*/
|
||||
virtual bool operator==(const Arg& a ) const;
|
||||
/**
|
||||
* Overrides operator== for specific behavior.
|
||||
*/
|
||||
virtual bool operator==(const Arg& a ) const;
|
||||
|
||||
/**
|
||||
* Instead of pushing to the front of list, push to the back.
|
||||
* \param argList - The list to add this to.
|
||||
*/
|
||||
virtual void addToList( std::list<Arg*>& argList ) const;
|
||||
/**
|
||||
* Instead of pushing to the front of list, push to the back.
|
||||
* \param argList - The list to add this to.
|
||||
*/
|
||||
virtual void addToList( std::list<Arg*>& argList ) const;
|
||||
|
||||
};
|
||||
|
||||
@@ -211,34 +212,32 @@ class UnlabeledValueArg : public ValueArg<T>
|
||||
*/
|
||||
template<class T>
|
||||
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
parser.add( this );
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,31 +246,31 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
template<class T>
|
||||
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
bool req,
|
||||
T val,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T val,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
parser.add( this );
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,18 +279,14 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
template<class T>
|
||||
bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
|
||||
if ( _alreadySet )
|
||||
return false;
|
||||
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
|
||||
// never ignore an unlabeled arg
|
||||
|
||||
_extractValue( args[*i] );
|
||||
_alreadySet = true;
|
||||
return true;
|
||||
if ( _alreadySet )
|
||||
return false;
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
// never ignore an unlabeled arg
|
||||
_extractValue( args[*i] );
|
||||
_alreadySet = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,8 +295,8 @@ bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
template<class T>
|
||||
std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + ">";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return std::string("<") + _typeDesc + ">";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,12 +305,11 @@ std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
|
||||
template<class T>
|
||||
std::string UnlabeledValueArg<T>::longID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
|
||||
// Ideally we would like to be able to use RTTI to return the name
|
||||
// of the type required for this argument. However, g++ at least,
|
||||
// doesn't appear to return terribly useful "names" of the types.
|
||||
return std::string("<") + _typeDesc + ">";
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
// Ideally we would like to be able to use RTTI to return the name
|
||||
// of the type required for this argument. However, g++ at least,
|
||||
// doesn't appear to return terribly useful "names" of the types.
|
||||
return std::string("<") + _typeDesc + ">";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,16 +318,16 @@ std::string UnlabeledValueArg<T>::longID(const std::string& val) const
|
||||
template<class T>
|
||||
bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
|
||||
{
|
||||
if ( _name == a.getName() || _description == a.getDescription() )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
if ( _name == a.getName() || _description == a.getDescription() )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
|
||||
{
|
||||
argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
|
||||
argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include "Arg.h"
|
||||
#include "Constraint.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The basic labeled argument that parses a value.
|
||||
@@ -42,206 +43,206 @@ namespace TCLAP {
|
||||
template<class T>
|
||||
class ValueArg : public Arg
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The value parsed from the command line.
|
||||
* Can be of any type, as long as the >> operator for the type
|
||||
* is defined.
|
||||
*/
|
||||
T _value;
|
||||
/**
|
||||
* The value parsed from the command line.
|
||||
* Can be of any type, as long as the >> operator for the type
|
||||
* is defined.
|
||||
*/
|
||||
T _value;
|
||||
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
T _default;
|
||||
/**
|
||||
* Used to support the reset() method so that ValueArg can be
|
||||
* reset to their constructed value.
|
||||
*/
|
||||
T _default;
|
||||
|
||||
/**
|
||||
* A human readable description of the type to be parsed.
|
||||
* This is a hack, plain and simple. Ideally we would use RTTI to
|
||||
* return the name of type T, but until there is some sort of
|
||||
* consistent support for human readable names, we are left to our
|
||||
* own devices.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
/**
|
||||
* A human readable description of the type to be parsed.
|
||||
* This is a hack, plain and simple. Ideally we would use RTTI to
|
||||
* return the name of type T, but until there is some sort of
|
||||
* consistent support for human readable names, we are left to our
|
||||
* own devices.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
|
||||
/**
|
||||
* A Constraint this Arg must conform to.
|
||||
*/
|
||||
Constraint<T>* _constraint;
|
||||
/**
|
||||
* A Constraint this Arg must conform to.
|
||||
*/
|
||||
Constraint<T>* _constraint;
|
||||
|
||||
/**
|
||||
* Extracts the value from the string.
|
||||
* Attempts to parse string as type T, if this fails an exception
|
||||
* is thrown.
|
||||
* \param val - value to be parsed.
|
||||
*/
|
||||
void _extractValue( const std::string& val );
|
||||
/**
|
||||
* Extracts the value from the string.
|
||||
* Attempts to parse string as type T, if this fails an exception
|
||||
* is thrown.
|
||||
* \param val - value to be parsed.
|
||||
*/
|
||||
void _extractValue( const std::string& val );
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v = NULL);
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v = NULL);
|
||||
|
||||
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param typeDesc - A short, human readable description of the
|
||||
* type that this object expects. This is used in the generation
|
||||
* of the USAGE statement. The goal is to be helpful to the end user
|
||||
* of the program.
|
||||
* \param parser - A CmdLine parser object to add this Arg to
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param parser - A CmdLine parser object to add this Arg to.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v = NULL );
|
||||
/**
|
||||
* Labeled ValueArg constructor.
|
||||
* You could conceivably call this constructor with a blank flag,
|
||||
* but that would make you a bad person. It would also cause
|
||||
* an exception to be thrown. If you want an unlabeled argument,
|
||||
* use the other constructor.
|
||||
* \param flag - The one character flag that identifies this
|
||||
* argument on the command line.
|
||||
* \param name - A one word name for the argument. Can be
|
||||
* used as a long flag on the command line.
|
||||
* \param desc - A description of what the argument is for or
|
||||
* does.
|
||||
* \param req - Whether the argument is required on the command
|
||||
* line.
|
||||
* \param value - The default value assigned to this argument if it
|
||||
* is not present on the command line.
|
||||
* \param constraint - A pointer to a Constraint object used
|
||||
* to constrain this Arg.
|
||||
* \param v - An optional visitor. You probably should not
|
||||
* use this unless you have a very good reason.
|
||||
*/
|
||||
ValueArg( const std::string& flag,
|
||||
const std::string& name,
|
||||
const std::string& desc,
|
||||
bool req,
|
||||
T value,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v = NULL );
|
||||
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
/**
|
||||
* Handles the processing of the argument.
|
||||
* This re-implements the Arg version of this method to set the
|
||||
* _value of the argument appropriately. It knows the difference
|
||||
* between labeled and unlabeled.
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, std::vector<std::string>& args);
|
||||
|
||||
/**
|
||||
* Returns the value of the argument.
|
||||
*/
|
||||
T& getValue() ;
|
||||
/**
|
||||
* Returns the value of the argument.
|
||||
*/
|
||||
T& getValue() ;
|
||||
|
||||
/**
|
||||
* Specialization of shortID.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val = "val") const;
|
||||
/**
|
||||
* Specialization of shortID.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string shortID(const std::string& val = "val") const;
|
||||
|
||||
/**
|
||||
* Specialization of longID.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val = "val") const;
|
||||
/**
|
||||
* Specialization of longID.
|
||||
* \param val - value to be used.
|
||||
*/
|
||||
virtual std::string longID(const std::string& val = "val") const;
|
||||
|
||||
virtual void reset() ;
|
||||
virtual void reset() ;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
ValueArg<T>(const ValueArg<T>& rhs);
|
||||
ValueArg<T>& operator=(const ValueArg<T>& rhs);
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
ValueArg<T>(const ValueArg<T>& rhs);
|
||||
ValueArg<T>& operator=(const ValueArg<T>& rhs);
|
||||
};
|
||||
|
||||
|
||||
@@ -256,11 +257,11 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL )
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL )
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
@@ -272,13 +273,13 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL )
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL )
|
||||
{
|
||||
parser.add( this );
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -289,11 +290,11 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
T val,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint )
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint )
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
@@ -305,13 +306,13 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint )
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint )
|
||||
{
|
||||
parser.add( this );
|
||||
parser.add( this );
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +320,10 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
* Implementation of getValue().
|
||||
*/
|
||||
template<class T>
|
||||
T& ValueArg<T>::getValue() { return _value; }
|
||||
T& ValueArg<T>::getValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of processArg().
|
||||
@@ -327,53 +331,46 @@ T& ValueArg<T>::getValue() { return _value; }
|
||||
template<class T>
|
||||
bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
{
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
|
||||
std::string flag = args[*i];
|
||||
|
||||
std::string value = "";
|
||||
trimFlag( flag, value );
|
||||
|
||||
if ( argMatches( flag ) )
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
if ( _hasBlanks( args[*i] ) )
|
||||
return false;
|
||||
std::string flag = args[*i];
|
||||
std::string value = "";
|
||||
trimFlag( flag, value );
|
||||
if ( argMatches( flag ) )
|
||||
{
|
||||
if ( _alreadySet )
|
||||
{
|
||||
if ( _alreadySet )
|
||||
{
|
||||
if ( _xorSet )
|
||||
throw( CmdLineParseException(
|
||||
"Mutually exclusive argument already set!",
|
||||
toString()) );
|
||||
else
|
||||
throw( CmdLineParseException("Argument already set!",
|
||||
toString()) );
|
||||
}
|
||||
|
||||
if ( Arg::delimiter() != ' ' && value == "" )
|
||||
throw( ArgParseException(
|
||||
"Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
if ( static_cast<unsigned int>(*i) < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgParseException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
if ( _xorSet )
|
||||
throw( CmdLineParseException(
|
||||
"Mutually exclusive argument already set!",
|
||||
toString()) );
|
||||
else
|
||||
throw( CmdLineParseException("Argument already set!",
|
||||
toString()) );
|
||||
}
|
||||
if ( Arg::delimiter() != ' ' && value == "" )
|
||||
throw( ArgParseException(
|
||||
"Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
if ( static_cast<unsigned int>(*i) < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgParseException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
return false;
|
||||
_extractValue( value );
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,8 +379,8 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
template<class T>
|
||||
std::string ValueArg<T>::shortID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::shortID( _typeDesc );
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::shortID( _typeDesc );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,32 +389,34 @@ std::string ValueArg<T>::shortID(const std::string& val) const
|
||||
template<class T>
|
||||
std::string ValueArg<T>::longID(const std::string& val) const
|
||||
{
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::longID( _typeDesc );
|
||||
static_cast<void>(val); // Ignore input, don't warn
|
||||
return Arg::longID( _typeDesc );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void ValueArg<T>::_extractValue( const std::string& val )
|
||||
{
|
||||
try {
|
||||
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
|
||||
} catch( ArgParseException &e) {
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _value ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
+ "' does not meet constraint: "
|
||||
+ _constraint->description(),
|
||||
toString() ) );
|
||||
try
|
||||
{
|
||||
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
|
||||
}
|
||||
catch( ArgParseException &e)
|
||||
{
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _value ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
+ "' does not meet constraint: "
|
||||
+ _constraint->description(),
|
||||
toString() ) );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void ValueArg<T>::reset()
|
||||
{
|
||||
Arg::reset();
|
||||
_value = _default;
|
||||
Arg::reset();
|
||||
_value = _default;
|
||||
}
|
||||
|
||||
} // namespace TCLAP
|
||||
|
@@ -41,7 +41,8 @@
|
||||
#error "Need a stringstream (sstream or strstream) to compile!"
|
||||
#endif
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A Constraint that constrains the Arg to only those values specified
|
||||
@@ -51,95 +52,91 @@ template<class T>
|
||||
class ValuesConstraint : public Constraint<T>
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param allowed - vector of allowed values.
|
||||
*/
|
||||
ValuesConstraint(std::vector<T>& allowed);
|
||||
/**
|
||||
* Constructor.
|
||||
* \param allowed - vector of allowed values.
|
||||
*/
|
||||
ValuesConstraint(std::vector<T>& allowed);
|
||||
|
||||
/**
|
||||
* Virtual destructor.
|
||||
*/
|
||||
virtual ~ValuesConstraint() {}
|
||||
/**
|
||||
* Virtual destructor.
|
||||
*/
|
||||
virtual ~ValuesConstraint() {}
|
||||
|
||||
/**
|
||||
* Returns a description of the Constraint.
|
||||
*/
|
||||
virtual std::string description() const;
|
||||
/**
|
||||
* Returns a description of the Constraint.
|
||||
*/
|
||||
virtual std::string description() const;
|
||||
|
||||
/**
|
||||
* Returns the short ID for the Constraint.
|
||||
*/
|
||||
virtual std::string shortID() const;
|
||||
/**
|
||||
* Returns the short ID for the Constraint.
|
||||
*/
|
||||
virtual std::string shortID() const;
|
||||
|
||||
/**
|
||||
* The method used to verify that the value parsed from the command
|
||||
* line meets the constraint.
|
||||
* \param value - The value that will be checked.
|
||||
*/
|
||||
virtual bool check(const T& value) const;
|
||||
/**
|
||||
* The method used to verify that the value parsed from the command
|
||||
* line meets the constraint.
|
||||
* \param value - The value that will be checked.
|
||||
*/
|
||||
virtual bool check(const T& value) const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The list of valid values.
|
||||
*/
|
||||
std::vector<T> _allowed;
|
||||
/**
|
||||
* The list of valid values.
|
||||
*/
|
||||
std::vector<T> _allowed;
|
||||
|
||||
/**
|
||||
* The string used to describe the allowed values of this constraint.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
/**
|
||||
* The string used to describe the allowed values of this constraint.
|
||||
*/
|
||||
std::string _typeDesc;
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
|
||||
: _allowed(allowed),
|
||||
_typeDesc("")
|
||||
: _allowed(allowed),
|
||||
_typeDesc("")
|
||||
{
|
||||
for ( unsigned int i = 0; i < _allowed.size(); i++ )
|
||||
{
|
||||
|
||||
for ( unsigned int i = 0; i < _allowed.size(); i++ )
|
||||
{
|
||||
#if defined(HAVE_SSTREAM)
|
||||
std::ostringstream os;
|
||||
std::ostringstream os;
|
||||
#elif defined(HAVE_STRSTREAM)
|
||||
std::ostrstream os;
|
||||
std::ostrstream os;
|
||||
#else
|
||||
#error "Need a stringstream (sstream or strstream) to compile!"
|
||||
#endif
|
||||
|
||||
os << _allowed[i];
|
||||
|
||||
std::string temp( os.str() );
|
||||
|
||||
if ( i > 0 )
|
||||
_typeDesc += "|";
|
||||
_typeDesc += temp;
|
||||
}
|
||||
os << _allowed[i];
|
||||
std::string temp( os.str() );
|
||||
if ( i > 0 )
|
||||
_typeDesc += "|";
|
||||
_typeDesc += temp;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool ValuesConstraint<T>::check( const T& val ) const
|
||||
{
|
||||
if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::string ValuesConstraint<T>::shortID() const
|
||||
{
|
||||
return _typeDesc;
|
||||
return _typeDesc;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::string ValuesConstraint<T>::description() const
|
||||
{
|
||||
return _typeDesc;
|
||||
return _typeDesc;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -28,7 +28,8 @@
|
||||
#include "CmdLineOutput.h"
|
||||
#include "Visitor.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A Vistor that will call the version method of the given CmdLineOutput
|
||||
@@ -36,43 +37,44 @@ namespace TCLAP {
|
||||
*/
|
||||
class VersionVisitor: public Visitor
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
VersionVisitor(const VersionVisitor& rhs);
|
||||
VersionVisitor& operator=(const VersionVisitor& rhs);
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
VersionVisitor(const VersionVisitor& rhs);
|
||||
VersionVisitor& operator=(const VersionVisitor& rhs);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The CmdLine of interest.
|
||||
*/
|
||||
CmdLineInterface* _cmd;
|
||||
/**
|
||||
* The CmdLine of interest.
|
||||
*/
|
||||
CmdLineInterface* _cmd;
|
||||
|
||||
/**
|
||||
* The output object.
|
||||
*/
|
||||
CmdLineOutput** _out;
|
||||
/**
|
||||
* The output object.
|
||||
*/
|
||||
CmdLineOutput** _out;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* \param cmd - The CmdLine the output is generated for.
|
||||
* \param out - The type of output.
|
||||
*/
|
||||
VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out )
|
||||
: Visitor(), _cmd( cmd ), _out( out ) { }
|
||||
/**
|
||||
* Constructor.
|
||||
* \param cmd - The CmdLine the output is generated for.
|
||||
* \param out - The type of output.
|
||||
*/
|
||||
VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out )
|
||||
: Visitor(), _cmd( cmd ), _out( out ) { }
|
||||
|
||||
/**
|
||||
* Calls the version method of the output object using the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit() {
|
||||
(*_out)->version(*_cmd);
|
||||
throw ExitException(0);
|
||||
}
|
||||
/**
|
||||
* Calls the version method of the output object using the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit()
|
||||
{
|
||||
(*_out)->version(*_cmd);
|
||||
throw ExitException(0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@@ -23,29 +23,30 @@
|
||||
#ifndef TCLAP_VISITOR_H
|
||||
#define TCLAP_VISITOR_H
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A base class that defines the interface for visitors.
|
||||
*/
|
||||
class Visitor
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor. Does nothing.
|
||||
*/
|
||||
Visitor() { }
|
||||
/**
|
||||
* Constructor. Does nothing.
|
||||
*/
|
||||
Visitor() { }
|
||||
|
||||
/**
|
||||
* Destructor. Does nothing.
|
||||
*/
|
||||
virtual ~Visitor() { }
|
||||
/**
|
||||
* Destructor. Does nothing.
|
||||
*/
|
||||
virtual ~Visitor() { }
|
||||
|
||||
/**
|
||||
* Does nothing. Should be overridden by child.
|
||||
*/
|
||||
virtual void visit() { }
|
||||
/**
|
||||
* Does nothing. Should be overridden by child.
|
||||
*/
|
||||
virtual void visit() { }
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* This class handles lists of Arg's that are to be XOR'd on the command
|
||||
@@ -37,54 +38,54 @@ namespace TCLAP {
|
||||
*/
|
||||
class XorHandler
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The list of of lists of Arg's to be or'd together.
|
||||
*/
|
||||
std::vector< std::vector<Arg*> > _orList;
|
||||
/**
|
||||
* The list of of lists of Arg's to be or'd together.
|
||||
*/
|
||||
std::vector< std::vector<Arg*> > _orList;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor. Does nothing.
|
||||
*/
|
||||
XorHandler( ) : _orList(std::vector< std::vector<Arg*> >()) {}
|
||||
/**
|
||||
* Constructor. Does nothing.
|
||||
*/
|
||||
XorHandler( ) : _orList(std::vector< std::vector<Arg*> >()) {}
|
||||
|
||||
/**
|
||||
* Add a list of Arg*'s that will be orred together.
|
||||
* \param ors - list of Arg* that will be xor'd.
|
||||
*/
|
||||
void add( std::vector<Arg*>& ors );
|
||||
/**
|
||||
* Add a list of Arg*'s that will be orred together.
|
||||
* \param ors - list of Arg* that will be xor'd.
|
||||
*/
|
||||
void add( std::vector<Arg*>& ors );
|
||||
|
||||
/**
|
||||
* Checks whether the specified Arg is in one of the xor lists and
|
||||
* if it does match one, returns the size of the xor list that the
|
||||
* Arg matched. If the Arg matches, then it also sets the rest of
|
||||
* the Arg's in the list. You shouldn't use this.
|
||||
* \param a - The Arg to be checked.
|
||||
*/
|
||||
int check( const Arg* a );
|
||||
/**
|
||||
* Checks whether the specified Arg is in one of the xor lists and
|
||||
* if it does match one, returns the size of the xor list that the
|
||||
* Arg matched. If the Arg matches, then it also sets the rest of
|
||||
* the Arg's in the list. You shouldn't use this.
|
||||
* \param a - The Arg to be checked.
|
||||
*/
|
||||
int check( const Arg* a );
|
||||
|
||||
/**
|
||||
* Returns the XOR specific short usage.
|
||||
*/
|
||||
std::string shortUsage();
|
||||
/**
|
||||
* Returns the XOR specific short usage.
|
||||
*/
|
||||
std::string shortUsage();
|
||||
|
||||
/**
|
||||
* Prints the XOR specific long usage.
|
||||
* \param os - Stream to print to.
|
||||
*/
|
||||
void printLongUsage(std::ostream& os);
|
||||
/**
|
||||
* Prints the XOR specific long usage.
|
||||
* \param os - Stream to print to.
|
||||
*/
|
||||
void printLongUsage(std::ostream& os);
|
||||
|
||||
/**
|
||||
* Simply checks whether the Arg is contained in one of the arg
|
||||
* lists.
|
||||
* \param a - The Arg to be checked.
|
||||
*/
|
||||
bool contains( const Arg* a );
|
||||
/**
|
||||
* Simply checks whether the Arg is contained in one of the arg
|
||||
* lists.
|
||||
* \param a - The Arg to be checked.
|
||||
*/
|
||||
bool contains( const Arg* a );
|
||||
|
||||
std::vector< std::vector<Arg*> >& getXorList();
|
||||
std::vector< std::vector<Arg*> >& getXorList();
|
||||
|
||||
};
|
||||
|
||||
@@ -94,65 +95,61 @@ class XorHandler
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
inline void XorHandler::add( std::vector<Arg*>& ors )
|
||||
{
|
||||
_orList.push_back( ors );
|
||||
_orList.push_back( ors );
|
||||
}
|
||||
|
||||
inline int XorHandler::check( const Arg* a )
|
||||
{
|
||||
// iterate over each XOR list
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
|
||||
{
|
||||
// if the XOR list contains the arg..
|
||||
ArgVectorIterator ait = std::find( _orList[i].begin(),
|
||||
_orList[i].end(), a );
|
||||
if ( ait != _orList[i].end() )
|
||||
{
|
||||
// first check to see if a mutually exclusive switch
|
||||
// has not already been set
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a != (*it) && (*it)->isSet() )
|
||||
throw(CmdLineParseException(
|
||||
"Mutually exclusive argument already set!",
|
||||
(*it)->toString()));
|
||||
|
||||
// go through and set each arg that is not a
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a != (*it) )
|
||||
(*it)->xorSet();
|
||||
|
||||
// return the number of required args that have now been set
|
||||
if ( (*ait)->allowMore() )
|
||||
return 0;
|
||||
else
|
||||
return static_cast<int>(_orList[i].size());
|
||||
}
|
||||
}
|
||||
|
||||
if ( a->isRequired() )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
// iterate over each XOR list
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
|
||||
{
|
||||
// if the XOR list contains the arg..
|
||||
ArgVectorIterator ait = std::find( _orList[i].begin(),
|
||||
_orList[i].end(), a );
|
||||
if ( ait != _orList[i].end() )
|
||||
{
|
||||
// first check to see if a mutually exclusive switch
|
||||
// has not already been set
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a != (*it) && (*it)->isSet() )
|
||||
throw(CmdLineParseException(
|
||||
"Mutually exclusive argument already set!",
|
||||
(*it)->toString()));
|
||||
// go through and set each arg that is not a
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a != (*it) )
|
||||
(*it)->xorSet();
|
||||
// return the number of required args that have now been set
|
||||
if ( (*ait)->allowMore() )
|
||||
return 0;
|
||||
else
|
||||
return static_cast<int>(_orList[i].size());
|
||||
}
|
||||
}
|
||||
if ( a->isRequired() )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool XorHandler::contains( const Arg* a )
|
||||
{
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a == (*it) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
|
||||
for ( ArgVectorIterator it = _orList[i].begin();
|
||||
it != _orList[i].end();
|
||||
it++ )
|
||||
if ( a == (*it) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::vector< std::vector<Arg*> >& XorHandler::getXorList()
|
||||
{
|
||||
return _orList;
|
||||
return _orList;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -34,7 +34,8 @@
|
||||
#include <tclap/XorHandler.h>
|
||||
#include <tclap/Arg.h>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A class that generates a Zsh completion function as output from the usage()
|
||||
@@ -43,280 +44,266 @@ namespace TCLAP {
|
||||
class ZshCompletionOutput : public CmdLineOutput
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
ZshCompletionOutput();
|
||||
ZshCompletionOutput();
|
||||
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the usage to stdout. Can be overridden to
|
||||
* produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void usage(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
/**
|
||||
* Prints the version to stdout. Can be overridden
|
||||
* to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
*/
|
||||
virtual void version(CmdLineInterface& c);
|
||||
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
/**
|
||||
* Prints (to stderr) an error message, short usage
|
||||
* Can be overridden to produce alternative behavior.
|
||||
* \param c - The CmdLine object the output is generated for.
|
||||
* \param e - The ArgException that caused the failure.
|
||||
*/
|
||||
virtual void failure(CmdLineInterface& c,
|
||||
ArgException& e );
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
void basename( std::string& s );
|
||||
void quoteSpecialChars( std::string& s );
|
||||
void basename( std::string& s );
|
||||
void quoteSpecialChars( std::string& s );
|
||||
|
||||
std::string getMutexList( CmdLineInterface& _cmd, Arg* a );
|
||||
void printOption( Arg* it, std::string mutex );
|
||||
void printArg( Arg* it );
|
||||
std::string getMutexList( CmdLineInterface& _cmd, Arg* a );
|
||||
void printOption( Arg* it, std::string mutex );
|
||||
void printArg( Arg* it );
|
||||
|
||||
std::map<std::string, std::string> common;
|
||||
char theDelimiter;
|
||||
std::map<std::string, std::string> common;
|
||||
char theDelimiter;
|
||||
};
|
||||
|
||||
ZshCompletionOutput::ZshCompletionOutput()
|
||||
: common(std::map<std::string, std::string>()),
|
||||
theDelimiter('=')
|
||||
: common(std::map<std::string, std::string>()),
|
||||
theDelimiter('=')
|
||||
{
|
||||
common["host"] = "_hosts";
|
||||
common["hostname"] = "_hosts";
|
||||
common["file"] = "_files";
|
||||
common["filename"] = "_files";
|
||||
common["user"] = "_users";
|
||||
common["username"] = "_users";
|
||||
common["directory"] = "_directories";
|
||||
common["path"] = "_directories";
|
||||
common["url"] = "_urls";
|
||||
common["host"] = "_hosts";
|
||||
common["hostname"] = "_hosts";
|
||||
common["file"] = "_files";
|
||||
common["filename"] = "_files";
|
||||
common["user"] = "_users";
|
||||
common["username"] = "_users";
|
||||
common["directory"] = "_directories";
|
||||
common["path"] = "_directories";
|
||||
common["url"] = "_urls";
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::version(CmdLineInterface& _cmd)
|
||||
{
|
||||
std::cout << _cmd.getVersion() << std::endl;
|
||||
std::cout << _cmd.getVersion() << std::endl;
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd )
|
||||
{
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
theDelimiter = _cmd.getDelimiter();
|
||||
basename(progName);
|
||||
|
||||
std::cout << "#compdef " << progName << std::endl << std::endl <<
|
||||
"# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl <<
|
||||
"_arguments -s -S";
|
||||
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->shortID().at(0) == '<' )
|
||||
printArg((*it));
|
||||
else if ( (*it)->getFlag() != "-" )
|
||||
printOption((*it), getMutexList(_cmd, *it));
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::list<Arg*> argList = _cmd.getArgList();
|
||||
std::string progName = _cmd.getProgramName();
|
||||
std::string xversion = _cmd.getVersion();
|
||||
theDelimiter = _cmd.getDelimiter();
|
||||
basename(progName);
|
||||
std::cout << "#compdef " << progName << std::endl << std::endl <<
|
||||
"# " << progName << " version " << _cmd.getVersion() << std::endl << std::endl <<
|
||||
"_arguments -s -S";
|
||||
for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->shortID().at(0) == '<' )
|
||||
printArg((*it));
|
||||
else if ( (*it)->getFlag() != "-" )
|
||||
printOption((*it), getMutexList(_cmd, *it));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::failure( CmdLineInterface& _cmd,
|
||||
ArgException& e )
|
||||
ArgException& e )
|
||||
{
|
||||
static_cast<void>(_cmd); // unused
|
||||
std::cout << e.what() << std::endl;
|
||||
static_cast<void>(_cmd); // unused
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::quoteSpecialChars( std::string& s )
|
||||
{
|
||||
size_t idx = s.find_last_of(':');
|
||||
while ( idx != std::string::npos )
|
||||
{
|
||||
s.insert(idx, 1, '\\');
|
||||
idx = s.find_last_of(':', idx);
|
||||
}
|
||||
idx = s.find_last_of('\'');
|
||||
while ( idx != std::string::npos )
|
||||
{
|
||||
s.insert(idx, "'\\'");
|
||||
if (idx == 0)
|
||||
idx = std::string::npos;
|
||||
else
|
||||
idx = s.find_last_of('\'', --idx);
|
||||
}
|
||||
size_t idx = s.find_last_of(':');
|
||||
while ( idx != std::string::npos )
|
||||
{
|
||||
s.insert(idx, 1, '\\');
|
||||
idx = s.find_last_of(':', idx);
|
||||
}
|
||||
idx = s.find_last_of('\'');
|
||||
while ( idx != std::string::npos )
|
||||
{
|
||||
s.insert(idx, "'\\'");
|
||||
if (idx == 0)
|
||||
idx = std::string::npos;
|
||||
else
|
||||
idx = s.find_last_of('\'', --idx);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::basename( std::string& s )
|
||||
{
|
||||
size_t p = s.find_last_of('/');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
s.erase(0, p + 1);
|
||||
}
|
||||
size_t p = s.find_last_of('/');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
s.erase(0, p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::printArg(Arg* a)
|
||||
{
|
||||
static int count = 1;
|
||||
|
||||
std::cout << " \\" << std::endl << " '";
|
||||
if ( a->acceptsMultipleValues() )
|
||||
std::cout << '*';
|
||||
else
|
||||
std::cout << count++;
|
||||
std::cout << ':';
|
||||
if ( !a->isRequired() )
|
||||
std::cout << ':';
|
||||
|
||||
std::cout << a->getName() << ':';
|
||||
std::map<std::string, std::string>::iterator compArg = common.find(a->getName());
|
||||
if ( compArg != common.end() )
|
||||
{
|
||||
std::cout << compArg->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "_guard \"^-*\" " << a->getName();
|
||||
}
|
||||
std::cout << '\'';
|
||||
static int count = 1;
|
||||
std::cout << " \\" << std::endl << " '";
|
||||
if ( a->acceptsMultipleValues() )
|
||||
std::cout << '*';
|
||||
else
|
||||
std::cout << count++;
|
||||
std::cout << ':';
|
||||
if ( !a->isRequired() )
|
||||
std::cout << ':';
|
||||
std::cout << a->getName() << ':';
|
||||
std::map<std::string, std::string>::iterator compArg = common.find(a->getName());
|
||||
if ( compArg != common.end() )
|
||||
{
|
||||
std::cout << compArg->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "_guard \"^-*\" " << a->getName();
|
||||
}
|
||||
std::cout << '\'';
|
||||
}
|
||||
|
||||
inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
||||
{
|
||||
std::string flag = a->flagStartChar() + a->getFlag();
|
||||
std::string name = a->nameStartString() + a->getName();
|
||||
std::string desc = a->getDescription();
|
||||
|
||||
// remove full stop and capitalisation from description as
|
||||
// this is the convention for zsh function
|
||||
if (!desc.compare(0, 12, "(required) "))
|
||||
{
|
||||
desc.erase(0, 12);
|
||||
}
|
||||
if (!desc.compare(0, 15, "(OR required) "))
|
||||
{
|
||||
desc.erase(0, 15);
|
||||
}
|
||||
size_t len = desc.length();
|
||||
if (len && desc.at(--len) == '.')
|
||||
{
|
||||
desc.erase(len);
|
||||
}
|
||||
if (len)
|
||||
{
|
||||
desc.replace(0, 1, 1, tolower(desc.at(0)));
|
||||
}
|
||||
|
||||
std::cout << " \\" << std::endl << " '" << mutex;
|
||||
|
||||
if ( a->getFlag().empty() )
|
||||
{
|
||||
std::cout << name;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "'{" << flag << ',' << name << "}'";
|
||||
}
|
||||
if ( theDelimiter == '=' && a->isValueRequired() )
|
||||
std::cout << "=-";
|
||||
quoteSpecialChars(desc);
|
||||
std::cout << '[' << desc << ']';
|
||||
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
if ( arg.at(arg.length()-1) == ']' )
|
||||
arg.erase(arg.length()-1);
|
||||
if ( arg.at(arg.length()-1) == ']' )
|
||||
{
|
||||
arg.erase(arg.length()-1);
|
||||
}
|
||||
if ( arg.at(0) == '<' )
|
||||
{
|
||||
arg.erase(arg.length()-1);
|
||||
arg.erase(0, 1);
|
||||
}
|
||||
size_t p = arg.find('|');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
do
|
||||
{
|
||||
arg.replace(p, 1, 1, ' ');
|
||||
}
|
||||
while ( (p = arg.find_first_of('|', p)) != std::string::npos );
|
||||
quoteSpecialChars(arg);
|
||||
std::cout << ": :(" << arg << ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << ':' << arg;
|
||||
std::map<std::string, std::string>::iterator compArg = common.find(arg);
|
||||
if ( compArg != common.end() )
|
||||
{
|
||||
std::cout << ':' << compArg->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << '\'';
|
||||
std::string flag = a->flagStartChar() + a->getFlag();
|
||||
std::string name = a->nameStartString() + a->getName();
|
||||
std::string desc = a->getDescription();
|
||||
// remove full stop and capitalisation from description as
|
||||
// this is the convention for zsh function
|
||||
if (!desc.compare(0, 12, "(required) "))
|
||||
{
|
||||
desc.erase(0, 12);
|
||||
}
|
||||
if (!desc.compare(0, 15, "(OR required) "))
|
||||
{
|
||||
desc.erase(0, 15);
|
||||
}
|
||||
size_t len = desc.length();
|
||||
if (len && desc.at(--len) == '.')
|
||||
{
|
||||
desc.erase(len);
|
||||
}
|
||||
if (len)
|
||||
{
|
||||
desc.replace(0, 1, 1, tolower(desc.at(0)));
|
||||
}
|
||||
std::cout << " \\" << std::endl << " '" << mutex;
|
||||
if ( a->getFlag().empty() )
|
||||
{
|
||||
std::cout << name;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "'{" << flag << ',' << name << "}'";
|
||||
}
|
||||
if ( theDelimiter == '=' && a->isValueRequired() )
|
||||
std::cout << "=-";
|
||||
quoteSpecialChars(desc);
|
||||
std::cout << '[' << desc << ']';
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
arg.erase(0, arg.find_last_of(theDelimiter) + 1);
|
||||
if ( arg.at(arg.length()-1) == ']' )
|
||||
arg.erase(arg.length()-1);
|
||||
if ( arg.at(arg.length()-1) == ']' )
|
||||
{
|
||||
arg.erase(arg.length()-1);
|
||||
}
|
||||
if ( arg.at(0) == '<' )
|
||||
{
|
||||
arg.erase(arg.length()-1);
|
||||
arg.erase(0, 1);
|
||||
}
|
||||
size_t p = arg.find('|');
|
||||
if ( p != std::string::npos )
|
||||
{
|
||||
do
|
||||
{
|
||||
arg.replace(p, 1, 1, ' ');
|
||||
}
|
||||
while ( (p = arg.find_first_of('|', p)) != std::string::npos );
|
||||
quoteSpecialChars(arg);
|
||||
std::cout << ": :(" << arg << ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << ':' << arg;
|
||||
std::map<std::string, std::string>::iterator compArg = common.find(arg);
|
||||
if ( compArg != common.end() )
|
||||
{
|
||||
std::cout << ':' << compArg->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << '\'';
|
||||
}
|
||||
|
||||
inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Arg* a)
|
||||
{
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
|
||||
if (a->getName() == "help" || a->getName() == "version")
|
||||
{
|
||||
return "(-)";
|
||||
}
|
||||
|
||||
std::ostringstream list;
|
||||
if ( a->acceptsMultipleValues() )
|
||||
{
|
||||
list << '*';
|
||||
}
|
||||
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end();
|
||||
it++)
|
||||
if ( a == (*it) )
|
||||
{
|
||||
list << '(';
|
||||
for ( ArgVectorIterator iu = xorList[i].begin();
|
||||
iu != xorList[i].end();
|
||||
iu++ )
|
||||
{
|
||||
bool notCur = (*iu) != a;
|
||||
bool hasFlag = !(*iu)->getFlag().empty();
|
||||
if ( iu != xorList[i].begin() && (notCur || hasFlag) )
|
||||
list << ' ';
|
||||
if (hasFlag)
|
||||
list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' ';
|
||||
if ( notCur || hasFlag )
|
||||
list << (*iu)->nameStartString() << (*iu)->getName();
|
||||
}
|
||||
list << ')';
|
||||
return list.str();
|
||||
}
|
||||
}
|
||||
|
||||
// wasn't found in xor list
|
||||
if (!a->getFlag().empty()) {
|
||||
list << "(" << a->flagStartChar() << a->getFlag() << ' ' <<
|
||||
a->nameStartString() << a->getName() << ')';
|
||||
}
|
||||
|
||||
return list.str();
|
||||
XorHandler xorHandler = _cmd.getXorHandler();
|
||||
std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
|
||||
if (a->getName() == "help" || a->getName() == "version")
|
||||
{
|
||||
return "(-)";
|
||||
}
|
||||
std::ostringstream list;
|
||||
if ( a->acceptsMultipleValues() )
|
||||
{
|
||||
list << '*';
|
||||
}
|
||||
for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ )
|
||||
{
|
||||
for ( ArgVectorIterator it = xorList[i].begin();
|
||||
it != xorList[i].end();
|
||||
it++)
|
||||
if ( a == (*it) )
|
||||
{
|
||||
list << '(';
|
||||
for ( ArgVectorIterator iu = xorList[i].begin();
|
||||
iu != xorList[i].end();
|
||||
iu++ )
|
||||
{
|
||||
bool notCur = (*iu) != a;
|
||||
bool hasFlag = !(*iu)->getFlag().empty();
|
||||
if ( iu != xorList[i].begin() && (notCur || hasFlag) )
|
||||
list << ' ';
|
||||
if (hasFlag)
|
||||
list << (*iu)->flagStartChar() << (*iu)->getFlag() << ' ';
|
||||
if ( notCur || hasFlag )
|
||||
list << (*iu)->nameStartString() << (*iu)->getName();
|
||||
}
|
||||
list << ')';
|
||||
return list.str();
|
||||
}
|
||||
}
|
||||
// wasn't found in xor list
|
||||
if (!a->getFlag().empty())
|
||||
{
|
||||
list << "(" << a->flagStartChar() << a->getFlag() << ' ' <<
|
||||
a->nameStartString() << a->getName() << ')';
|
||||
}
|
||||
return list.str();
|
||||
}
|
||||
|
||||
} //namespace TCLAP
|
||||
|
Reference in New Issue
Block a user