SYNOPSIS
#include <bobcat/lc>
DESCRIPTION
The template struct FBB::LC can be used to declare and define a local context struct as used with the Bobcat classes FnWrap1c and FnWrap2c.
These latter two classes are normally used in combination with generic (STL) algorithms to process data made available by the generic algorithms in combination with information that may be available locally, as in a function. Local information could consist of, e.g., local variables or parameters defined for a function.
The functions that are passed to the local context wrappers FnWrap1c and FnWrap2c therefore require the specification of the data types made available by the generic algorithms as well as the declaration and definition of a local context struct that is passed to those functions by the local context wrappers. This in turn requires the definition of the local context structs as nested structs in classes declaring such functions. Although this is perfectly possible, it complicates those classes to some extent and requires the class designer to define struct type names for the local context structs, although those type names are irrelevant in practice.
The LC template struct can be used to declare and define local context structs `on the spot' without requiring the class designer to add struct definition to the class at hand. To use the LC template struct the types of the various fields of the local context structs are specified at the template's declaration and definition and its fields are accessed through standardized field names. The first field becomes f1, the second field f2, until the last field (e.g., f12).
Clearly there is a drawback in using standardized names: the association between field name and its semantics is lost. It is a matter of taste whether this is considered a severe enough drawback to avoid using the LC template struct. But then: it is still possible to add fully defined local context structs to a class if this is preferred over using the LC template structs.
When using the LC local context struct generating template the types need to be specified in various locations: when the template is declared, when it is defined and when the context wrapper template is instantiated. This again could be considered a drawback reducing its usefulness. However, this latter drawback is easily overcome by using a typedef to associate a type name with a particular LC template configuration.
The distributed LC template struct allows for the definition of local context structs having at most 10 fields. Local context structs requiring more than 10 fields are seldom seen. Should the need for such a local context structs arise then a solution is readily available. With the Bobcat library a program bobcatlcgen(1) is distributed that can be used to recreate the <bobcat/lc> file (either locally or system-wide) allowing the use of a larger number of template type parameters than the default number of 10.
The example section shows how a LC local context struct can be used in lieu of an explicitly defined local context struct.
NAMESPACE
FBBAll constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
INHERITS FROM
-
CONSTRUCTORS
-
LC<typelist>(initialization values):
The standard copy constructor is available.
MEMBER FUNCTIONS
There are no member functions defined. As the template generates a struct rather than a class all its members are immediately available to its users.
EXAMPLE
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <bobcat/fnwrap1c> #include <bobcat/lc> using namespace std; using namespace FBB; class Strings { typedef LC<size_t, ostream &> lc; vector<string> d_vs; public: Strings() { d_vs.push_back("one"); d_vs.push_back("two"); d_vs.push_back(""); d_vs.push_back("three"); } void display(ostream &out) const { lc c(1, out); find_if(d_vs.begin(), d_vs.end(), FnWrap1c<string const &, lc &, bool> (&Strings::untilEmpty, c)); } private: static bool untilEmpty(string const &str, lc &c) { if (str.empty()) return true; // stop c.f2 << c.f1++ << " " << str << endl; return false; // don't stop } }; int main() { Strings s; s.display(cout); }
FILES
bobcat/lc - defines the class interface
BUGS
None Reported.
DISTRIBUTION FILES
- bobcat_2.08.01-x.dsc: detached signature;
- bobcat_2.08.01-x.tar.gz: source archive;
- bobcat_2.08.01-x_i386.changes: change log;
- libbobcat1_2.08.01-x_*.deb: debian package holding the libraries;
- libbobcat1-dev_2.08.01-x_*.deb: debian package holding the libraries, headers and manual pages;
-
http://sourceforge.net/projects/bobcat: public archive location;
BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL).