You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Ned Rockson <nr...@stanford.edu> on 2008/01/09 21:04:12 UTC
Problem with autogenerated C++ Records using bin/rcc
Recently I've been trying to autogenerate some data structures that
will work for both C++ and Java. I've made many that work with Java,
but every time I try to generate one for C++ the generator breaks
down. For instance, I was trying to create a Text class for C++, so I
created a text.jr:
module io {
class Text {
ustring text;
}
}
that in Java works fine, but in C++, this is generated (implementation
is fine for the methods defined):
#ifndef __TEXT_DDL__
#define __TEXT_DDL__
#include "recordio.hh"
namespace io {
class Text : public ::hadoop::Record {
private:
::std::string text;
public:
virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;
virtual void deserialize(::hadoop::IArchive& a_, const char* tag);
virtual const ::std::string& type() const;
virtual const ::std::string& signature() const;
virtual bool operator<(const Text& peer_) const;
virtual bool operator==(const Text& peer_) const;
virtual ~Text() {};
virtual const ::std::string& getText() const {
return text;
}
virtual ::std::string& getText() {
return text;
}
}; // end record Text
} // end namespace io
#endif //TEXT_DDL__
What is obviously missing is
-a constructor,
-a setter (there are getters for const and non-const...)
This is with hadoop-0.15.1 and I've also tried following the examples
given in the API to no luck. Thanks for any feedback!
Re: Problem with autogenerated C++ Records using bin/rcc
Posted by Ned Rockson <nr...@stanford.edu>.
Okay, that makes sense. It seems strange to return a reference to a
string object that's not const. Doesn't this break some C++ coding
standards? It seems it should return a pointer or have a set method
to maintain symmetry between the two languages. The counter argument,
of course, is that it's easier to not have a set method and return
some form of reference (be it reference or pointer).
Thanks for the response!
Ned
On Jan 10, 2008 8:25 PM, Vivek Ratan <vi...@yahoo-inc.com> wrote:
> Hi Ned.
>
> The generated C++ class does not have an explicit constructor, as you've
> pointed out. This is by design. the fields in the DDL class definition
> become private members of the C++ class. It is expected that you assign
> values to each one of them separately, rather than through a constructor.
> There are explicit setters for basic types such as bools or ints. However,
> for strings, you get a reference to the private string member variable
> (using a getter) and then set it. So, in your example, you could do
> something like this:
>
> Text t = new Text();
> t.getText().assign("whatever value you want"); // assign a value to the
> 'text' field
>
> Suppose your class Text had an additional bool parameter:
> module io {
> class Text {
> ustring text;
> boolean b;
> }
> }
>
> There'd be a setter for 'b' in the generated C++ class, and you'd do
> something like:
> Text t = new Text();
> t.setB(true);
>
> It's only for the more complex types (strings, maps, vectors) that you don't
> have explicit setters. You use a getter to get a reference object to the
> member variable, then assign values to it.
>
> AFAIK, the C++ generated classes are not broken. They're a bit different
> from the Java classes, which have setters for each field (and you could
> discus whether the C++ and Java classes should look more like each other),
> but they work.
>
>
> -----Original Message-----
> From: nedrocks@gmail.com [mailto:nedrocks@gmail.com] On Behalf Of Ned
> Rockson
> Sent: Thursday, January 10, 2008 1:34 AM
> To: hadoop-user@lucene.apache.org
> Subject: Problem with autogenerated C++ Records using bin/rcc
>
> Recently I've been trying to autogenerate some data structures that will
> work for both C++ and Java. I've made many that work with Java, but every
> time I try to generate one for C++ the generator breaks down. For instance,
> I was trying to create a Text class for C++, so I created a text.jr:
>
> module io {
> class Text {
> ustring text;
> }
> }
>
> that in Java works fine, but in C++, this is generated (implementation is
> fine for the methods defined):
>
> #ifndef __TEXT_DDL__
> #define __TEXT_DDL__
> #include "recordio.hh"
> namespace io {
> class Text : public ::hadoop::Record {
> private:
> ::std::string text;
> public:
> virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;
> virtual void deserialize(::hadoop::IArchive& a_, const char* tag);
> virtual const ::std::string& type() const;
> virtual const ::std::string& signature() const;
> virtual bool operator<(const Text& peer_) const;
> virtual bool operator==(const Text& peer_) const;
> virtual ~Text() {};
> virtual const ::std::string& getText() const {
> return text;
> }
> virtual ::std::string& getText() {
> return text;
> }
> }; // end record Text
> } // end namespace io
> #endif //TEXT_DDL__
>
> What is obviously missing is
> -a constructor,
> -a setter (there are getters for const and non-const...)
>
> This is with hadoop-0.15.1 and I've also tried following the examples given
> in the API to no luck. Thanks for any feedback!
>
>
RE: Problem with autogenerated C++ Records using bin/rcc
Posted by Vivek Ratan <vi...@yahoo-inc.com>.
Hi Ned.
The generated C++ class does not have an explicit constructor, as you've
pointed out. This is by design. the fields in the DDL class definition
become private members of the C++ class. It is expected that you assign
values to each one of them separately, rather than through a constructor.
There are explicit setters for basic types such as bools or ints. However,
for strings, you get a reference to the private string member variable
(using a getter) and then set it. So, in your example, you could do
something like this:
Text t = new Text();
t.getText().assign("whatever value you want"); // assign a value to the
'text' field
Suppose your class Text had an additional bool parameter:
module io {
class Text {
ustring text;
boolean b;
}
}
There'd be a setter for 'b' in the generated C++ class, and you'd do
something like:
Text t = new Text();
t.setB(true);
It's only for the more complex types (strings, maps, vectors) that you don't
have explicit setters. You use a getter to get a reference object to the
member variable, then assign values to it.
AFAIK, the C++ generated classes are not broken. They're a bit different
from the Java classes, which have setters for each field (and you could
discus whether the C++ and Java classes should look more like each other),
but they work.
-----Original Message-----
From: nedrocks@gmail.com [mailto:nedrocks@gmail.com] On Behalf Of Ned
Rockson
Sent: Thursday, January 10, 2008 1:34 AM
To: hadoop-user@lucene.apache.org
Subject: Problem with autogenerated C++ Records using bin/rcc
Recently I've been trying to autogenerate some data structures that will
work for both C++ and Java. I've made many that work with Java, but every
time I try to generate one for C++ the generator breaks down. For instance,
I was trying to create a Text class for C++, so I created a text.jr:
module io {
class Text {
ustring text;
}
}
that in Java works fine, but in C++, this is generated (implementation is
fine for the methods defined):
#ifndef __TEXT_DDL__
#define __TEXT_DDL__
#include "recordio.hh"
namespace io {
class Text : public ::hadoop::Record {
private:
::std::string text;
public:
virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;
virtual void deserialize(::hadoop::IArchive& a_, const char* tag);
virtual const ::std::string& type() const;
virtual const ::std::string& signature() const;
virtual bool operator<(const Text& peer_) const;
virtual bool operator==(const Text& peer_) const;
virtual ~Text() {};
virtual const ::std::string& getText() const {
return text;
}
virtual ::std::string& getText() {
return text;
}
}; // end record Text
} // end namespace io
#endif //TEXT_DDL__
What is obviously missing is
-a constructor,
-a setter (there are getters for const and non-const...)
This is with hadoop-0.15.1 and I've also tried following the examples given
in the API to no luck. Thanks for any feedback!