Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Arrys vs Vectors
Re: Arrys vs Vectors [message #30270 is a reply to message #30268] Tue, 21 December 2010 12:36 Go to previous messageGo to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i'd recommend to use Vector here, see Core/Gtypes.h for Size and Point implementations, they also are templates, and are only Moveable<>, no need for you to MoveableAndDeepCopyOption<> them. it is a lightweight pointer class as i can see. it is best copied. i suppose T is double or float..

picked is misleading... Upp has own usage for pick stuff, think of a different name for it.

also, use the initializer list in constructors, and the implicit logic of classes (aka implicit copy constructor).

think of what you really need to have getters/setters to. better make the members public in this case.

template<class T>
class Point3D : Moveable<Point3D<T> >
{
public:
	T x,y,z,w;
	unsigned int id,layer;
	bool taken;
public:
	Point3D ()
		: x(T())
		, y(T())
		, z(T())
		, w((T)1.0)
		, id(0)
		, layer(-1)
		, taken(0)
	{}	

	Point3D (const T& a, const T& b, const T& c, unsigned int e, bool f, unsigned int g, const T& d=(T)1.0)
		: x(a)
		, y(b)
		, z(c)
		, w(d)
		, id(e)
		, layer(g)
		, taken(f)
	{}

	//use implicit copy constructor

	//this one should probaly be Point3D<T> operator*(const T& o) const, since yours is modifying object
	void operator*(const T& o){
		x*=o;
		y*=o;
		z*=o;
		w*=o;
	}

	Point3D<T> operator+(const Point3D<T> &o){
		return Point3D<T>(x+o.x(),y+o.y(),z+o.z(),w+o.w());
	}

	void Serialize(Stream& s){
		s%x%y%z%w%id%taken%layer;		
	}

	String ToString()const{
		String s;
		s<<"x:"<<x<<","<<"y:"<<y<<","<<"z:"<<z<<","<<"w:"<<w<<","<<"id:"<<id<<","<<"taken:"<<taken<<", "<<"layer:"<<layer;
		return s;
	}	
};


GUI_APP_MAIN
{
	Vector<Point3D<double> > v;
	v.Add();
	
	Vector<Point3D<double> > vw;
	vw <<= v;

	Point3D<double> p;
	p = v[0];
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: asxml...or like I would like to keep encoding...
Next Topic: :( errors on sfx project
Goto Forum:
  


Current Time: Fri May 10 16:42:58 CEST 2024

Total time taken to generate the page: 0.01718 seconds