Results 1 to 4 of 4

Thread: slice2cpp does not support copy construct and operator =

  1. #1
    damingyipai is offline Registered User
    Join Date
    Jan 2004
    Posts
    59

    slice2cpp does not support copy construct and operator =

    the struct class class that was generated by slice2cpp does not support copy construct and operator =,
    maybe it too simple, but is important to me, because it's ISO standard.

    sample:

    slice:

    sequence< string > NameList;

    class FlatTree
    {
    string Id;
    string Type;
    string Name;
    NameList Parents;
    NameList Members;
    };

    the generated cpp code list bellow:

    class FlatTree : virtual public ::Ice::Object
    {
    public:

    void __copyMembers(::jf::server::FlatTreePtr) const;
    virtual ::Ice::ObjectPtr ice_clone() const;

    static const ::std::string __ids[2];
    virtual bool ice_isA(const ::std::string&, const ::Ice::Current& = ::Ice::Current()) const;
    virtual ::std::vector< ::std::string> ice_ids(const ::Ice::Current& = ::Ice::Current()) const;
    virtual const ::std::string& ice_id(const ::Ice::Current& = ::Ice::Current()) const;
    static const ::std::string& ice_staticId();

    ::std::string Id;

    ::std::string Type;

    ::std::string Name;

    ::NameList Parents;

    ::NameList Members;

    virtual void __write(::IceInternal::BasicStream*) const;
    virtual void __read(::IceInternal::BasicStream*, bool);
    virtual void __write(const ::Ice::OutputStreamPtr&) const;
    virtual void __read(const ::Ice::InputStreamPtr&, bool);

    static const ::Ice::ObjectFactoryPtr& ice_factory();

    private:

    static ::Ice::ObjectFactoryPtr _factory;
    };

    Now, I need copy a FlatTree object:

    FlatTreePtr o( new FlatTree() );
    ...
    FlatTree o2( * o ); // copy construct is not support
    FlatTree o2 = * o; // operator = is not support

    then, I must do this:

    FlatTreePtr o2( new FlatTree() );
    o->__copyMembers( o2 );

    It's feel not beautiful.

    I know, mostly I needn't call copy construct function, because the Ice::Handle can copy a object to anywhere, but now I really to do this. :-)

    Can slice2cpp support C++ copy construct and operator = ?

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    You should use ice_clone(). __copyMembers() is an internal function (everything in Ice that starts with underscores is internal). For example:

    FlatTreePtr o = FlatTree::dynamicCast(o2->ice_clone());

    However, off hand, I can't think of any reason why we cannot support the copy constructor or assignment operator for classes. Note that for structs, there are compiler-generated copy constructors and assignment operators.

  3. #3
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    As Marc says, for structures, the compiler-generated default copy constructor and assignment operator do the right thing.

    For classes, copy construction and assignment are deliberately disabled. (All classes ultimately derive from IceUtil::noncopyable, which hides the copy constructor and assignment operator -- see page 208 of the doc.) That's because class instances are reference counted and must be heap-allocated, and direct assignment and copy construction don't make sense. If you want to make a copy of a class, call ice_clone() and assign the return value to a smart pointer for the class. (See page 210 in the doc.)

    Cheers,

    Michi.

  4. #4
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Ice 2.2 will provide one-shot constructors for exceptions and classes, so you can initialize the data members in a single statement (instead of having to default-construct the instance and then assign each data member).

    Ice 2.2 will also provide copy constructor and assignment operator for classes, so you can assign classes to each other.

    Cheers,

    Michi.
    Last edited by michi; 06-17-2005 at 02:44 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Byte sequence zero copy with AMD in Ice 3.4x
    By lafayej in forum Help Center
    Replies: 1
    Last Post: 08-02-2010, 02:40 PM
  2. Large file copy example
    By pjtait in forum Help Center
    Replies: 2
    Last Post: 12-02-2009, 07:27 AM
  3. how can construct apache +ice +mysql?
    By karlwu in forum Help Center
    Replies: 4
    Last Post: 08-21-2008, 07:55 AM
  4. operator== of C++ classes
    By smu in forum Help Center
    Replies: 3
    Last Post: 06-21-2007, 06:08 PM
  5. Is serialization zero copy?
    By Markus Bernhard in forum Help Center
    Replies: 4
    Last Post: 06-14-2006, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •