mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 23:06:56 +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(); }
|
||||
class TRexpp
|
||||
{
|
||||
public:
|
||||
TRexpp()
|
||||
{
|
||||
_exp = (TRex *)0;
|
||||
}
|
||||
~TRexpp()
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
// compiles a regular expression
|
||||
void Compile(const TRexChar *pattern) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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; }
|
||||
int GetSubExpCount()
|
||||
{
|
||||
return _exp?trex_getsubexpcount(_exp):0;
|
||||
}
|
||||
private:
|
||||
void CleanUp()
|
||||
{
|
||||
if(_exp) trex_free(_exp);
|
||||
_exp = (TRex *)0;
|
||||
}
|
||||
TRex *_exp;
|
||||
};
|
||||
#endif //_TREXPP_H_
|
||||
|
@@ -24,8 +24,7 @@
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* cJSON Types: */
|
||||
@@ -40,7 +39,8 @@ extern "C"
|
||||
#define cJSON_IsReference 256
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON {
|
||||
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. */
|
||||
|
||||
@@ -53,7 +53,8 @@ typedef struct cJSON {
|
||||
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 {
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
void *(*malloc_fn)(size_t sz);
|
||||
void (*free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -99,14 +99,16 @@ typedef unsigned char Boolean; /* 0 or 1 */
|
||||
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
|
||||
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
|
||||
|
||||
typedef enum {
|
||||
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 {
|
||||
typedef enum
|
||||
{
|
||||
strictConversion = 0,
|
||||
lenientConversion
|
||||
} ConversionFlags;
|
||||
|
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
|
||||
|
@@ -126,7 +126,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* initialise dir */
|
||||
dir->_files = NULL;
|
||||
#ifdef _MSC_VER
|
||||
@@ -135,7 +134,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
||||
dir->_d = NULL;
|
||||
#endif
|
||||
tinydir_close(dir);
|
||||
|
||||
strcpy(dir->path, path);
|
||||
#ifdef _MSC_VER
|
||||
strcat(dir->path, "\\*");
|
||||
@@ -150,7 +148,6 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
||||
errno = ENOENT;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* read first file */
|
||||
dir->has_next = 1;
|
||||
#ifndef _MSC_VER
|
||||
@@ -160,9 +157,7 @@ int tinydir_open(tinydir_dir *dir, const char *path)
|
||||
dir->has_next = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
bail:
|
||||
tinydir_close(dir);
|
||||
return -1;
|
||||
@@ -175,7 +170,6 @@ int tinydir_open_sorted(tinydir_dir *dir, const char *path)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
dir->n_files = 0;
|
||||
while (dir->has_next)
|
||||
{
|
||||
@@ -187,23 +181,18 @@ int tinydir_open_sorted(tinydir_dir *dir, const char *path)
|
||||
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;
|
||||
@@ -216,7 +205,6 @@ void tinydir_close(tinydir_dir *dir)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(dir->path, 0, sizeof(dir->path));
|
||||
dir->has_next = 0;
|
||||
dir->n_files = -1;
|
||||
@@ -254,7 +242,6 @@ int tinydir_next(tinydir_dir *dir)
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
if (FindNextFile(dir->_h, &dir->_f) == 0)
|
||||
#else
|
||||
@@ -273,7 +260,6 @@ int tinydir_next(tinydir_dir *dir)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -319,7 +305,6 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(file->path, dir->path);
|
||||
strcat(file->path, "/");
|
||||
strcpy(file->name,
|
||||
@@ -360,7 +345,6 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
|
||||
#else
|
||||
S_ISREG(file->_s.st_mode);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -377,9 +361,7 @@ int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, int i)
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(file, &dir->_files[i], sizeof(tinydir_file));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -397,14 +379,12 @@ int tinydir_open_subdir_n(tinydir_dir *dir, int i)
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(path, dir->_files[i].path);
|
||||
tinydir_close(dir);
|
||||
if (tinydir_open_sorted(dir, path) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -219,7 +219,8 @@ extern "C" {
|
||||
|
||||
|
||||
/* Wide-character version */
|
||||
struct _wdirent {
|
||||
struct _wdirent
|
||||
{
|
||||
long d_ino; /* Always zero */
|
||||
unsigned short d_reclen; /* Structure size */
|
||||
size_t d_namlen; /* Length of name without \0 */
|
||||
@@ -228,7 +229,8 @@ struct _wdirent {
|
||||
};
|
||||
typedef struct _wdirent _wdirent;
|
||||
|
||||
struct _WDIR {
|
||||
struct _WDIR
|
||||
{
|
||||
struct _wdirent ent; /* Current directory entry */
|
||||
WIN32_FIND_DATAW data; /* Private file data */
|
||||
int cached; /* True if data is valid */
|
||||
@@ -253,7 +255,8 @@ static void _wrewinddir (_WDIR* dirp);
|
||||
|
||||
|
||||
/* Multi-byte character versions */
|
||||
struct dirent {
|
||||
struct dirent
|
||||
{
|
||||
long d_ino; /* Always zero */
|
||||
unsigned short d_reclen; /* Structure size */
|
||||
size_t d_namlen; /* Length of name without \0 */
|
||||
@@ -262,7 +265,8 @@ struct dirent {
|
||||
};
|
||||
typedef struct dirent dirent;
|
||||
|
||||
struct DIR {
|
||||
struct DIR
|
||||
{
|
||||
struct dirent ent;
|
||||
struct _WDIR *wdirp;
|
||||
};
|
||||
@@ -305,50 +309,49 @@ _wopendir(
|
||||
{
|
||||
_WDIR *dirp = NULL;
|
||||
int error;
|
||||
|
||||
/* Must have directory name */
|
||||
if (dirname == NULL || dirname[0] == '\0') {
|
||||
if (dirname == NULL || dirname[0] == '\0')
|
||||
{
|
||||
dirent_set_errno (ENOENT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate new _WDIR structure */
|
||||
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
|
||||
if (dirp != NULL) {
|
||||
if (dirp != NULL)
|
||||
{
|
||||
DWORD n;
|
||||
|
||||
/* Reset _WDIR structure */
|
||||
dirp->handle = INVALID_HANDLE_VALUE;
|
||||
dirp->patt = NULL;
|
||||
dirp->cached = 0;
|
||||
|
||||
/* Compute the length of full path plus zero terminator */
|
||||
n = GetFullPathNameW (dirname, 0, NULL, NULL);
|
||||
|
||||
/* Allocate room for absolute directory name and search pattern */
|
||||
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
|
||||
if (dirp->patt) {
|
||||
|
||||
if (dirp->patt)
|
||||
{
|
||||
/*
|
||||
* Convert relative directory name to an absolute one. This
|
||||
* allows rewinddir() to function correctly even when current
|
||||
* working directory is changed between opendir() and rewinddir().
|
||||
*/
|
||||
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
|
||||
if (n > 0) {
|
||||
if (n > 0)
|
||||
{
|
||||
wchar_t *p;
|
||||
|
||||
/* Append search pattern \* to the directory name */
|
||||
p = dirp->patt + n;
|
||||
if (dirp->patt < p) {
|
||||
switch (p[-1]) {
|
||||
if (dirp->patt < p)
|
||||
{
|
||||
switch (p[-1])
|
||||
{
|
||||
case '\\':
|
||||
case '/':
|
||||
case ':':
|
||||
/* Directory ends in path separator, e.g. c:\temp\ */
|
||||
/*NOP*/;
|
||||
/*NOP*/
|
||||
;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Directory name doesn't end in path separator */
|
||||
*p++ = '\\';
|
||||
@@ -356,39 +359,43 @@ _wopendir(
|
||||
}
|
||||
*p++ = '*';
|
||||
*p = '\0';
|
||||
|
||||
/* Open directory stream and retrieve the first entry */
|
||||
if (dirent_first (dirp)) {
|
||||
if (dirent_first (dirp))
|
||||
{
|
||||
/* Directory stream opened successfully */
|
||||
error = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot retrieve first entry */
|
||||
error = 1;
|
||||
dirent_set_errno (ENOENT);
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot retrieve full path name */
|
||||
dirent_set_errno (ENOENT);
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot allocate memory for search pattern */
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot allocate _WDIR structure */
|
||||
error = 1;
|
||||
}
|
||||
|
||||
/* Clean up in case of error */
|
||||
if (error && dirp) {
|
||||
if (error && dirp)
|
||||
{
|
||||
_wclosedir (dirp);
|
||||
dirp = NULL;
|
||||
}
|
||||
|
||||
return dirp;
|
||||
}
|
||||
|
||||
@@ -407,47 +414,48 @@ _wreaddir(
|
||||
|
||||
/* Read next directory entry */
|
||||
datap = dirent_next (dirp);
|
||||
if (datap) {
|
||||
if (datap)
|
||||
{
|
||||
size_t n;
|
||||
DWORD attr;
|
||||
|
||||
/* Pointer to directory entry to return */
|
||||
entp = &dirp->ent;
|
||||
|
||||
/*
|
||||
* Copy file name as wide-character string. If the file name is too
|
||||
* long to fit in to the destination buffer, then truncate file name
|
||||
* to PATH_MAX characters and zero-terminate the buffer.
|
||||
*/
|
||||
n = 0;
|
||||
while (n < PATH_MAX && datap->cFileName[n] != 0) {
|
||||
while (n < PATH_MAX && datap->cFileName[n] != 0)
|
||||
{
|
||||
entp->d_name[n] = datap->cFileName[n];
|
||||
n++;
|
||||
}
|
||||
dirp->ent.d_name[n] = 0;
|
||||
|
||||
/* Length of file name excluding zero terminator */
|
||||
entp->d_namlen = n;
|
||||
|
||||
/* File type */
|
||||
attr = datap->dwFileAttributes;
|
||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
|
||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
|
||||
{
|
||||
entp->d_type = DT_CHR;
|
||||
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
||||
}
|
||||
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||
{
|
||||
entp->d_type = DT_DIR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
entp->d_type = DT_REG;
|
||||
}
|
||||
|
||||
/* Reset dummy fields */
|
||||
entp->d_ino = 0;
|
||||
entp->d_reclen = sizeof (struct _wdirent);
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Last directory entry read */
|
||||
entp = NULL;
|
||||
|
||||
}
|
||||
|
||||
return entp;
|
||||
@@ -463,25 +471,26 @@ _wclosedir(
|
||||
_WDIR *dirp)
|
||||
{
|
||||
int ok;
|
||||
if (dirp) {
|
||||
|
||||
if (dirp)
|
||||
{
|
||||
/* Release search handle */
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose (dirp->handle);
|
||||
dirp->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
/* Release search pattern */
|
||||
if (dirp->patt) {
|
||||
if (dirp->patt)
|
||||
{
|
||||
free (dirp->patt);
|
||||
dirp->patt = NULL;
|
||||
}
|
||||
|
||||
/* Release directory structure */
|
||||
free (dirp);
|
||||
ok = /*success*/0;
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Invalid directory stream */
|
||||
dirent_set_errno (EBADF);
|
||||
ok = /*failure*/-1;
|
||||
@@ -497,12 +506,13 @@ static void
|
||||
_wrewinddir(
|
||||
_WDIR* dirp)
|
||||
{
|
||||
if (dirp) {
|
||||
if (dirp)
|
||||
{
|
||||
/* Release existing search handle */
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose (dirp->handle);
|
||||
}
|
||||
|
||||
/* Open new search handle */
|
||||
dirent_first (dirp);
|
||||
}
|
||||
@@ -514,21 +524,19 @@ dirent_first(
|
||||
_WDIR *dirp)
|
||||
{
|
||||
WIN32_FIND_DATAW *datap;
|
||||
|
||||
/* Open directory and retrieve the first entry */
|
||||
dirp->handle = FindFirstFileW (dirp->patt, &dirp->data);
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
||||
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* a directory entry is now waiting in memory */
|
||||
datap = &dirp->data;
|
||||
dirp->cached = 1;
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to re-open directory: no directory entry in memory */
|
||||
dirp->cached = 0;
|
||||
datap = NULL;
|
||||
|
||||
}
|
||||
return datap;
|
||||
}
|
||||
@@ -539,34 +547,34 @@ dirent_next(
|
||||
_WDIR *dirp)
|
||||
{
|
||||
WIN32_FIND_DATAW *p;
|
||||
|
||||
/* Get next directory entry */
|
||||
if (dirp->cached != 0) {
|
||||
|
||||
if (dirp->cached != 0)
|
||||
{
|
||||
/* A valid directory entry already in memory */
|
||||
p = &dirp->data;
|
||||
dirp->cached = 0;
|
||||
|
||||
} else if (dirp->handle != INVALID_HANDLE_VALUE) {
|
||||
|
||||
}
|
||||
else if (dirp->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* Get the next directory entry from stream */
|
||||
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
|
||||
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE)
|
||||
{
|
||||
/* Got a file */
|
||||
p = &dirp->data;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The very last entry has been processed or an error occured */
|
||||
FindClose (dirp->handle);
|
||||
dirp->handle = INVALID_HANDLE_VALUE;
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* End of directory stream reached */
|
||||
p = NULL;
|
||||
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -579,35 +587,38 @@ opendir(
|
||||
{
|
||||
struct DIR *dirp;
|
||||
int error;
|
||||
|
||||
/* Must have directory name */
|
||||
if (dirname == NULL || dirname[0] == '\0') {
|
||||
if (dirname == NULL || dirname[0] == '\0')
|
||||
{
|
||||
dirent_set_errno (ENOENT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate memory for DIR structure */
|
||||
dirp = (DIR*) malloc (sizeof (struct DIR));
|
||||
if (dirp) {
|
||||
if (dirp)
|
||||
{
|
||||
wchar_t wname[PATH_MAX + 1];
|
||||
size_t n;
|
||||
|
||||
/* Convert directory name to wide-character string */
|
||||
error = dirent_mbstowcs_s(
|
||||
&n, wname, PATH_MAX + 1, dirname, PATH_MAX);
|
||||
if (!error) {
|
||||
|
||||
if (!error)
|
||||
{
|
||||
/* Open directory stream using wide-character name */
|
||||
dirp->wdirp = _wopendir (wname);
|
||||
if (dirp->wdirp) {
|
||||
if (dirp->wdirp)
|
||||
{
|
||||
/* Directory stream opened */
|
||||
error = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to open directory stream */
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Cannot convert file name to wide-character string. This
|
||||
* occurs if the string contains invalid multi-byte sequences or
|
||||
@@ -616,18 +627,18 @@ opendir(
|
||||
*/
|
||||
error = 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot allocate DIR structure */
|
||||
error = 1;
|
||||
}
|
||||
|
||||
/* Clean up in case of error */
|
||||
if (error && dirp) {
|
||||
if (error && dirp)
|
||||
{
|
||||
free (dirp);
|
||||
dirp = NULL;
|
||||
}
|
||||
|
||||
return dirp;
|
||||
}
|
||||
|
||||
@@ -653,14 +664,13 @@ readdir(
|
||||
|
||||
/* Read next directory entry */
|
||||
datap = dirent_next (dirp->wdirp);
|
||||
if (datap) {
|
||||
if (datap)
|
||||
{
|
||||
size_t n;
|
||||
int error;
|
||||
|
||||
/* Attempt to convert file name to multi-byte string */
|
||||
error = dirent_wcstombs_s(
|
||||
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cFileName, MAX_PATH);
|
||||
|
||||
/*
|
||||
* If the file name cannot be represented by a multi-byte string,
|
||||
* then attempt to use old 8+3 file name. This allows traditional
|
||||
@@ -671,37 +681,40 @@ readdir(
|
||||
* name unless the file system provides one. At least
|
||||
* VirtualBox shared folders fail to do this.
|
||||
*/
|
||||
if (error && datap->cAlternateFileName[0] != '\0') {
|
||||
if (error && datap->cAlternateFileName[0] != '\0')
|
||||
{
|
||||
error = dirent_wcstombs_s(
|
||||
&n, dirp->ent.d_name, MAX_PATH + 1, datap->cAlternateFileName,
|
||||
sizeof (datap->cAlternateFileName) /
|
||||
sizeof (datap->cAlternateFileName[0]));
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
if (!error)
|
||||
{
|
||||
DWORD attr;
|
||||
|
||||
/* Initialize directory entry for return */
|
||||
entp = &dirp->ent;
|
||||
|
||||
/* Length of file name excluding zero terminator */
|
||||
entp->d_namlen = n - 1;
|
||||
|
||||
/* File attributes */
|
||||
attr = datap->dwFileAttributes;
|
||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
|
||||
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0)
|
||||
{
|
||||
entp->d_type = DT_CHR;
|
||||
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
||||
}
|
||||
else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||
{
|
||||
entp->d_type = DT_DIR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
entp->d_type = DT_REG;
|
||||
}
|
||||
|
||||
/* Reset dummy fields */
|
||||
entp->d_ino = 0;
|
||||
entp->d_reclen = sizeof (struct dirent);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Cannot convert file name to multi-byte string so construct
|
||||
* an errornous directory entry and return that. Note that
|
||||
@@ -716,8 +729,9 @@ readdir(
|
||||
entp->d_ino = 0;
|
||||
entp->d_reclen = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No more directory entries */
|
||||
entp = NULL;
|
||||
}
|
||||
@@ -733,21 +747,19 @@ closedir(
|
||||
DIR *dirp)
|
||||
{
|
||||
int ok;
|
||||
if (dirp) {
|
||||
|
||||
if (dirp)
|
||||
{
|
||||
/* Close wide-character directory stream */
|
||||
ok = _wclosedir (dirp->wdirp);
|
||||
dirp->wdirp = NULL;
|
||||
|
||||
/* Release multi-byte character version */
|
||||
free (dirp);
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Invalid directory stream */
|
||||
dirent_set_errno (EBADF);
|
||||
ok = /*failure*/-1;
|
||||
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -773,43 +785,35 @@ dirent_mbstowcs_s(
|
||||
size_t count)
|
||||
{
|
||||
int error;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
|
||||
/* Microsoft Visual Studio 2005 or later */
|
||||
error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
|
||||
|
||||
#else
|
||||
|
||||
/* Older Visual Studio or non-Microsoft compiler */
|
||||
size_t n;
|
||||
|
||||
/* Convert to wide-character string */
|
||||
n = mbstowcs (wcstr, mbstr, count);
|
||||
if (n < sizeInWords) {
|
||||
|
||||
if (n < sizeInWords)
|
||||
{
|
||||
/* Zero-terminate output buffer */
|
||||
if (wcstr) {
|
||||
if (wcstr)
|
||||
{
|
||||
wcstr[n] = 0;
|
||||
}
|
||||
|
||||
/* Length of resuting multi-byte string WITH zero terminator */
|
||||
if (pReturnValue) {
|
||||
if (pReturnValue)
|
||||
{
|
||||
*pReturnValue = n + 1;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
error = 0;
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Could not convert string */
|
||||
error = 1;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -823,43 +827,35 @@ dirent_wcstombs_s(
|
||||
size_t count)
|
||||
{
|
||||
int error;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
|
||||
/* Microsoft Visual Studio 2005 or later */
|
||||
error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
|
||||
|
||||
#else
|
||||
|
||||
/* Older Visual Studio or non-Microsoft compiler */
|
||||
size_t n;
|
||||
|
||||
/* Convert to multi-byte string */
|
||||
n = wcstombs (mbstr, wcstr, count);
|
||||
if (n < sizeInBytes) {
|
||||
|
||||
if (n < sizeInBytes)
|
||||
{
|
||||
/* Zero-terminate output buffer */
|
||||
if (mbstr) {
|
||||
if (mbstr)
|
||||
{
|
||||
mbstr[n] = '\0';
|
||||
}
|
||||
|
||||
/* Lenght of resulting multi-bytes string WITH zero-terminator */
|
||||
if (pReturnValue) {
|
||||
if (pReturnValue)
|
||||
{
|
||||
*pReturnValue = n + 1;
|
||||
}
|
||||
|
||||
/* Success */
|
||||
error = 0;
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cannot convert string */
|
||||
error = 1;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -869,15 +865,11 @@ dirent_set_errno(
|
||||
int error)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
/* Microsoft Visual Studio */
|
||||
_set_errno (error);
|
||||
|
||||
#else
|
||||
|
||||
/* Non-Microsoft compiler */
|
||||
errno = error;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,8 @@
|
||||
typedef unsigned int TRexBool;
|
||||
typedef struct TRex TRex;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
const TRexChar *begin;
|
||||
int len;
|
||||
} TRexMatch;
|
||||
|
@@ -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,7 +41,7 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
struct LineSegment
|
||||
{
|
||||
float x1;
|
||||
@@ -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
|
||||
|
116
src/tclap/Arg.h
116
src/tclap/Arg.h
@@ -54,7 +54,8 @@ typedef std::istrstream istringstream;
|
||||
#include "ArgTraits.h"
|
||||
#include "StandardTraits.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A virtual base class that defines the essential data for all arguments.
|
||||
@@ -77,13 +78,21 @@ class Arg
|
||||
/**
|
||||
* Indicates whether the rest of the arguments should be ignored.
|
||||
*/
|
||||
static bool& ignoreRestRef() { static bool ign = false; return ign; }
|
||||
static bool& ignoreRestRef()
|
||||
{
|
||||
static bool ign = false;
|
||||
return ign;
|
||||
}
|
||||
|
||||
/**
|
||||
* The delimiter that separates an argument flag/name from the
|
||||
* value.
|
||||
*/
|
||||
static char& delimiterRef() { static char delim = ' '; return delim; }
|
||||
static char& delimiterRef()
|
||||
{
|
||||
static char delim = ' ';
|
||||
return delim;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -197,24 +206,36 @@ class Arg
|
||||
/**
|
||||
* Begin ignoring arguments since the "--" argument was specified.
|
||||
*/
|
||||
static void beginIgnoring() { ignoreRestRef() = true; }
|
||||
static void beginIgnoring()
|
||||
{
|
||||
ignoreRestRef() = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to ignore the rest.
|
||||
*/
|
||||
static bool ignoreRest() { return ignoreRestRef(); }
|
||||
static bool ignoreRest()
|
||||
{
|
||||
return ignoreRestRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* The delimiter that separates an argument flag/name from the
|
||||
* value.
|
||||
*/
|
||||
static char delimiter() { return delimiterRef(); }
|
||||
static char delimiter()
|
||||
{
|
||||
return delimiterRef();
|
||||
}
|
||||
|
||||
/**
|
||||
* The char used as a place holder when SwitchArgs are combined.
|
||||
* Currently set to the bell char (ASCII 7).
|
||||
*/
|
||||
static char blankChar() { return (char)7; }
|
||||
static char blankChar()
|
||||
{
|
||||
return (char)7;
|
||||
}
|
||||
|
||||
/**
|
||||
* The char that indicates the beginning of a flag. Defaults to '-', but
|
||||
@@ -223,7 +244,10 @@ class Arg
|
||||
#ifndef TCLAP_FLAGSTARTCHAR
|
||||
#define TCLAP_FLAGSTARTCHAR '-'
|
||||
#endif
|
||||
static char flagStartChar() { return TCLAP_FLAGSTARTCHAR; }
|
||||
static char flagStartChar()
|
||||
{
|
||||
return TCLAP_FLAGSTARTCHAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sting that indicates the beginning of a flag. Defaults to "-", but
|
||||
@@ -233,7 +257,10 @@ class Arg
|
||||
#ifndef TCLAP_FLAGSTARTSTRING
|
||||
#define TCLAP_FLAGSTARTSTRING "-"
|
||||
#endif
|
||||
static const std::string flagStartString() { return TCLAP_FLAGSTARTSTRING; }
|
||||
static const std::string flagStartString()
|
||||
{
|
||||
return TCLAP_FLAGSTARTSTRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sting that indicates the beginning of a name. Defaults to "--", but
|
||||
@@ -242,18 +269,27 @@ class Arg
|
||||
#ifndef TCLAP_NAMESTARTSTRING
|
||||
#define TCLAP_NAMESTARTSTRING "--"
|
||||
#endif
|
||||
static const std::string nameStartString() { return TCLAP_NAMESTARTSTRING; }
|
||||
static const std::string nameStartString()
|
||||
{
|
||||
return TCLAP_NAMESTARTSTRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name used to identify the ignore rest argument.
|
||||
*/
|
||||
static const std::string ignoreNameString() { return "ignore_rest"; }
|
||||
static const std::string ignoreNameString()
|
||||
{
|
||||
return "ignore_rest";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delimiter for all arguments.
|
||||
* \param c - The character that delimits flags/names from values.
|
||||
*/
|
||||
static void setDelimiter( char c ) { delimiterRef() = c; }
|
||||
static void setDelimiter( char c )
|
||||
{
|
||||
delimiterRef() = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure virtual method meant to handle the parsing and value assignment
|
||||
@@ -416,9 +452,9 @@ ExtractValue(T &destVal, const std::string& strVal, ValueLike vl)
|
||||
{
|
||||
static_cast<void>(vl); // Avoid warning about unused vl
|
||||
std::istringstream is(strVal);
|
||||
|
||||
int valuesRead = 0;
|
||||
while ( is.good() ) {
|
||||
while ( is.good() )
|
||||
{
|
||||
if ( is.peek() != EOF )
|
||||
#ifdef TCLAP_SETBASE_ZERO
|
||||
is >> std::setbase(0) >> destVal;
|
||||
@@ -427,19 +463,14 @@ ExtractValue(T &destVal, const std::string& strVal, ValueLike vl)
|
||||
#endif
|
||||
else
|
||||
break;
|
||||
|
||||
valuesRead++;
|
||||
}
|
||||
|
||||
if ( is.fail() )
|
||||
throw( ArgParseException("Couldn't read argument value "
|
||||
"from string '" + strVal + "'"));
|
||||
|
||||
|
||||
if ( valuesRead > 1 )
|
||||
throw( ArgParseException("More than one valid value parsed from "
|
||||
"string '" + strVal + "'"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -480,7 +511,6 @@ inline Arg::Arg(const std::string& flag,
|
||||
if ( _flag.length() > 1 )
|
||||
throw(SpecificationException(
|
||||
"Argument flag can only be one character long", toString() ) );
|
||||
|
||||
if ( _name != ignoreNameString() &&
|
||||
( _flag == Arg::flagStartString() ||
|
||||
_flag == Arg::nameStartString() ||
|
||||
@@ -489,7 +519,6 @@ inline Arg::Arg(const std::string& flag,
|
||||
Arg::flagStartString() + "' or '" +
|
||||
Arg::nameStartString() + "' or a space.",
|
||||
toString() ) );
|
||||
|
||||
if ( ( _name.substr( 0, Arg::flagStartString().length() ) == Arg::flagStartString() ) ||
|
||||
( _name.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) ||
|
||||
( _name.find( " ", 0 ) != std::string::npos ) )
|
||||
@@ -497,7 +526,6 @@ inline Arg::Arg(const std::string& flag,
|
||||
Arg::flagStartString() + "' or '" +
|
||||
Arg::nameStartString() + "' or space.",
|
||||
toString() ) );
|
||||
|
||||
}
|
||||
|
||||
inline Arg::~Arg() { }
|
||||
@@ -505,42 +533,31 @@ inline Arg::~Arg() { }
|
||||
inline std::string Arg::shortID( const std::string& valueId ) const
|
||||
{
|
||||
std::string id = "";
|
||||
|
||||
if ( _flag != "" )
|
||||
id = Arg::flagStartString() + _flag;
|
||||
else
|
||||
id = Arg::nameStartString() + _name;
|
||||
|
||||
if ( _valueRequired )
|
||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||
|
||||
if ( !_required )
|
||||
id = "[" + id + "]";
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
inline std::string Arg::longID( const std::string& valueId ) const
|
||||
{
|
||||
std::string id = "";
|
||||
|
||||
if ( _flag != "" )
|
||||
{
|
||||
id += Arg::flagStartString() + _flag;
|
||||
|
||||
if ( _valueRequired )
|
||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||
|
||||
id += ", ";
|
||||
}
|
||||
|
||||
id += Arg::nameStartString() + _name;
|
||||
|
||||
if ( _valueRequired )
|
||||
id += std::string( 1, Arg::delimiter() ) + "<" + valueId + ">";
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
inline bool Arg::operator==(const Arg& a) const
|
||||
@@ -556,21 +573,31 @@ inline std::string Arg::getDescription() const
|
||||
std::string desc = "";
|
||||
if ( _required )
|
||||
desc = "(" + _requireLabel + ") ";
|
||||
|
||||
// if ( _valueRequired )
|
||||
// desc += "(value required) ";
|
||||
|
||||
desc += _description;
|
||||
return desc;
|
||||
}
|
||||
|
||||
inline const std::string& Arg::getFlag() const { return _flag; }
|
||||
inline const std::string& Arg::getFlag() const
|
||||
{
|
||||
return _flag;
|
||||
}
|
||||
|
||||
inline const std::string& Arg::getName() const { return _name; }
|
||||
inline const std::string& Arg::getName() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
inline bool Arg::isRequired() const { return _required; }
|
||||
inline bool Arg::isRequired() const
|
||||
{
|
||||
return _required;
|
||||
}
|
||||
|
||||
inline bool Arg::isValueRequired() const { return _valueRequired; }
|
||||
inline bool Arg::isValueRequired() const
|
||||
{
|
||||
return _valueRequired;
|
||||
}
|
||||
|
||||
inline bool Arg::isSet() const
|
||||
{
|
||||
@@ -580,7 +607,10 @@ inline bool Arg::isSet() const
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool Arg::isIgnoreable() const { return _ignoreable; }
|
||||
inline bool Arg::isIgnoreable() const
|
||||
{
|
||||
return _ignoreable;
|
||||
}
|
||||
|
||||
inline void Arg::setRequireLabel( const std::string& s)
|
||||
{
|
||||
@@ -599,12 +629,9 @@ inline bool Arg::argMatches( const std::string& argFlag ) const
|
||||
inline std::string Arg::toString() const
|
||||
{
|
||||
std::string s = "";
|
||||
|
||||
if ( _flag != "" )
|
||||
s += Arg::flagStartString() + _flag + " ";
|
||||
|
||||
s += "(" + Arg::nameStartString() + _name + ")";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -626,13 +653,11 @@ inline void Arg::trimFlag(std::string& flag, std::string& value) const
|
||||
stop = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( stop > 1 )
|
||||
{
|
||||
value = flag.substr(stop+1);
|
||||
flag = flag.substr(0,stop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -643,7 +668,6 @@ inline bool Arg::_hasBlanks( const std::string& s ) const
|
||||
for ( int i = 1; static_cast<unsigned int>(i) < s.length(); i++ )
|
||||
if ( s[i] == Arg::blankChar() )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,8 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A simple class that defines and argument exception. Should be caught
|
||||
@@ -61,7 +62,10 @@ class ArgException : public std::exception
|
||||
/**
|
||||
* Returns the error text.
|
||||
*/
|
||||
std::string error() const { return ( _errorText ); }
|
||||
std::string error() const
|
||||
{
|
||||
return ( _errorText );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument id.
|
||||
@@ -184,13 +188,17 @@ class SpecificationException : public ArgException
|
||||
|
||||
};
|
||||
|
||||
class ExitException {
|
||||
public:
|
||||
class ExitException
|
||||
{
|
||||
public:
|
||||
ExitException(int estat) : _estat(estat) {}
|
||||
|
||||
int getExitStatus() const { return _estat; }
|
||||
int getExitStatus() const
|
||||
{
|
||||
return _estat;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
int _estat;
|
||||
};
|
||||
|
||||
|
@@ -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,7 +36,8 @@ 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 {
|
||||
struct ValueLike
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLike() {}
|
||||
};
|
||||
@@ -45,7 +47,8 @@ struct ValueLike {
|
||||
* operator=(string). Usefull if the value type contains spaces which
|
||||
* will be broken up into individual tokens by operator>>.
|
||||
*/
|
||||
struct StringLike {
|
||||
struct StringLike
|
||||
{
|
||||
virtual ~StringLike() {}
|
||||
};
|
||||
|
||||
@@ -54,7 +57,8 @@ struct StringLike {
|
||||
* traits. This is a compile time thing and does not add any overhead
|
||||
* to the inherenting class.
|
||||
*/
|
||||
struct StringLikeTrait {
|
||||
struct StringLikeTrait
|
||||
{
|
||||
typedef StringLike ValueCategory;
|
||||
virtual ~StringLikeTrait() {}
|
||||
};
|
||||
@@ -64,7 +68,8 @@ struct StringLikeTrait {
|
||||
* traits. This is a compile time thing and does not add any overhead
|
||||
* to the inherenting class.
|
||||
*/
|
||||
struct ValueLikeTrait {
|
||||
struct ValueLikeTrait
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
virtual ~ValueLikeTrait() {}
|
||||
};
|
||||
@@ -76,7 +81,8 @@ struct ValueLikeTrait {
|
||||
* supported types are StringLike and ValueLike.
|
||||
*/
|
||||
template<typename T>
|
||||
struct ArgTraits {
|
||||
struct ArgTraits
|
||||
{
|
||||
typedef typename T::ValueCategory ValueCategory;
|
||||
virtual ~ArgTraits() {}
|
||||
//typedef ValueLike ValueCategory;
|
||||
|
@@ -48,7 +48,8 @@
|
||||
#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)
|
||||
{
|
||||
@@ -157,7 +158,7 @@ class CmdLine : public CmdLineInterface
|
||||
*/
|
||||
void deleteOnExit(Visitor* ptr);
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/**
|
||||
* Prevent accidental copying.
|
||||
@@ -346,8 +347,8 @@ inline CmdLine::~CmdLine()
|
||||
{
|
||||
ClearContainer(_argDeleteOnExitList);
|
||||
ClearContainer(_visitorDeleteOnExitList);
|
||||
|
||||
if ( !_userSetOutput ) {
|
||||
if ( !_userSetOutput )
|
||||
{
|
||||
delete _output;
|
||||
_output = 0;
|
||||
}
|
||||
@@ -356,11 +357,8 @@ inline CmdLine::~CmdLine()
|
||||
inline void CmdLine::_constructor()
|
||||
{
|
||||
_output = new StdOutput;
|
||||
|
||||
Arg::setDelimiter( _delimiter );
|
||||
|
||||
Visitor* v;
|
||||
|
||||
if ( _helpAndVersion )
|
||||
{
|
||||
v = new HelpVisitor( this, &_output );
|
||||
@@ -370,7 +368,6 @@ inline void CmdLine::_constructor()
|
||||
add( help );
|
||||
deleteOnExit(help);
|
||||
deleteOnExit(v);
|
||||
|
||||
v = new VersionVisitor( this, &_output );
|
||||
SwitchArg* vers = new SwitchArg("","version",
|
||||
"Displays version information and exits.",
|
||||
@@ -379,7 +376,6 @@ inline void CmdLine::_constructor()
|
||||
deleteOnExit(vers);
|
||||
deleteOnExit(v);
|
||||
}
|
||||
|
||||
v = new IgnoreRestVisitor();
|
||||
SwitchArg* ignore = new SwitchArg(Arg::flagStartString(),
|
||||
Arg::ignoreNameString(),
|
||||
@@ -393,7 +389,6 @@ inline void CmdLine::_constructor()
|
||||
inline void CmdLine::xorAdd( std::vector<Arg*>& ors )
|
||||
{
|
||||
_xorHandler.add( ors );
|
||||
|
||||
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++)
|
||||
{
|
||||
(*it)->forceRequired();
|
||||
@@ -422,9 +417,7 @@ inline void CmdLine::add( Arg* a )
|
||||
throw( SpecificationException(
|
||||
"Argument with same flag/name already exists!",
|
||||
a->longID() ) );
|
||||
|
||||
a->addToList( _argList );
|
||||
|
||||
if ( a->isRequired() )
|
||||
_numRequired++;
|
||||
}
|
||||
@@ -437,7 +430,6 @@ inline void CmdLine::parse(int argc, const char * const * argv)
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; i++)
|
||||
args.push_back(argv[i]);
|
||||
|
||||
parse(args);
|
||||
}
|
||||
|
||||
@@ -445,18 +437,17 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
||||
{
|
||||
bool shouldExit = false;
|
||||
int estat = 0;
|
||||
|
||||
try {
|
||||
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++) {
|
||||
it != _argList.end(); it++)
|
||||
{
|
||||
if ( (*it)->processArg( &i, args ) )
|
||||
{
|
||||
requiredCount += _xorHandler.check( *it );
|
||||
@@ -464,46 +455,47 @@ inline void CmdLine::parse(std::vector<std::string>& args)
|
||||
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 ) {
|
||||
}
|
||||
catch ( ArgException& e )
|
||||
{
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions) {
|
||||
if ( !_handleExceptions)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
_output->failure(*this,e);
|
||||
} catch ( ExitException &ee ) {
|
||||
}
|
||||
catch ( ExitException &ee )
|
||||
{
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
} catch (ExitException &ee) {
|
||||
}
|
||||
catch (ExitException &ee)
|
||||
{
|
||||
// If we're not handling the exceptions, rethrow.
|
||||
if ( !_handleExceptions) {
|
||||
if ( !_handleExceptions)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
estat = ee.getExitStatus();
|
||||
shouldExit = true;
|
||||
}
|
||||
|
||||
if (shouldExit)
|
||||
exit(estat);
|
||||
}
|
||||
@@ -512,18 +504,15 @@ 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;
|
||||
}
|
||||
|
||||
inline void CmdLine::missingArgsException()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
std::string missingArgList;
|
||||
for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++)
|
||||
{
|
||||
@@ -535,15 +524,12 @@ inline void CmdLine::missingArgsException()
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -619,7 +605,6 @@ inline void CmdLine::reset()
|
||||
{
|
||||
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;
|
||||
|
@@ -30,7 +30,8 @@
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
class CmdLineInterface;
|
||||
class ArgException;
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The interface that defines the interaction between the Arg and Constraint.
|
||||
@@ -61,7 +62,10 @@ class Constraint
|
||||
* Silences warnings about Constraint being a base class with virtual
|
||||
* functions but without a virtual destructor.
|
||||
*/
|
||||
virtual ~Constraint() { ; }
|
||||
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
|
||||
@@ -101,28 +102,21 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd )
|
||||
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++ )
|
||||
{
|
||||
@@ -130,45 +124,34 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd )
|
||||
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,
|
||||
@@ -213,22 +196,17 @@ 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();
|
||||
@@ -246,20 +224,16 @@ inline void DocBookOutput::printShortArg(Arg* a)
|
||||
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;
|
||||
@@ -268,7 +242,6 @@ inline void DocBookOutput::printLongArg(Arg* a)
|
||||
std::cout << "</option>" << std::endl;
|
||||
std::cout << "</term>" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "<term>" << std::endl;
|
||||
std::cout << "<option>";
|
||||
std::cout << a->nameStartString() << a->getName();
|
||||
@@ -285,13 +258,11 @@ inline void DocBookOutput::printLongArg(Arg* a)
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
@@ -67,7 +68,11 @@ class HelpVisitor: public Visitor
|
||||
* Calls the usage method of the CmdLineOutput for the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit() { (*_out)->usage(*_cmd); throw ExitException(0); }
|
||||
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
|
||||
@@ -44,7 +45,10 @@ class IgnoreRestVisitor: public Visitor
|
||||
/**
|
||||
* Sets Arg::_ignoreRest.
|
||||
*/
|
||||
void visit() { Arg::beginIgnoring(); }
|
||||
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,12 +39,12 @@ namespace TCLAP {
|
||||
template<class T>
|
||||
class MultiArg : public Arg
|
||||
{
|
||||
public:
|
||||
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.
|
||||
@@ -73,7 +74,7 @@ protected:
|
||||
*/
|
||||
bool _allowMore;
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -191,13 +192,19 @@ public:
|
||||
* Returns an iterator over the values parsed from the command
|
||||
* line.
|
||||
*/
|
||||
const_iterator begin() const { return _values.begin(); }
|
||||
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(); }
|
||||
const_iterator end() const
|
||||
{
|
||||
return _values.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the a short id string. Used in the usage.
|
||||
@@ -221,7 +228,7 @@ public:
|
||||
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
@@ -254,7 +261,7 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL ),
|
||||
@@ -274,7 +281,7 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
bool req,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
@@ -291,7 +298,7 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_values(std::vector<T>()),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint ),
|
||||
@@ -302,29 +309,27 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
}
|
||||
|
||||
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 == "" )
|
||||
{
|
||||
@@ -337,7 +342,6 @@ bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
/*
|
||||
// continuing taking the args until we hit one with a start string
|
||||
while ( (unsigned int)(*i)+1 < args.size() &&
|
||||
@@ -345,10 +349,8 @@ bool MultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -391,20 +393,21 @@ bool MultiArg<T>::isRequired() const
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void MultiArg<T>::_extractValue( const std::string& val )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
T tmp;
|
||||
ExtractValue(tmp, val, typename ArgTraits<T>::ValueCategory());
|
||||
_values.push_back(tmp);
|
||||
} catch( ArgParseException &e) {
|
||||
}
|
||||
catch( ArgParseException &e)
|
||||
{
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _values.back() ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
|
@@ -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
|
||||
@@ -132,9 +133,9 @@ inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
|
||||
const std::string& desc,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
{ }
|
||||
|
||||
inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
|
||||
@@ -143,46 +144,41 @@ inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
|
||||
CmdLineInterface& parser,
|
||||
int init,
|
||||
Visitor* v )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
: SwitchArg(flag, name, desc, false, v),
|
||||
_value( init ),
|
||||
_default( init )
|
||||
{
|
||||
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
|
||||
|
@@ -26,7 +26,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
class OptionalUnlabeledTracker
|
||||
{
|
||||
@@ -35,13 +36,23 @@ class OptionalUnlabeledTracker
|
||||
|
||||
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:
|
||||
|
||||
static bool& alreadyOptionalRef() { static bool ct = false; return ct; }
|
||||
static bool& alreadyOptionalRef()
|
||||
{
|
||||
static bool ct = false;
|
||||
return ct;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -51,7 +62,6 @@ inline void OptionalUnlabeledTracker::check( bool req, const std::string& argNam
|
||||
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,7 +50,8 @@ namespace TCLAP {
|
||||
* longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<long> {
|
||||
struct ArgTraits<long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -57,7 +59,8 @@ struct ArgTraits<long> {
|
||||
* ints have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<int> {
|
||||
struct ArgTraits<int>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -65,7 +68,8 @@ struct ArgTraits<int> {
|
||||
* shorts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<short> {
|
||||
struct ArgTraits<short>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -73,7 +77,8 @@ struct ArgTraits<short> {
|
||||
* chars have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<char> {
|
||||
struct ArgTraits<char>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -82,7 +87,8 @@ struct ArgTraits<char> {
|
||||
* long longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<long long> {
|
||||
struct ArgTraits<long long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
@@ -95,7 +101,8 @@ struct ArgTraits<long long> {
|
||||
* unsigned longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned long> {
|
||||
struct ArgTraits<unsigned long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -103,7 +110,8 @@ struct ArgTraits<unsigned long> {
|
||||
* unsigned ints have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned int> {
|
||||
struct ArgTraits<unsigned int>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -111,7 +119,8 @@ struct ArgTraits<unsigned int> {
|
||||
* unsigned shorts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned short> {
|
||||
struct ArgTraits<unsigned short>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -119,7 +128,8 @@ struct ArgTraits<unsigned short> {
|
||||
* unsigned chars have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned char> {
|
||||
struct ArgTraits<unsigned char>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -129,7 +139,8 @@ struct ArgTraits<unsigned char> {
|
||||
* size_ts have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<size_t> {
|
||||
struct ArgTraits<size_t>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
@@ -140,7 +151,8 @@ struct ArgTraits<size_t> {
|
||||
* unsigned long longs have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<unsigned long long> {
|
||||
struct ArgTraits<unsigned long long>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
@@ -153,7 +165,8 @@ struct ArgTraits<unsigned long long> {
|
||||
* floats have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<float> {
|
||||
struct ArgTraits<float>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -161,7 +174,8 @@ struct ArgTraits<float> {
|
||||
* doubles have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<double> {
|
||||
struct ArgTraits<double>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -173,7 +187,8 @@ struct ArgTraits<double> {
|
||||
* bools have value-like semantics.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<bool> {
|
||||
struct ArgTraits<bool>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
|
||||
@@ -183,7 +198,8 @@ struct ArgTraits<bool> {
|
||||
*/
|
||||
#ifndef TCLAP_DONT_DECLARE_WCHAR_T_ARGTRAITS
|
||||
template<>
|
||||
struct ArgTraits<wchar_t> {
|
||||
struct ArgTraits<wchar_t>
|
||||
{
|
||||
typedef ValueLike ValueCategory;
|
||||
};
|
||||
#endif
|
||||
@@ -192,7 +208,8 @@ struct ArgTraits<wchar_t> {
|
||||
* Strings have string like argument traits.
|
||||
*/
|
||||
template<>
|
||||
struct ArgTraits<std::string> {
|
||||
struct ArgTraits<std::string>
|
||||
{
|
||||
typedef StringLike ValueCategory;
|
||||
};
|
||||
|
||||
|
@@ -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
|
||||
@@ -109,7 +110,6 @@ 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;
|
||||
}
|
||||
@@ -117,38 +117,28 @@ inline void StdOutput::version(CmdLineInterface& _cmd)
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
inline void StdOutput::failure( CmdLineInterface& _cmd,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -160,9 +150,7 @@ StdOutput::_shortUsage( CmdLineInterface& _cmd,
|
||||
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++ )
|
||||
{
|
||||
@@ -170,20 +158,16 @@ StdOutput::_shortUsage( CmdLineInterface& _cmd,
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -195,7 +179,6 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
||||
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++ )
|
||||
{
|
||||
@@ -205,13 +188,11 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
||||
{
|
||||
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) ) )
|
||||
@@ -220,9 +201,7 @@ StdOutput::_longUsage( CmdLineInterface& _cmd,
|
||||
spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
os << std::endl;
|
||||
|
||||
spacePrint( os, message, 75, 3, 0 );
|
||||
}
|
||||
|
||||
@@ -233,7 +212,6 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
||||
int secondLineOffset ) const
|
||||
{
|
||||
int len = static_cast<int>(s.length());
|
||||
|
||||
if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
|
||||
{
|
||||
int allowedLen = maxWidth - indentSpaces;
|
||||
@@ -245,7 +223,6 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
||||
// 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 &&
|
||||
@@ -253,36 +230,28 @@ inline void StdOutput::spacePrint( std::ostream& os,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -137,7 +138,7 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
||||
const std::string& desc,
|
||||
bool default_val,
|
||||
Visitor* v )
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default( default_val )
|
||||
{ }
|
||||
@@ -148,21 +149,23 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
||||
CmdLineInterface& parser,
|
||||
bool default_val,
|
||||
Visitor* v )
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
: Arg(flag, name, desc, false, false, v),
|
||||
_value( default_val ),
|
||||
_default(default_val)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -172,16 +175,13 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
||||
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++ )
|
||||
@@ -196,7 +196,6 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
||||
combinedSwitches[i] = Arg::blankChar();
|
||||
return true;
|
||||
}
|
||||
|
||||
// none of the switches passed in the list match.
|
||||
return false;
|
||||
}
|
||||
@@ -206,17 +205,13 @@ 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();
|
||||
}
|
||||
|
||||
@@ -224,12 +219,10 @@ 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
|
||||
@@ -240,9 +233,7 @@ inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||
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.
|
||||
|
@@ -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,
|
||||
@@ -190,7 +191,7 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
@@ -204,7 +205,7 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
: MultiArg<T>("", name, desc, req, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
@@ -219,7 +220,7 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
Constraint<T>* constraint,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
@@ -233,7 +234,7 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
: MultiArg<T>("", name, desc, req, constraint, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(true, toString());
|
||||
@@ -244,16 +245,11 @@ UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
|
||||
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() &&
|
||||
@@ -261,9 +257,7 @@ bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
|
||||
_extractValue( args[++(*i)] );
|
||||
*/
|
||||
|
||||
_alreadySet = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -31,7 +31,8 @@
|
||||
#include "OptionalUnlabeledTracker.h"
|
||||
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The basic unlabeled argument that parses a value.
|
||||
@@ -217,12 +218,10 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
const std::string& typeDesc,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -234,7 +233,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
CmdLineInterface& parser,
|
||||
bool ignoreable,
|
||||
Visitor* v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
: ValueArg<T>("", name, desc, req, val, typeDesc, v)
|
||||
{
|
||||
_ignoreable = ignoreable;
|
||||
OptionalUnlabeledTracker::check(req, toString());
|
||||
@@ -252,7 +251,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
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());
|
||||
@@ -267,7 +266,7 @@ UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
|
||||
CmdLineInterface& parser,
|
||||
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());
|
||||
@@ -280,15 +279,11 @@ 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;
|
||||
@@ -311,7 +306,6 @@ 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.
|
||||
|
@@ -29,7 +29,8 @@
|
||||
#include "Arg.h"
|
||||
#include "Constraint.h"
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* The basic labeled argument that parses a value.
|
||||
@@ -236,7 +237,7 @@ class ValueArg : public Arg
|
||||
|
||||
virtual void reset() ;
|
||||
|
||||
private:
|
||||
private:
|
||||
/**
|
||||
* Prevent accidental copying
|
||||
*/
|
||||
@@ -256,7 +257,7 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
T val,
|
||||
const std::string& typeDesc,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
@@ -272,7 +273,7 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
const std::string& typeDesc,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( typeDesc ),
|
||||
@@ -289,7 +290,7 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
T val,
|
||||
Constraint<T>* constraint,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
@@ -305,7 +306,7 @@ ValueArg<T>::ValueArg(const std::string& flag,
|
||||
Constraint<T>* constraint,
|
||||
CmdLineInterface& parser,
|
||||
Visitor* v)
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
: Arg(flag, name, desc, req, true, v),
|
||||
_value( val ),
|
||||
_default( val ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
@@ -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().
|
||||
@@ -329,15 +333,11 @@ 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 ( _alreadySet )
|
||||
@@ -350,12 +350,10 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
throw( CmdLineParseException("Argument already set!",
|
||||
toString()) );
|
||||
}
|
||||
|
||||
if ( Arg::delimiter() != ' ' && value == "" )
|
||||
throw( ArgParseException(
|
||||
"Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
@@ -367,7 +365,6 @@ bool ValueArg<T>::processArg(int *i, std::vector<std::string>& args)
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
@@ -399,12 +396,14 @@ std::string ValueArg<T>::longID(const std::string& val) const
|
||||
template<class T>
|
||||
void ValueArg<T>::_extractValue( const std::string& val )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
ExtractValue(_value, val, typename ArgTraits<T>::ValueCategory());
|
||||
} catch( ArgParseException &e) {
|
||||
}
|
||||
catch( ArgParseException &e)
|
||||
{
|
||||
throw ArgParseException(e.error(), toString());
|
||||
}
|
||||
|
||||
if ( _constraint != NULL )
|
||||
if ( ! _constraint->check( _value ) )
|
||||
throw( CmdLineParseException( "Value '" + val +
|
||||
|
@@ -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
|
||||
@@ -97,12 +98,11 @@ class ValuesConstraint : public Constraint<T>
|
||||
|
||||
template<class T>
|
||||
ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
|
||||
: _allowed(allowed),
|
||||
: _allowed(allowed),
|
||||
_typeDesc("")
|
||||
{
|
||||
for ( unsigned int i = 0; i < _allowed.size(); i++ )
|
||||
{
|
||||
|
||||
#if defined(HAVE_SSTREAM)
|
||||
std::ostringstream os;
|
||||
#elif defined(HAVE_STRSTREAM)
|
||||
@@ -110,11 +110,8 @@ ValuesConstraint<T>::ValuesConstraint(std::vector<T>& allowed)
|
||||
#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;
|
||||
|
@@ -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
|
||||
@@ -69,7 +70,8 @@ class VersionVisitor: public Visitor
|
||||
* Calls the version method of the output object using the
|
||||
* specified CmdLine.
|
||||
*/
|
||||
void visit() {
|
||||
void visit()
|
||||
{
|
||||
(*_out)->version(*_cmd);
|
||||
throw ExitException(0);
|
||||
}
|
||||
|
@@ -23,7 +23,8 @@
|
||||
#ifndef TCLAP_VISITOR_H
|
||||
#define TCLAP_VISITOR_H
|
||||
|
||||
namespace TCLAP {
|
||||
namespace TCLAP
|
||||
{
|
||||
|
||||
/**
|
||||
* A base class that defines the interface for visitors.
|
||||
|
@@ -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
|
||||
@@ -116,14 +117,12 @@ inline int XorHandler::check( const Arg* a )
|
||||
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;
|
||||
@@ -131,7 +130,6 @@ inline int XorHandler::check( const Arg* a )
|
||||
return static_cast<int>(_orList[i].size());
|
||||
}
|
||||
}
|
||||
|
||||
if ( a->isRequired() )
|
||||
return 1;
|
||||
else
|
||||
@@ -146,7 +144,6 @@ inline bool XorHandler::contains( const Arg* a )
|
||||
it++ )
|
||||
if ( a == (*it) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
@@ -84,7 +85,7 @@ class ZshCompletionOutput : public CmdLineOutput
|
||||
};
|
||||
|
||||
ZshCompletionOutput::ZshCompletionOutput()
|
||||
: common(std::map<std::string, std::string>()),
|
||||
: common(std::map<std::string, std::string>()),
|
||||
theDelimiter('=')
|
||||
{
|
||||
common["host"] = "_hosts";
|
||||
@@ -110,11 +111,9 @@ inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd )
|
||||
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) == '<' )
|
||||
@@ -122,7 +121,6 @@ inline void ZshCompletionOutput::usage(CmdLineInterface& _cmd )
|
||||
else if ( (*it)->getFlag() != "-" )
|
||||
printOption((*it), getMutexList(_cmd, *it));
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
@@ -164,7 +162,6 @@ inline void ZshCompletionOutput::basename( std::string& s )
|
||||
inline void ZshCompletionOutput::printArg(Arg* a)
|
||||
{
|
||||
static int count = 1;
|
||||
|
||||
std::cout << " \\" << std::endl << " '";
|
||||
if ( a->acceptsMultipleValues() )
|
||||
std::cout << '*';
|
||||
@@ -173,7 +170,6 @@ inline void ZshCompletionOutput::printArg(Arg* a)
|
||||
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() )
|
||||
@@ -192,7 +188,6 @@ 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) "))
|
||||
@@ -212,9 +207,7 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
||||
{
|
||||
desc.replace(0, 1, 1, tolower(desc.at(0)));
|
||||
}
|
||||
|
||||
std::cout << " \\" << std::endl << " '" << mutex;
|
||||
|
||||
if ( a->getFlag().empty() )
|
||||
{
|
||||
std::cout << name;
|
||||
@@ -227,7 +220,6 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
||||
std::cout << "=-";
|
||||
quoteSpecialChars(desc);
|
||||
std::cout << '[' << desc << ']';
|
||||
|
||||
if ( a->isValueRequired() )
|
||||
{
|
||||
std::string arg = a->shortID();
|
||||
@@ -264,7 +256,6 @@ inline void ZshCompletionOutput::printOption(Arg* a, std::string mutex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << '\'';
|
||||
}
|
||||
|
||||
@@ -272,18 +263,15 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar
|
||||
{
|
||||
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();
|
||||
@@ -309,13 +297,12 @@ inline std::string ZshCompletionOutput::getMutexList( CmdLineInterface& _cmd, Ar
|
||||
return list.str();
|
||||
}
|
||||
}
|
||||
|
||||
// wasn't found in xor list
|
||||
if (!a->getFlag().empty()) {
|
||||
if (!a->getFlag().empty())
|
||||
{
|
||||
list << "(" << a->flagStartChar() << a->getFlag() << ' ' <<
|
||||
a->nameStartString() << a->getName() << ')';
|
||||
}
|
||||
|
||||
return list.str();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user