Hurricane VLSI Database


List of all members | Public Member Functions
Hurricane::Filter< Type > Class Template Referenceabstract

Filter description (API) More...

Inheritance diagram for Hurricane::Filter< Type >:
Inheritance graph
[legend]

Public Member Functions

GenericFilter< Type > operator! () const
 
virtual Filter< Type > * getClone () const =0
 
virtual bool accept (Type type) const =0
 

Detailed Description

template<class Type>
class Hurricane::Filter< Type >

Filter description (API)

Introduction

A filter is a functional object which, used in conjunction with a collection, allows to get only the elements of this collection which meet some criteria.

This class is an abstract class which must be derived in order to get the appropriate behaviour.

You will have also to define the default constructor, the copy constructor, the assignment operator and overload the two following member functions :

Simple Example

Definition of the filter selecting external nets of a cell :

class IsExternal : public Filter<Net*> {
// ***********************************
public:
IsExternal() {};
IsExternal(const IsExternal& isExternal) {};
IsExternal& operator=(const IsExternal& isExternal) {return *this;};
virtual Filter<Net*>* getClone() const {return new IsExternal(*this);};
virtual bool accept(Net* net) const {return net->isExternal();};
};
virtual Filter< Type > * getClone() const =0
virtual bool accept(Type type) const =0

Implementation of the accessor getExternalNets for the cells :

Nets Cell::getExternalNet() const
// ******************************
{
return getNets().getSubSet(IsExternal());
}
GenericCollection< Net * > Nets
Definition: Nets.h:27

Similarly, the accessor getInternalNets can be implemented using the ! operator :

// *******************************
{
return getNets().getSubSet(!IsExternal());
}
Nets getInternalNets() const
GenericCollection< Type > getSubSet(const Filter< Type > &filter) const
Definition: Collection.h:98

Complex Example

In order to implement previous examples we could have used filter with a simpler interface. Now the filters as they are defined open the door to much more complex processing.

As a matter of fact the function accept receives only one argument which represents the element of the collection to be accepted or rejected.

Sometimes the filter must take into account other criteria. For example to print the external nets of a cell whose name start with a given character. Those additional criteria will then become attributes of the filter as shown in the following example :

Filter definition :

class MyFilter : public Filter<Net*> {
// *********************************
public:
char _c;
MyFilter(char c) : _c(c) {};
MyFilter(const MyFilter& myFilter) : _c(myFilter._c) {};
MyFilter& operator=(const MyFilter& myFilter)
{
_c = myFilter._c;
return *this;
};
virtual Filter<Net*>* getClone() const {return new MyFilter(*this);};
virtual bool accept(Net* net) const
{
return net->isExternal() && (net->getName()[0] == _c);
};
};

Afterwards do

forEach(Net*, inet, cell->getNets().getSubSet(MyFilter('k'))) {
assert(inet->isExternal());
assert(inet->getName()[0] == 'k');
cerr << "net: " << (*inet) << endl;
}

Although this example is not of great interest, it illustrates the way to proceed to create a complex filter.

Member Function Documentation

◆ operator!()

template<class Type >
GenericFilter< Type > Hurricane::Filter< Type >::operator! ( ) const
inline

Returns: the inverse filter of the filter <this> (accepted elements are those rejected and conversely).

◆ getClone()

template<class Type >
Filter< Type > * Hurricane::Filter< Type >::getClone ( ) const
pure virtual

Remarks

It is wise to use filters only when it is trully necessary, that is to produce useful collections to be used extensively.

Indeed, for the previous example, preferably write it like this :

forEach(Net*, inet, cell->getNets()) {
if (inet->isExternal() && (inet->getName()[0] == 'k'))
cerr << "net: " << *net << endl;
}

or more simply :

forEach(Net*, net, cell->getExternalNets()) {
if (inet->getName()[0] == 'k')
cerr << "net: " << *inet << endl;
}

Filters are objects like any other : they can be passed as function arguments as shown below :

Nets Cell::getNets(const GenericFilter<Net*>& filter) const
// ********************************************************
{
return getNets().getSubSet(filter);
}
Nets getNets() const
Definition: Cell.h:438

As far as the type NetFilter is defined as being a GenericFilter<Net*> the previous function can be written like this :

Nets Cell::getNets(const NetFilter& filter) const
// **********************************************
{
return getNets().getSubSet(filter);
}
GenericFilter< Net * > NetFilter
Definition: Nets.h:51

Returns: a filter copy.

◆ accept()

template<class Type >
bool Hurricane::Filter< Type >::accept ( Type  element) const
pure virtual

This member function returns true if the filter accepts the element else false.


The documentation for this class was generated from the following files:


Generated by doxygen 1.9.1 on Thu Aug 11 2022 Return to top of page
Hurricane VLSI Database Copyright © 2000-2020 Bull S.A. All rights reserved