Quote:
Originally Posted by mikets
Sure, how about this? It is basically the same as your Posedge_toggle class except that it allows the update method to also return the switch state so you don't have to make the get call.
|
That would work too.
It seems like you've added a lot of unnecessary stuff though. You're made the class's code go from 13 lines to 33 while you could have made it do that by just adding one line:
Code:
class Posedge_toggle{
bool value,last;
public:
Posedge_toggle():value(0),last(1){}
bool update(bool sample){
if(sample&&!last) value=!value;
last=sample;
return value; //this is the only new line
}
bool get()const{ return value; }
};
As for whether the code ought to work this way, I guess it's a matter of taste, but I prefer
command-query seperation when possible.