OK, there is no problem to keep it as an exception. But it would be easier
to code if it wasn't. I agree with leave it as an exception to explicity to
mean that it's an EXCEPTION.
I'm actually coding from DAS Java to DAS c++ and there is one part of the
code that requires to check if exists a property with a specified name. But
I can handle it with exception anyway ; ) Thanks
Adriano Crestani
On 1/11/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
Just one more thought. It comes down to how often you think the property
will not be found. returning a pointer (or even a re counting ptr object)
requires the user to ALWAYS code an if (xxx) following the getProperty.
This
is why the API is as it is today so that the "normal" use case is simple
for
the user.
I'd like to understand the use case where we are trying to do
Type::getProperty("propname") where you are not expecting propname to be a
property.
Cheers,
On 11/01/07, Yang ZHONG <[EMAIL PROTECTED]> wrote:
>
> Agree, neither Property* nor Property& tracks references.
>
> On 1/11/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> >
> > Maybe the best solution would be to return a PropertyPtr (we do not
like
> > returning raw pointers to our internal data so this is better than
> > Property*
> > ... avoids lifetime of the Pointee problems):
> >
> >
> > PropertyPtr x = myType->getProperty("ID");
> > if (x)
> > {
> >
> > x->what_ever_it_is_you_want_to_do_with_the_property??
> >
> > }
> >
> >
> >
> > On 11/01/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> >
> > > The reason getProperty throws an exception is that it's a
exceptional
> > > condition ;-)
> > > The expectation is that you KNOW the names of the properties on the
> SDO
> > > that you are dealing with. If not, then you would use
getPropertyList
> or
> > > getInstanceProperties and iterate over the list.
> > >
> > > I'm assuming in your case that ALL your DO's are expected to have a
> > > particular property (ID)??. In which case isn't it an error if they
> > don't =
> > > exception?
> > >
> > >
> > >
> > > On 11/01/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> > > >
> > > > I think it wouldn't be a good idea, because if you want to check
if
> > > > there is
> > > > a property with the specified name using hasProperty method and
> later
> > to
> > > > get
> > > > the property with getProperty(string) it would look for the
property
> > > > name
> > > > twice in the property list, for example:
> > > >
> > > > if (hasProperty("ID")) { // look on the list here
> > > > const Property& t = getProperty("ID"); // and here
> > > > }
> > > >
> > > > The best way should be:
> > > >
> > > > int propertyIndex = getPropertyIndex("ID");
> > > >
> > > > if (propertyIndex != -1) { // if it hasn't been found
> > > > const Property& t = getProperty(propertyIndex); // and here to
get
> > the
> > > >
> > > > Property directly
> > > > }
> > > >
> > > > However, if the method getPropertyIndex(string) doesn't find any
> > > > property
> > > > with the specified name it also throws a
> SDOPropertyNotFoundException.
> > I
> > > > think we could purpose not a bool
> > > > Type::hasProperty(std::string propertyName) method, but a int
> > > > Type::getPropertyIndex(string) that returns a -1 value if the
> property
> > > > name
> > > > is not found, instead of an exception.
> > > >
> > > > Another question, where do I find the sdo spec?
> > > >
> > > > Adriano Crestani
> > >
> > >
> > > http://osoa.org/display/Main/Service+Data+Objects+Specifications
> > >
> > > On 1/11/07, Pete Robbins <[EMAIL PROTECTED] > wrote:
> > > > >
> > > > > On 11/01/07, Adriano Crestani < [EMAIL PROTECTED]>
wrote:
> > > > > >
> > > > > > Thanks Pete, I thought there would be an easier way to do
this.
> > But
> > > > if
> > > > > you
> > > > > > say so, I think it's the only way. Thanks again!
> > > > >
> > > > >
> > > > > That is what is in the spec. Maybe we could propose a bool
> > > > > Type::hasProperty(std::string propertyName); method
> > > > >
> > > > > Cheers,
> > > > >
> > > > > Adriano Crestani
> > > > > >
> > > > > > On 1/10/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> > > > > > >
> > > > > > > On 10/01/07, Adriano Crestani < [EMAIL PROTECTED]>
> > wrote:
> > > > > > > >
> > > > > > > > I'm begginer with C++ and I have one doubt about the
> function
> > > > > defined
> > > > > > in
> > > > > > > > Type.h: "virtual SDO_API const Property& getProperty(const
> > char*
> > > > > > > > propertyName) const = 0". It's supposed to return a
> reference
> > > > to a
> > > > > > > > Property
> > > > > > > > object that has the name equal to the parameter
> propertyName,
> > > > but if
> > > > > > > there
> > > > > > > > is no Property object with this name? What does this
> function
> > > > > return?
> > > > > > >
> > > > > > >
> > > > > > > It would through a SDOPropertyNotFoundException.
> > > > > > >
> > > > > > > I tried to do this...
> > > > > > > >
> > > > > > > > if (type.getProperty ("ID") == NULL)
> > > > > > > >
> > > > > > > > ...but as long as far as I know it's not possible. Is
there
> a
> > > > way to
> > > > >
> > > > > > > check
> > > > > > > > if the function has found Property object with the
specified
> > > > name or
> > > > > > > not.
> > > > > > > >
> > > > > > > > Adriano Crestani
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > There is no easy way to do this. You would need to wrap the
> > > > > getProperty
> > > > > > in
> > > > > > > a
> > > > > > > try/catch block.
> > > > > > >
> > > > > > > Cheers,
> > > > > > >
> > > > > > > --
> > > > > > > Pete
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Pete
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Pete
> >
> >
> >
> >
> > --
> > Pete
> >
> >
>
>
> --
>
> Yang ZHONG
>
>
--
Pete