SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTFunctorMap1< Key > Class Template Reference

Deprecated. A functor map that takes only one argument at invocation time and returns no value. More...

#include <rw/functor/map/RWTFunctorMap1.h>

Inheritance diagram for RWTFunctorMap1< Key >:
RWTFunctor1< Key >

Public Types

typedef unsigned(* hash_function) (const Key &)
 
typedef Key key_type
 
- Public Types inherited from RWTFunctor1< Key >
typedef void(* CallerSignature) (Key)
 
typedef Key S1Type
 

Public Member Functions

 RWTFunctorMap1 (const RWTFunctorMap1< Key > &second)
 
 RWTFunctorMap1 (hash_function hf, size_t size=RW_FUNCTOR_MAP_CAPACITY)
 
 ~RWTFunctorMap1 (void)
 
bool add (Key key, RWFunctor0 functor)
 
void clear (void)
 
bool contains (Key key) const
 
size_t entries (void) const
 
bool find (Key key, RWFunctor0 &functor) const
 
RWFunctor0 getDefault (void) const
 
void operator() (Key key) const
 
RWTFunctorMap1< Key > & operator= (const RWTFunctorMap1< Key > &second)
 
bool remove (Key key)
 
void resize (size_t size)
 
void setDefault (RWFunctor0 functor)
 
- Public Member Functions inherited from RWTFunctor1< Key >
 RWTFunctor1 (const RWTFunctor1< Key > &second)
 
 RWTFunctor1 (const RWTFunctor< void(Key)> &second)
 
 RWTFunctor1 (RWStaticCtor)
 
 RWTFunctor1 (RWTFunctor1Imp< Key > *functorImp)
 
 RWTFunctor1 (void)
 
 ~RWTFunctor1 (void)
 
RWTFunctor1Imp< Key > & body (void) const
 
RWTFunctor1< Key > & operator= (const RWTFunctor1< Key > &second)
 
RWTFunctor1< Key > & operator= (const RWTFunctor< void(Key)> &second)
 

Detailed Description

template<class Key>
class RWTFunctorMap1< Key >
Deprecated
As of SourcePro 12.5, use RWTValHashMap<Key, RWTFunctor<void()>> instead.

The RWTFunctorMap1 class represents the functor maps that take only one argument at invocation time and return no value. Since this single argument is the key into the map, the functors held in the map take no arguments, and are RWFunctor0 functors.

Functor maps allow functors to be grouped together in a key/value table structure. Add functors to the map with a corresponding key of type key_type, used later to invoke the desired functor.

Example
#include <rw/functor/map/RWTFunctorMap1.h>
#include <rw/functor/functor0.h>
#include <rw/cstring.h>
// Functions that we want to wrap in functors:
void okButton() { std::cout << "okButton was pushed" << std::endl; }
void cancelButton() {
std::cout << "cancelButton was pushed" << std::endl;
}
int main() {
// Create new RWFunctor0s to be the values in the map.
RWFunctor0 okFunctor = rwtMakeFunctor0((void (*)(void))0, okButton);
RWFunctor0 cancelFunctor =
rwtMakeFunctor0((void (*)(void))0, cancelButton);
// Create keys with which to associate the values.
RWCString okKey = "ok";
RWCString cancelKey = "cancel";
// Declare a new map. A complete, but empty, instance
// now exists.
// Add something to the map to make it useful.
fmap.add(okKey, okFunctor);
fmap.add(cancelKey, cancelFunctor);
// Invoking the map with the key "ok" calls the okButton functor.
fmap("ok");
// Finally, invoking the map with the key "cancel" calls the
// cancelButton functor.
fmap("cancel");
return 0;
}
Offers powerful and convenient facilities for manipulating strings.
Definition stdcstring.h:826
static unsigned hash(const RWCString &str)
Definition stdcstring.h:4413
Deprecated. Represents the group of functors that are invoked without any arguments and whose invocat...
Definition RWFunctor0.h:94
Deprecated. A functor map that takes only one argument at invocation time and returns no value.
Definition RWTFunctorMap1.h:103
RWFunctor0 rwtMakeFunctor0(void(*caller)(void), DR(*callee)(void))
Definition rwtMakeFunctor0.h:83

