need a command-line parser to fit my requirements - c++

It's a question about C/C++ command line parser.
I used the command line parsers provided in glib and Boost, but I found them not satisfying. I have two special requirements:
multiple values following one key, so that I can use file glob on command line like this:
my_program --input dir/*.txt
customized value type, like this:
typedef enum { FORMAT_A, FORMAT_B, FORMAT_C } InputFormat;
InputFormat option_format;
I want my user can specify the format in command line --format format_a. The parser need to allow customized callback function to recognize the string value and set the enum value.
It seems boost supports 1 but not 2. It only allow you define an additional parser that traverse the tokens one by one, but not by KV pairs. And glib supports 2 but not 1. It only allows multiple calling like --input foo --input bar.
Any more libs that support both 1 and 2? Or any suggestions on advanced use of glib or boost to achieve both 1 and 2?

Boost can in fact handle requirement 2. You'll need to create your own child of value_semantic with an appropriate parser and pass an instance of that into add_options rather than using the typical value<int>() mechanism.

Related

How can I run a custom command at build time in meson?

in my projects I adopt a semantic versioning scheme following the standard described by semver. I obtain something like this: product_v1.2.3-alpha-dirty.elf .
I work with embedded system and with make I usually generate a version_autogen.h file at compile time that contains both information of the version number , e.g 1.4.3.1, and current git repository, e.g --dirty, --clean and so on, using shell commands.
I'm starting to using meson and it is very easy and flexible but the custom commands like
run_command('command', 'arg1', 'arg2', 'arg3')
are available only at configure time while I need them at compile time to retrieve information like git status and similar.
How can I do that?
After a deeper research I found that custom_target() (as suggested by nielsdg) can do my job. I did something like this:
# versioning
version_autogen_h = custom_target(
'version_autogen.h',
output : 'version_autogen.h',
input : 'version_creator.sh',
command : ['#INPUT#', '0', '0', '1', 'alpha.1', '#OUTPUT#' ],
)
where version_creator.sh is my bash script that retrieves git info and creates the file version_autogen.h given the version numbers passed as the command arguments. The custom target is created at compile time, so my script is executed at compile time as well, exactly when I want it to be.
I also discovered that in meson there is the possibility to use generators to do something similar to this but in that case they transform an input file in one or more output file, so they didn't fit my case where I didn't need to have a file as input but just versioning numbers.
meson has specialized command for this job - vcs_tag
This command detects revision control commit information at build time
and places it in the specified output file. This file is guaranteed to
be up to date on every build. Keywords are similar to custom_target.
, so it'd look a bit shorter with possibility to avoid generation script and have just
git_version_h = vcs_tag(input : 'version.h.in',
output : 'version.h')
where version.h.in file that you should provide with #VCS_TAG# string that will be replaced, e.g.
#define MYPROJ_VERSION "#VCS_TAG#"
of course, you can have file header and naming according to your project style and possibly to add other definitions also. It is also possible to use another replace string and own command line to generate version, e.g.
vcs_tag(command: [
'git', '--git-dir', meson.build_root(),
'describe', '--tags', '--long',
'--match', '?.*.*', '--always'
],
...
)
which I found and adapted from here

How do I add comments to my config file using QSettings?

I'm writing a c++ code using qt and need an editable config file for my user to change some settings. In order to provide him some additional information I would like to add comments to my config file, however I cant find a way to mark them as comments.
I am using QSettings, my file is a .flt file. The usual '#' unfortunately does not seem to work with QSettings.
when using setting files in Qt and the QSettings class, you don't use the "usual"
#
for defining a comment, but the
;
instead...
so:
[abc]
key=val
;this is a comment in the QSettings
flag=true
QSetting's INI file format uses MS Windows file format, which is
a) hierarchical and uses brackets [] for section names
b) uses ; to designate comment lines.
Note, thr default engine of QSetting would wipe any comments, because the whole mechanism is just serialization of name-value pairs from file and to file. To avoid that, a custom reader-writer class should be devised which would read and preserve comments somehow. QSettings supports custom formats by offering interface for read and write functions.

How to pass parameters to svcutil

I am trying to generate the proxy file from wcf service using svcutil.exe, but I didn't understand how to pass the parameters to svcutil to collection type as system.Collections.Generic.List
I tried the below command in visual studio command prompt.
svcutil http://localhost:19021/InterviewManagementService/InterviewManagementService.svc /l:C# /out:Reference.cs /config /s /ct:System.Collections.Generic.List`1 /t:code /n:*,newnamespace
Please correct me with the above command.
I think you need to specify the assembly for the referenced collection types (more info here).
When using the Svcutil.exe tool, this reference can be accomplished by using the /collectionType command-line switch (short form: /ct). Keep in mind that you must also specify the assembly for the referenced collection types using the /reference switch (short form: /r). If the type is generic, it must be followed by a back quote and the number of generic parameters. The back quote (`) is not to be confused with the single quote (‘) character. You can specify multiple referenced collection types by using the /collectionType switch more than once.
So you need to add /r:C:\full_path_to_system_dll\System.dll to your command right before /ct:System.Collections.Generic.List

How to use the original filename in a multi file template in resharper?

I have a multi file template in resharper and I can use $NAME$ macro to get the name of the original file to use to name the other files in the template. But I also want to use the $NAME$ of the original file in the content of the other file template.
Is this possible? I can't see a macro which seems suitable for the internal variables as onlt the Current File Name seems available.
Anyone know if this is possible or how I might workaround this?
As a workaround, you may create a parameter $FILENAME$ (macro "Current file name without extension") in the first file e.g. in the comments, like:
class Foo
{
//$FILENAME$
}
Then you may call this parameter in other files of the multifile template - this parameter will contain the name of the first file since the first file will be generated before other ones.
Unfortunately, there isn't a macro that will give you this. I've added a feature request that you can vote on and track (and more specific detail as to what your requirements are would be useful) - http://youtrack.jetbrains.com/issue/RSRP-415055
It is possible to write your own macros as part of a plugin, but there isn't a sure-fire way of getting the name of the first document in the created file set. The IHotspotSessionContext instance that is passed to the macro via IHotspotSession.Context property includes an enumerable of IDocument, from which you can get IDocument.Moniker, which will be the full path for file based documents. However, there's no guarantee of the order of the enumerable - it's backed by a hashset. You might be able to rely on implementation details (small set, no removes) to be able to use the first document as the original, but there is really no guarantee of this.

How do I create an object from parsing FIX XML data in C++?

The XML below represents a FIX message. This message has a variable number of fields (numbered using the id tag), each containing differing attributes. So I would like to parse this XML and with my additional coding abilities output a C++ message object which includes all the attribute information per field.
First question would be- is there a boost library which I can use to do this? My second question would be what is the interface between what the XML parser can provide and where I have to write code to create the objects. So for example, in the XML on line 8 there is a <delta/> tag and this is an attribute of the object. So for field 52 (line 8) the attribute would be a Delta sub type object but for line 9 the attribute would be a Copy subtype object. I would like to store these subtypes in an std::unordered_map with the field ID being the key.
I guess another way of wording this is- what "end result" will the XML parser give me to help build the objects the way I want them?
You should probably use one of the many commonly-used xml parsers, Xerces and TinyXML are two possibilities. There are more. Google is your friend.
You want to run in SAX mode rather than DOM mode (the documentation for the parser you choose will explain). That means the parser will call code you supply for each element and attribute it parses rather than building an arbitrary structure in memory that doesn't match your domain-specific needs.