25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Ads   Donate   Humor

anyclass.cpp

/*	anyclass.cpp               4-27-00
	A skeleton C++ class where you fill in the blanks.
	Paste the text into your program, mass-replace all "CL" with the name of your class,
	and voila, instant class with lots of typing saved.

	Text similar to this is also in an AutoText entry in the CPROGRAM.DOT MS Word template.

*/
//////////////////////////////////////////////////////////////////////////////
//
class CL : public TArrayAsVector<complex>
{
public:
	CL();
	CL(const CL& other) { *this = other; }
	virtual ~CL();

	CL& operator = (const CL& other);
	BOOL operator == (const CL& other) const;
	BOOL operator != (const CL& other) const { return(!(*this == other)); }
	BOOL operator < (const CL& other) const;
	operator int() { return(GetItemsInContainer()); }

	friend ostream& operator << (ostream& os, const CL& s);	// write
	friend istream& operator >> (istream& is, CL& s);		// read

	// functions

	// variables

protected:

};
//----------------------------------------------------------------------------
// 							end class CL
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// class CL code
//----------------------------------------------------------------------------
// constructor
CL::CL()
{

}                       	//constructor
//----------------------------------------------------------------------------
// destructor
CL::~CL()
{

}                       	//destructor
//----------------------------------------------------------------------------
// assignment operator	(always define this, and let copy constructor call it)
CL& CL::operator = (const CL& other)
{
if(this == &other)
	return(*this);

return(*this);
}                    		//assignment operator
//----------------------------------------------------------------------------
// equality
BOOL CL::operator == (const CL& other) const
{
	return(&other == this);   					// not always the test to use
}                        	//operator ==
//----------------------------------------------------------------------------
// less than
BOOL CL::operator < (const CL& other) const
{
	return(X < other.X);
}                     		//operator <
//----------------------------------------------------------------------------
// output to a stream
ostream& operator << (ostream& os, CL& s)
{
// you usually let the caller add the endl
os << "";

return(os);
}                 			//operator <<
//----------------------------------------------------------------------------
// read from a stream
// be sure to set ALL members, even those not read from the stream.
// this example is complicated, for easy reference, but uses >> ws unusually, particularly:
// do not use a final >> ws (or any input) after you have all the input you need for the object,
// because if you got what you needed, it shouldn't return as failed until the *next* call.
istream& operator >> (istream& is, CL& s)
{
char buf[80];
is >> ws;							// ensure first getline has something to read
while(is.getline(buf,sizeof(buf)))
{
	istrstream str(buf);
	str >> x >> ws;                 // do force a failure if there's nothing left on the line
	if(str)                  		// if there is anything left, it is Y
	{
		str >> y;
		s.Add(x,y);
	}
	else
		s.Add(x);            		// this x is really the y variable
	is >> ws;                       // skip blank lines before the next getline()
}
return(is);
}                  			//operator >>
//----------------------------------------------------------------------------
// 						end class CL
//////////////////////////////////////////////////////////////////////////////

 

 

Valid HTML 4.01 Transitional Valid CSS
View content labeling at ICRA.
Copyright ©2008 Steven Whitney. Last modified 02/27/2008.