View Single Post
  #7   Spotlight this post!  
Unread 18-12-2013, 02:56
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
Re: C++ Toggle Button

Quote:
Originally Posted by mikets View Post
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.
Reply With Quote