FBB::FnWrap1c

FBB::FnWrap1c

libbobcat1-dev_2.02.03-x.tar.gz

2005-2009


FBB::FnWrap1c(3bobcat)

FBB::FnWrap1c(3bobcat)

libbobcat1-dev_2.02.03-x.tar.gz Configurable Unary FnWrapper

2005-2009

NAME

FBB::FnWrap1c - Configurabale unary argument wrapper template class

SYNOPSIS

#include <bobcat/fnwrap1c>

DESCRIPTION

The FBB::FnWrap1c class is a configurable unary argument conetext wrapper template class. Its primary use is in combination with the generic algorithms from the standard template libray. The called function expects a local context struct which is used to pass arguments to the function called by the generic algorithm which are available in the local context of the called generic algorithm. The local context struct can be either a const or non-const struct.

The called function itself may be specified as one of the constructor's arguments. It must be a (static member) function. Using a (static member) function has various advantages, especially with the FnWrap?c classes to which a local context can be passed:

The FBB::FnWrap1c template class has the following template parameters:

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

CONSTRUCTOR

OVERLOADED OPERATOR

The following member function will call the function that's passed to FBB::FnWrap1c's constructor. See the example below.

TYPEDEFS

The class defines two types, which are used by generic algorithms:

EXAMPLE


    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <bobcat/fnwrap1c>
    
    using namespace std;
    using namespace FBB;
    
    class Strings
    {
        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
            {
                SContext c = {1, out};
                find_if(d_vs.begin(), d_vs.end(),
                    FnWrap1c<string const &, SContext &, bool>
                         (&Strings::untilEmpty, c));
            }
    
        private:
            struct SContext
            {
                size_t nr;
                ostream &out;
            };
    
            static bool untilEmpty(string const &str, SContext &c)
            {
                if (str.empty())
                    return true;        // stop
    
                c.out << c.nr++ << " " << str << endl;
                return false;           // don't stop
            }
    };
    
    int main()
    {
        Strings s;
    
        s.display(cout);
    }
        
After compilation and linking, simply call the program without any arguments.

FILES

bobcat/fnwrap1c - defines the class interface

SEE ALSO

bobcat(7), fnwrap1(3bobcat), fnwrap2(3bobcat), fnwrap2c(3bobcat), foreach(3bobcat), lc(3bobcat), repeat(3bobcat)

BUGS

Caveat: the template parameter specifying the type of the local context struct should probably not be specified as a value type as this will result in copying the local context struct for each call of the FNWrap1c object or of the function that it is provided with, making it impossible for the algorithms to modify value- or pointer-fields of the outermost local context struct. Instead, the template type specifying the type of the local context struct should be specified as a pointer or reference template type when instantiating the FnWrap1c object.

DISTRIBUTION FILES

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).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).