mirror of
https://github.com/worldforge/worldforge
synced 2026-08-17 16:26:05 -04:00
63 lines
2.2 KiB
Text
63 lines
2.2 KiB
Text
I'm trying to come up with a general class layout that all
|
|
(significant) classes will obey. Friend functions are included
|
|
under the corresponding section. Currently it's this:
|
|
|
|
1) Constructors and destructor
|
|
|
|
The default constructor will not initialize the object. If the default
|
|
constructor is used, the object must first be initialized with operator>>(),
|
|
FromString(), FromAtlas(), operator=(), or one of the initializer functions
|
|
given later in the class. There is no constructor from a string value, as such
|
|
construction can fail. The destructor is not virtual, nor is any other
|
|
function in the class, as this is a low-level library designed primarily
|
|
for speed.
|
|
|
|
2) operator<<() and operator>>(), toAtlas() and fromAtlas()
|
|
|
|
friend std::ostream& operator<<(std::ostream& os, const Foo& f);
|
|
friend std::istream& operator>>(std::istream& is, Foo& f);
|
|
|
|
operator>>() indicates a parse failure by setting the fail() flag on the stream.
|
|
Failure also indicates that the object is in an invalid state. The definitions
|
|
of these functions are placed in the file stream.h, so the class only needs to
|
|
include <iosfwd>. The toAtlas() and fromAtlas() functions need a forward
|
|
declaration of Atlas::Message::Object, which is done in const.h. They
|
|
are only defined for certain classes (see Atlas protocol specs (where?)
|
|
for details). The implementations of these functions belong in atlasconv.h,
|
|
and must be done inline or as templates, so that the library can be built and
|
|
used without libAtlas.
|
|
|
|
3) operator=()
|
|
|
|
4) isEqualTo() method
|
|
|
|
this function is of the form
|
|
|
|
bool C::isEqualTo(const C& c, CoordType tolerance = WFMATH_EPSILON);
|
|
|
|
5) operator==(), operator!=()
|
|
|
|
these call isEqualTo()
|
|
|
|
6) Class initializers
|
|
|
|
e.g. zero() for Vector<>, origin() for Point<>, etc.
|
|
|
|
7) operator<()
|
|
|
|
sort only, if comparison makes sense stick others here too
|
|
|
|
8) math operators
|
|
|
|
9) other operators (e.g. operator[]())
|
|
|
|
10) other functions
|
|
|
|
11) dimension-specific constructors/operators/functions
|
|
|
|
e.g. Vector(CoordType& x, CoordType& y, CoordType& z) for Vector<3>
|
|
|
|
Every class is also defines two non-member functions:
|
|
ToString() and FromString(). These functions are
|
|
automatically generated in stream.h using templates
|
|
and the operator<<() and operator>>() functions.
|