 |
|
 |
I want to pass the name of a filename on the command line, then open and read from that file. I want to put the filename into a char* variable. There doesn't appear to be any way to do this. None of these will work:
char filename[256];
strcpy(filename, p["paramName"]);
or
filename << p["paramName"];
or
char filename[256] = p["paramName"];
Also, I'd like to know what sort of license you're releasing this with. Can I use it for anything, free of charge?
Sadly, I spent some time writing a similar class about 15 years ago, and can't find the source code to it now.
|
|
|
|
 |
|
 |
Really nice is the dynamic documentation and also the realization of nested switches.
To get values with blanks handled correct, you need to set 3 <"> ( prog -f """a bc.txt""", correct would be prog -f "a bc.txt" )
How can I handle / recognize optional noswitch arguments ?
( e.g. prog -action=list file1 file2 ..... )
|
|
|
|
 |
|
 |
The CVS version of Boost (on 22 Sep 04) has a very similar library. I am checking it out now.
--
alnitak
|
|
|
|
 |
|
 |
Thanks for posting this, I was just looking for something to deal with this chore! I have a few suggestions if you don't mind, I am using MS dotNet 2003 (beginner here so take this with a pinch of salt).
At the end of ParamContainer.h there is this line:
#endif __PARAMCONTAINER_H
it needs to be changed to
#endif // __PARAMCONTAINER_H
and a newline is needed too!
Secondly you are using a couple of functions (stricmp and getcwd) which are not found by the Microsoft linker, because MS saw fit to rename them to _stricmp and _getcwd. If the names are changed in the source then the code compiles fine. Better is to use this bit of macro hackery I got from the web:
/* _MSC_VER is defined by Microsoft compilers */
#ifdef WIN32
# ifdef _MSC_VER
# define stricmp _stricmp
# define getcwd _getcwd
# endif
#else
#define stricmp strcasecmp
#endif
Actually, the use of stricmp can be eliminated altogether (it's not part of the C++ standard, it's a C routine) by writing a routine to lowercase a string:
std::string ToLower(const std::string& Str) {
std::string result(Str);
for (std::string::iterator i = result.begin(); i != result.end(); ++i)
*i = static_cast (tolower(*i));
return result;
}
if(j==k && ((div[0]=='\\' && (ToLower(spath.substr(i, j-i)) != ToLower(tpath.substr(i, k-i)))) || (div[0]=='/' && spath.substr(i, j-i) == tpath.substr(i, k-i))))
//if(j==k && ((div[0]=='\\' && !stricmp(spath.substr(i, j-i).c_str(), tpath.substr(i, k-i).c_str())) || (div[0]=='/' && spath.substr(i, j-i)==tpath.substr(i, k-i))))
getcwd can't be removed in this fashion, but I would go further and notice that there is quite a lot of code just to support the loading and saving of parameter containers, and I don't think this will be used by 95% of the clients of this class, so why not move it into a derived class, say "PersistentParamContainer", or into global functions within a ParamContainer namespace? I didn't have time to pursue this myself, so I just deleted all that code. (In fact, this gets rid of the need for stricmp too
I would also like the facility to do a lookup of option names in a case sensitive manner. This is because it is my experience that most people on Windows expect case-insensitive operations. I think this should be done by getting rid of the initOptions routine, adding those and the new case sensitive option into the constructor, and then constructing a map which is case-sensitive or not, as appropriate. There is some code here to do it, but I haven't had chance to do that yet. And it's a bit tricky at the moment with all those Russian comments
If you email me I will send you my modified version.
--
alnitak
|
|
|
|
 |
|
 |
alnitak wrote:
std::string ToLower(const std::string& Str) {
std::string result(Str);
for (std::string::iterator i = result.begin(); i != result.end(); ++i)
*i = static_cast (tolower(*i));
return result;
}
Or:std::string ToLower(const std::string& Str)
{
std::string result(Str);
std::transform(result.begin(), result.end(), result.begin(), tolower);
return result;
}Suits my taste a bit more, but YMMV, as always.
--
The Blog: Bits and Pieces
|
|
|
|
 |
|
 |
I've been looking for something like this for .NET console apps. Any chance you have a C# version?
Unfortunately all the comments in the code are garbled - I assume some sort of non-standard character set? I was unable to view them in either VS.NET or Notepad.
Nice code, regardless!
|
|
|
|
 |
|
 |
Thank you for your feedback.
No, unfortunately our group currently is not developing on C#.
All comments are in Russian language (Win1251 charset, if you care about We thought that explanations in readme.txt will be enough to understand how to use it. If you still want to see comments, we can translate to English in a while.
BioRainbow Group,
www.biorainbow.com
|
|
|
|
 |
|