misclib
This is a project space for miscellaeous tools and is a small library. As the need arises new tools will be added to this project space.
tokenizer tt; ... cout << (string)tt << endl;
printcontainer::space="\n";
cout <&tl; v << endl;
These are a function that used the operator () with a signature. For example
class fcfragle
{
public:
double operator()(double x)
{ return x*x; }
};
...
fcfragle f;
y = f(1.2);
STL's library is built on them working with templates. This is the primary use for them and is a massive topic. Presently I am going to avoid compile time binding and use functional objects for dynamic binding.
fnobj.h are the base classes with the virtual functions declared. Both const and non-const are supported.
fnobjT.h abstracts the type T away.
fnobjTfn.h is a different beast. It converts any classes member functions to functional objects.
If ever the need arises I can write non-virtual function code, but then I would probably use templates to solve the problem instead.
Process command line arguments independent of order. The name of the option and its argument are separated by an equals sign. Further the argument does not contain whitespace.
For example location=/base/p1 associates a value /base/p1 with the location variable.
This command line processing is useful because it simplifies arguments supplied to the C++ program. The programmer doesn't have to deal with the details of argc and argv. Conversions are performed in a type safe way [if the user inputs garbage expect garbage returned ] by a binding of the identifier string with a reference to a data type.
An object orientated interface evolved. Through a templated class function the user can use implicit template construction making the process easier.
A primitive help utility was added allowing the client -h command line
option to query the available bindings. The catch is the programmer has to
call the function ostream & help(ostream & os ) const. After the bindings.
A just do it implementation, tokens and bindvar were added. So the programmer can test for tokens. This is how -h works. It looks for that token and if there performs the action of displaying bindings.
I added a callback mechanism for object member functions.
mapcallback(...). Instead of writing
a variable an objects function is called. This
was intended for initialization. Here are two versions of the same
code. The mapcallback takes one line whereas the
simpler mapvar takes four. Less code to debug and clearer
code result from the mapcallback code. While the code is
complicated such that the user passes the address of the function,
this code is clearly an improvement. The reduction of programmer written
code and the automation of processes is a positive step.
cmd.mapcallback(tetd,&d4tessdraw::enablepoints,"points");
// Alternative code has 4 lines.
bool enablepoints(false);
cmd.mapvar(enablepoints);
if (enablepoints)
tetd.enablepoints();
stringstream was used to convert between a string and a variable
type. eg
stringstream s;
s << i0 << ' ' << i1;
cout << s.str();
string ss("3.14");
double d;
stringstream s(ss);
s >> d;
This class is really simple to use. The code in the interface is divided into three sections. Ignore the Specialized Functionality because its really specific and gives me a headache thinking about it.
The Input Reading Functions are concerned with initializing the data structure by reading the command line. You do need to input something.
The Binding section only has a major function to match a variable to some input.
int main( int argc, char** argv)
{
commandline cmd(argc, argv);
int count=-1;
cmd.mapvar(count,"count");
if (count!=-1)
{
// count was initialized at the command line
....