[Liblas-devel] HasColor() and HasTime() removed from Schema class public interface

Trudgett, David D.Trudgett at aamgroup.com
Sun Dec 19 23:22:05 EST 2010


> On Dec 19, 2010, at 7:20 PM, Trudgett, David wrote:

> > 
> > Hello,
> > 
> > In lasschema.hpp, on lines 100 & 101 (between lines 128 and 129 in
the
> > new 1.6.0b3 version of the file), the HasColor() and HasTime()
public
> > boolean methods of the Schema class seem to have been removed. 
> > 
> > Was this a mistake or is there now another way to access this
> > functionality?

> It was intentional. See below. I would note that I have been working
> under the expectation that the entire C++ API is up for grabs for
> this 1.6.0 release until it goes final. After the dust settles
> beyond this release, I don't envision it changing too much other
> than for a few additions here or there.

OK, no worries. I didn't realise that the C++ API was in a state of
flux.


> > There doesn't seem to be any mention of this change
> > anywhere that I can see. I'm trying to build an application that
depends
> > on HasColor(), but obviously the build is now failing because there
is
> > no longer any HasColor().

> Wow, I didn't know anyone noticed that, and more importantly,
> actually used it :)

Yes, apparently someone has used it ;-) It's a third party GPL
licensed application for visualising LAS point cloud data.


> The proper way to ask for HasColor or HasTime now is to ask the
> schema if the color or time dimensions exist.

> bool bColorExists = false;
> try {

> 	liblas::Dimension const& red = schema.GetDimension("Red");
> 	liblas::Dimension const& green = schema.GetDimension("Green");
> 	liblas::Dimension const& blue = schema.GetDimension("Blue");
>  	bColorExists = true;

> } catch (std::runtime_error const&)
> {
> }

OK, I've used that method, and it seems to work fine. Thank you.


> Looking at this now, maybe we should have a real exception instead
> of the generic runtime_error.

Yes, if you are going to use exceptions, then it would be better to
have the unexceptional exceptions defined! ;-) 


> Yes, I'm aware this design might rankle those who have not grown up
> with the notion that exceptions are not exceptional.

Obviously, they should not be called exceptions, but conditions (as in
Common Lisp, for example). One type of condition is an error or
"exception". Of course, if they were called conditions, then an actual
condition handling system would be required... instead of just
unwinding the stack willy nilly, thereby losing the ability to recover
and continue processing in many situations ;-)


> I'd be happy to hear of alternative designs, because I don't see
> this stuff as too engrained yet.

hasColor = schema.GetDimension("Red") || schema.GetDimension("Green")
           || schema.GetDimension("Blue");

or 

hasRgbColor = schema.GetDimension("Red") && schema.GetDimension("Green")
              && schema.GetDimension("Blue");


That requires GetDimension to return NULL or something that tests
FALSE on failure, and something that tests TRUE on success. If that is
possible, it means that you can avoid throwing an unexceptional
exception for possibly no good reason.

Even better would be to invent some syntax for using dimensions, but I
don't know if that's possible in C++, not being a C++ guru. In Lisp,
for instance, you might do something like:

(let ((hasColor (with-dimensions (r :red g :green b :blue) theSchema
                  (or r g b))))
  ;; Stuff using hasColor here
  )

or define a boolean method or function for it:

(defun has-rgb-color? (the-schema)
  (with-dimensions (r :red g :green b :blue) the-schema
    (and r g b)))

I'm not sure to what extent one can create syntax like this with C++
macros or template programming.

I personally prefer to avoid using exceptions for conditions that
commonly occur where they don't seem to add much value. But take that
with a grain of salt, since I don't use C++ day in, day out.

Regards,
David
Attention

Email Disclaimer Notice - This message is the property of AAM Pty Ltd. The information in this email is confidential and may be legally privileged.
It is intended solely for the
addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful.

If you have received this message in error please notify AAM Pty Ltd. immediately via email to mailadmin at aamgroup.com <mailto:mailadmin at aamgroup.com> 

This email has been scanned and cleared by NetIQ Mail Marshal, however AAM Pty Ltd does not guarantee this message free of viruses, or interference. 
________________________________


More information about the Liblas-devel mailing list