OUTPUT:

okButton was pushed
cancelButton was pushed

Member Typedef Documentation

◆ hash_function

template<class Key >
typedef unsigned(* RWTFunctorMap1< Key >::hash_function) (const Key &)

The signature of the hash function.

◆ key_type

template<class Key >
typedef Key RWTFunctorMap1< Key >::key_type

The type of the key.

Constructor & Destructor Documentation

◆ RWTFunctorMap1() [1/2]

template<class Key >
RWTFunctorMap1< Key >::RWTFunctorMap1 ( hash_function hf,
size_t size = RW_FUNCTOR_MAP_CAPACITY )

Constructs an empty map instance. This creates a complete RWTFunctorMap1 instance, but with no entries. The size parameter has a default value of RW_FUNCTOR_MAP_CAPACITY, defined in rw/functor/map/pkgdefs.h.

◆ RWTFunctorMap1() [2/2]

template<class Key >
RWTFunctorMap1< Key >::RWTFunctorMap1 ( const RWTFunctorMap1< Key > & second)

Copy constructor. Constructs a new functor map instance that shares its representation with the functor map second.

◆ ~RWTFunctorMap1()

template<class Key >
RWTFunctorMap1< Key >::~RWTFunctorMap1 ( void )

Destructor.

Member Function Documentation

◆ add()

template<class Key >
bool RWTFunctorMap1< Key >::add ( Key key,
RWFunctor0 functor )

Adds the specified functor to the functor map with the corresponding key, and returns true. If an entry already exists with an equivalent key, returns false, and the addition fails.

◆ clear()

template<class Key >
void RWTFunctorMap1< Key >::clear ( void )

Clears the functor map of all entries.

◆ contains()

template<class Key >
bool RWTFunctorMap1< Key >::contains ( Key key) const

Returns true if the functor map contains an entry with key equivalent to the given key, otherwise false.

◆ entries()

template<class Key >
size_t RWTFunctorMap1< Key >::entries ( void ) const

Returns the number of entries in the functor map.

◆ find()

template<class Key >
bool RWTFunctorMap1< Key >::find ( Key key,
RWFunctor0 & functor ) const

Finds the entry in the functor map with a key equivalent to the given key, and returns it via the reference parameter functor. Returns true if the key is found, otherwise false. If a matching key is not found but a default functor exists, sets the parameter functor to the default functor, and returns false. If no match is found and there is no default functor, throws an RWTHRInternalError exception.

See also
setDefault().

◆ getDefault()

template<class Key >
RWFunctor0 RWTFunctorMap1< Key >::getDefault ( void ) const

Returns the map's default functor.

See also
setDefault().

◆ operator()()

template<class Key >
void RWTFunctorMap1< Key >::operator() ( Key key) const

Invokes the functor in the map that is associated with a key equivalent to the given key. If there is no matching key, and a default functor has been set, calls the default. If there is no default and no matching key, throws an RWTHRInternalError exception.

◆ operator=()

template<class Key >
RWTFunctorMap1< Key > & RWTFunctorMap1< Key >::operator= ( const RWTFunctorMap1< Key > & second)

Assignment operator. Binds this functor map instance to the representation of the second map instance.

◆ remove()

template<class Key >
bool RWTFunctorMap1< Key >::remove ( Key key)

Removes the entry, if it exists, with a key equivalent to the given key, and returns true. If no such entry exists, returns false.

◆ resize()

template<class Key >
void RWTFunctorMap1< Key >::resize ( size_t size)

Changes the size of the map to size. This is an expensive operation, since the entire map must be re-created. Size can be set at construction time via the size parameter of the constructor.

◆ setDefault()

template<class Key >
void RWTFunctorMap1< Key >::setDefault ( RWFunctor0 functor)

Sets functor as the default functor. This functor is used when an invalid key is provided to access the functor map.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.