Sekwencja obiektów w CORBie - jak ją zaimplementować

0

User.idl:

#ifndef __USER_IDL__
#define __USER_IDL__

interface Group;

interface User
{
    typedef sequence<Group> Groups;
    Groups getGroups();
    void setGroups(in Groups g);
};

#endif

UserImpl.h and UserImpl.cpp:

class UserImpl : public POA_User
{
    private :
        User::Groups groups;
    public :

        User::Groups* getGroups();
        void setGroups(const ::User::Groups& g);
};

#endif

#include "UserImpl.h"

User::Groups* UserImpl::getGroups()
{
    return &(this->groups);
}

void UserImpl::setGroups(const ::User::Groups& g)
{
    this->groups.length(g.length());
    for(int i=0; i<g.length(); i++)
    {
        this->groups[i] = this->groups[i];
    }
}

Group.idl:

#ifndef __GROUP_IDL__
#define __GROUP_IDL__

#include "User.idl"

interface Group
{
    typedef sequence<User> Users;
    User getFounder();
    void setFounder(in User u);
    Users getUsers();
    void setUsers(in Users u);
};

#endif

GroupImpl.h, GroupImpl.cpp:

class UserImpl;

class GroupImpl : public POA_Group
{
    private :

        UserImpl *founder;
        Group::Users members;            

    public :

        User_ptr getFounder();
        void setFounder(::User_ptr u);
        Group::Users* getUsers();
        void setUsers(const ::Group::Users& u);
};

User_ptr GroupImpl::getFounder()
{
    return this->founder->_this();
}

void GroupImpl::setFounder(::User_ptr u)
{

}

Group::Users* GroupImpl::getUsers()
{

}

void GroupImpl::setUsers(const ::Group::Users& u)
{

}

**Mam taki kod - nie jestem jednak pewien, czy dobrze rozwiązałem kwestię sekwencji + jak przypisać w zwrócić (napisać treść metod get i set dla members i founder, aby móc w mainie zrobić tak, jak poniżej? **

#include "UserImpl.h"
#include "GroupImpl.h"
#include <omniORB4/CORBA.h>
#include <omniORB4/Naming.hh>
#include <iostream>
using std::cout;
using std::cerr;

int main(int argc, char **argv)
{
    UserImpl u;
    u.setLogin("yak");
    u.setID(123);
    cout << u.getLogin() << "\n";
    cout << u.getID() << "\n";
    cout << u.toString() << "\n";


    GroupImpl **g = new GroupImpl*[1];
    for(int i=0; i<1; i++)
    {
        g[i] = new GroupImpl();
    }

    u.setGroups(g);

    return 0;
}
0

ok, w sumie potrzebuję już tylko pomocy w napisaniu settera, na razie mam to:

void UserImpl::setGroups(const ::User::Groups& g)
{
    const size_t size = g.length();
    this->groups.resize(size);

    for(size_t i = 0; i<size; i++)
    {
        this->groups.push_back(Group::value_type(g[i]->getID(), g[i]->getName()));
    }
}

i takie błędy:

UserImpl.cpp: In member function ‘virtual void UserImpl::setGroups(const User::Groups&)’: UserImpl.cpp32: error: ‘value_type’ is not a member of ‘Group’

1 użytkowników online, w tym zalogowanych: 0, gości: 1