file: filter.cc
/*
This file contains the longer methods for the filter class
declared in filter.h. The methods included are:
constructor:
filter::filter(unsigned short int newmask,const vector<unsigned short int>& //OVERLOAD CALL: filter: filter.cc(filter), filter.h(filter)
newfields)
unsigned short int filter::args(const vector<unsigned short int>& args) const -filters arguments as unsigned short ints into opcodes.
void filter::printstate() const -prints out state of filter
Revision History:
first made: 3/4/96 by John Langford
*/
#include "filter.h"
/*
filter(unsigned short int newmask,const vector<unsigned short int>& //OVERLOAD CALL: filter: filter.cc(filter), filter.h(filter)
newfields)
Description: Constructs the argument to opcode filter. The object will
output an object code with the bits in newmask bitwise
'or'ed with the various arguments.
Arguments: newmask - the instruction bits of an opcode.
newfields - a vector of bit locations just past the high
bit of each argument field.
Return Value: None.
Inputs: None.
Outputs: None.
Error Handling: error object
Algorithms: None.
Data Structures: None.
Last Modified: 3/4/97
*/
filter::filter(unsigned short int newmask,const vector<unsigned short int>&
newfields)
{
if (newmask > maxbitfield)
mask=err(OVERSIZE_MASK,newfields,newmask);
mask=newmask;
//check that bitfields don't overlap
for(vector<unsigned short int>::const_iterator i=newfields.begin();
i!=newfields.end();i++)
{
if ((unsigned short int)1 << (*i) > maxbitfield)
err(OVERSIZE_FIELD,newfields,*i);
}
fields=newfields;
}
/*
inline void filter::printstate() const
Description: Prints out the state of the filter in a human readable form
Arguments: none.
Return Value: none.
Inputs: None.
Outputs: the base instruction bitfield as 0's and 1's followed by
the bit 1 past high of each argument field.
Error Handling: None.
Algorithms: None.
Data Structures: None.
Last Modified: 3/4/97
*/
struct foo : unary_function<unsigned short int, int>{
};
void foo::operator() (const unsigned short int& p)
{
cout << "high = " << p << endl;
}
void filter::printstate() const
{
cout << hex << mask << dec << endl;
for (int i=maxbitfield/2;i>0;i/=2)
if (((mask/i)%2)==1)
cout << "1";
else
cout << "0";
cout << endl;
for_each(fields.begin(),
fields.end(),
foo());
}
/*
args(const vector<unsigned short int>& args)
Description: This is the actual filter. It takes a vector of args, and
bitwise 'or's them at the appropriate locations in the
opcode.
Arguments: args -a vector of the arguments as unsigned short ints.
Return Value: unsigned short int - the instruction bits 'or'ed with the
arguments.
Inputs: None.
Outputs: None.
Error Handling: error object
Algorithms: None.
Data Structures: None.
Last Modified: 3/4/97
*/
unsigned short int filter::args(const vector<unsigned short int>& args) const
{
unsigned short int ret=mask;
if (args.size()!=fields.size()){
return err(WRONG_ARGUMENT_COUNT,args,ret);
}
vector<unsigned short int>::const_iterator i=fields.begin();
for(int fnum=0;i!=fields.end();i++,fnum++)
{
unsigned short int low;
if((i+1)!=fields.end())
low=(*(i+1));
else
low=0;
if ((((unsigned short int)1 << ((*i)-low-1))) < args[fnum]){
return err(OVERSIZE_ARGUMENT, args, args[fnum]);
}
else
ret = ret | (args[fnum] << low);
}
return ret;
}
C++ to HTML Conversion by ctoohtml