Hello,
I'm back on the topic of C++ coding style to annoy those of you
who actually DO something to enhance AviFile.
As usual in many C++ programs, most avifile classes have a lot
of small methods just to get/set attributes. In the book
Exceptional C++ I've read some rationale on a common style for
such functions and I've decided to adopt it unconditionally.
So, if you have an attribute called "foo" which is both readable
and writable, you just need two members:
class myClass
{
private:
clFoo * _foo;
public:
clFoo * foo() const { return _foo };
void foo(clFoo * f) { _foo = f };
}
You use it like this:
// set foo
myclass.foo(f);
// get foo
f = myclass.foo();
Note that there's no "get" or "set" prepended to the method names,
since it's redundant and does not help understanding what the code
is doing any better.
Also note that the attribute name must now be called something else
because the word "foo" is already used. If you like Ungarish notation,
you can call it "m_foo", otherwise the best choice is "_foo", because
it makes it clear that nobody should ever need to access this member.
To be honest, the book suggested to use "foo_" to avoid clashes with
names used in the standard library.
Also the other members of the same class (and subclasses) should
use the foo() methods instead of accessing directly to _foo. The code
would get inlined anyway, so there's no speed penalty and it makes
your code easier to maintain in the case you want to drop the
_foo member to compute it on the fly or move it somewhere else.
In case you don't want to give write access to the user, you can
use
const clFoo * foo() const;
instead. If you want to implement both methods, perhaps with different
access policies (i.e.: make the const version public and the non-const
version protected or private), you should rename the other function
like this:
const clFoo * c_foo() const;
which is exactly the same convention used by the STL (string::c_str()).
Of course, this is just my $0.02 opinion ;-)
--
// Bernardo Innocenti
\X/ http://www.codewiz.org/~bernie
_______________________________________________
Avifile mailing list
[EMAIL PROTECTED]
http://prak.org/mailman/listinfo/avifile