Hi all!
I have a class: -
class UserImpl : public POA_User
-
{
-
private :
-
typedef vector<GroupImpl*> Groups;
-
Groups groups;
-
-
public :
-
-
User::Groups* getGroups();
-
void setGroups(const ::User::Groups& g);
-
};
-
-
#endif
-
-
#include "UserImpl.h"
-
-
User::Groups* UserImpl::getGroups()
-
{
-
const size_t size = this->groups.size();
-
User::Groups_var seqOfObjects = new User::Groups(size);
-
seqOfObjects->length(size);
-
-
size_t i = 0;
-
vector<GroupImpl*>::const_iterator it = groups.begin();
-
while (it != groups.end())
-
{
-
seqOfObjects[i] = Group::_duplicate((*it)->_this());
-
++it;
-
++i;
-
}
-
-
return seqOfObjects._retn();
-
}
-
-
void UserImpl::setGroups(const ::User::Groups& g)
-
{
-
const size_t size = g.length();
-
this->groups.resize(size);
-
this->groups.clear();
-
-
for(size_t i = 0; i<size; i++)
-
{
-
GroupImpl *newGroup = new GroupImpl(g[i]->getID(), g[i]->getName(),
-
g[i]->getDescription(),g[i]->getFounder(),
-
*(g[i]->getUsers()));
-
this->groups.push_back(Groups::value_type(newGroup));
-
}
-
}
And I have some troubles how to write a getter and setter for my class field "groups". I did it, but I have dooubts
if it's a good way to do this. It compiles with no error but I'm a beginner in CORBA and would like get some help from anybody who is good at it. Thanks:)
3 2428
Generaly, getter and setter functions are not good programming practice. The idea behind the class is that the class member functions protect the data (which is private).
Therefore, if the data gets screwed up then it's the member functions that did it. Using a getter/setter means that any code anywhere in your program can mess things up.
You may as well skip classes altogether and use a global variable, itself a bad practice.
Aso, a vector manages its own memory so you don't have to be doing your own memoery alloctions using the new operator. Ny time you allocate memory, some one has to delete it. When you delete a pointer you need to know there are no other copies of it laying around otherwise you will crash your code. Knowing if you are deleting the only copy of the pointer involves another level to control and this usually brings you to using smart pointers.
I don't know what POA_User does but if you post it, that could shed some light on your design.
It's a small part of a bigger project. I can only say that I have a class which need to set groups. Class POA_User is a class generated by omniorb's IDL compiler, omniidl from User interface written in IDL language. It looks like this: - // This file is generated by omniidl (C++ backend)- omniORB_4_1. Do not edit.
-
#ifndef __User_hh__
-
#define __User_hh__
-
-
#ifndef __CORBA_H_EXTERNAL_GUARD__
-
#include <omniORB4/CORBA.h>
-
#endif
-
-
#ifndef USE_stub_in_nt_dll
-
# define USE_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
#ifndef USE_core_stub_in_nt_dll
-
# define USE_core_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
#ifndef USE_dyn_stub_in_nt_dll
-
# define USE_dyn_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
-
-
-
-
-
-
#ifdef USE_stub_in_nt_dll
-
# ifndef USE_core_stub_in_nt_dll
-
# define USE_core_stub_in_nt_dll
-
# endif
-
# ifndef USE_dyn_stub_in_nt_dll
-
# define USE_dyn_stub_in_nt_dll
-
# endif
-
#endif
-
-
#ifdef _core_attr
-
# error "A local CPP macro _core_attr has already been defined."
-
#else
-
# ifdef USE_core_stub_in_nt_dll
-
# define _core_attr _OMNIORB_NTDLL_IMPORT
-
# else
-
# define _core_attr
-
# endif
-
#endif
-
-
#ifdef _dyn_attr
-
# error "A local CPP macro _dyn_attr has already been defined."
-
#else
-
# ifdef USE_dyn_stub_in_nt_dll
-
# define _dyn_attr _OMNIORB_NTDLL_IMPORT
-
# else
-
# define _dyn_attr
-
# endif
-
#endif
-
-
-
-
-
-
#ifndef __Group__
-
#define __Group__
-
-
class Group;
-
class _objref_Group;
-
class _impl_Group;
-
-
typedef _objref_Group* Group_ptr;
-
typedef Group_ptr GroupRef;
-
-
class Group_Helper {
-
public:
-
typedef Group_ptr _ptr_type;
-
-
static _ptr_type _nil();
-
static _CORBA_Boolean is_nil(_ptr_type);
-
static void release(_ptr_type);
-
static void duplicate(_ptr_type);
-
static void marshalObjRef(_ptr_type, cdrStream&);
-
static _ptr_type unmarshalObjRef(cdrStream&);
-
};
-
-
typedef _CORBA_ObjRef_Var<_objref_Group, Group_Helper> Group_var;
-
typedef _CORBA_ObjRef_OUT_arg<_objref_Group,Group_Helper > Group_out;
-
-
#endif
-
-
#ifndef __User__
-
#define __User__
-
-
class User;
-
class _objref_User;
-
class _impl_User;
-
-
typedef _objref_User* User_ptr;
-
typedef User_ptr UserRef;
-
-
class User_Helper {
-
public:
-
typedef User_ptr _ptr_type;
-
-
static _ptr_type _nil();
-
static _CORBA_Boolean is_nil(_ptr_type);
-
static void release(_ptr_type);
-
static void duplicate(_ptr_type);
-
static void marshalObjRef(_ptr_type, cdrStream&);
-
static _ptr_type unmarshalObjRef(cdrStream&);
-
};
-
-
typedef _CORBA_ObjRef_Var<_objref_User, User_Helper> User_var;
-
typedef _CORBA_ObjRef_OUT_arg<_objref_User,User_Helper > User_out;
-
-
#endif
-
-
// interface User
-
class User {
-
public:
-
// Declarations for this interface type.
-
typedef User_ptr _ptr_type;
-
typedef User_var _var_type;
-
-
static _ptr_type _duplicate(_ptr_type);
-
static _ptr_type _narrow(::CORBA::Object_ptr);
-
static _ptr_type _unchecked_narrow(::CORBA::Object_ptr);
-
-
static _ptr_type _nil();
-
-
static inline void _marshalObjRef(_ptr_type, cdrStream&);
-
-
static inline _ptr_type _unmarshalObjRef(cdrStream& s) {
-
omniObjRef* o = omniObjRef::_unMarshal(_PD_repoId,s);
-
if (o)
-
return (_ptr_type) o->_ptrToObjRef(_PD_repoId);
-
else
-
return _nil();
-
}
-
-
static _core_attr const char* _PD_repoId;
-
-
// Other IDL defined within this scope.
-
class Groups_var;
-
-
class Groups : public _CORBA_Unbounded_Sequence_ObjRef< _objref_Group, _CORBA_ObjRef_Element< _objref_Group, Group_Helper> , Group_Helper > {
-
public:
-
typedef Groups_var _var_type;
-
inline Groups() {}
-
inline Groups(const Groups& _s)
-
: _CORBA_Unbounded_Sequence_ObjRef< _objref_Group, _CORBA_ObjRef_Element< _objref_Group, Group_Helper> , Group_Helper > (_s) {}
-
-
inline Groups(_CORBA_ULong _max)
-
: _CORBA_Unbounded_Sequence_ObjRef< _objref_Group, _CORBA_ObjRef_Element< _objref_Group, Group_Helper> , Group_Helper > (_max) {}
-
inline Groups(_CORBA_ULong _max, _CORBA_ULong _len, Group_ptr* _val, _CORBA_Boolean _rel=0)
-
: _CORBA_Unbounded_Sequence_ObjRef< _objref_Group, _CORBA_ObjRef_Element< _objref_Group, Group_Helper> , Group_Helper > (_max, _len, _val, _rel) {}
-
-
-
-
inline Groups& operator = (const Groups& _s) {
-
_CORBA_Unbounded_Sequence_ObjRef< _objref_Group, _CORBA_ObjRef_Element< _objref_Group, Group_Helper> , Group_Helper > ::operator=(_s);
-
return *this;
-
}
-
};
-
-
class Groups_out;
-
-
class Groups_var {
-
public:
-
inline Groups_var() : _pd_seq(0) {}
-
inline Groups_var(Groups* _s) : _pd_seq(_s) {}
-
inline Groups_var(const Groups_var& _s) {
-
if( _s._pd_seq ) _pd_seq = new Groups(*_s._pd_seq);
-
else _pd_seq = 0;
-
}
-
inline ~Groups_var() { if( _pd_seq ) delete _pd_seq; }
-
-
inline Groups_var& operator = (Groups* _s) {
-
if( _pd_seq ) delete _pd_seq;
-
_pd_seq = _s;
-
return *this;
-
}
-
inline Groups_var& operator = (const Groups_var& _s) {
-
if( _s._pd_seq ) {
-
if( !_pd_seq ) _pd_seq = new Groups;
-
*_pd_seq = *_s._pd_seq;
-
} else if( _pd_seq ) {
-
delete _pd_seq;
-
_pd_seq = 0;
-
}
-
return *this;
-
}
-
inline _CORBA_ObjRef_Element< _objref_Group, Group_Helper> operator [] (_CORBA_ULong _s) {
-
return (*_pd_seq)[_s];
-
}
-
-
-
-
inline Groups* operator -> () { return _pd_seq; }
-
inline const Groups* operator -> () const { return _pd_seq; }
-
#if defined(__GNUG__)
-
inline operator Groups& () const { return *_pd_seq; }
-
#else
-
inline operator const Groups& () const { return *_pd_seq; }
-
inline operator Groups& () { return *_pd_seq; }
-
#endif
-
-
inline const Groups& in() const { return *_pd_seq; }
-
inline Groups& inout() { return *_pd_seq; }
-
inline Groups*& out() {
-
if( _pd_seq ) { delete _pd_seq; _pd_seq = 0; }
-
return _pd_seq;
-
}
-
inline Groups* _retn() { Groups* tmp = _pd_seq; _pd_seq = 0; return tmp; }
-
-
friend class Groups_out;
-
-
private:
-
Groups* _pd_seq;
-
};
-
-
class Groups_out {
-
public:
-
inline Groups_out(Groups*& _s) : _data(_s) { _data = 0; }
-
inline Groups_out(Groups_var& _s)
-
: _data(_s._pd_seq) { _s = (Groups*) 0; }
-
inline Groups_out(const Groups_out& _s) : _data(_s._data) {}
-
inline Groups_out& operator = (const Groups_out& _s) {
-
_data = _s._data;
-
return *this;
-
}
-
inline Groups_out& operator = (Groups* _s) {
-
_data = _s;
-
return *this;
-
}
-
inline operator Groups*&() { return _data; }
-
inline Groups*& ptr() { return _data; }
-
inline Groups* operator->() { return _data; }
-
-
inline _CORBA_ObjRef_Element< _objref_Group, Group_Helper> operator [] (_CORBA_ULong _i) {
-
return (*_data)[_i];
-
}
-
-
-
-
Groups*& _data;
-
-
private:
-
Groups_out();
-
Groups_out& operator=(const Groups_var&);
-
};
-
-
-
};
-
-
class _objref_User :
-
public virtual ::CORBA::Object,
-
public virtual omniObjRef
-
{
-
public:
-
User::Groups* getGroups();
-
void setGroups(const ::User::Groups& g);
-
-
inline _objref_User() { _PR_setobj(0); } // nil
-
_objref_User(omniIOR*, omniIdentity*);
-
-
protected:
-
virtual ~_objref_User();
-
-
-
private:
-
virtual void* _ptrToObjRef(const char*);
-
-
_objref_User(const _objref_User&);
-
_objref_User& operator = (const _objref_User&);
-
// not implemented
-
-
friend class User;
-
};
-
-
class _pof_User : public _OMNI_NS(proxyObjectFactory) {
-
public:
-
inline _pof_User() : _OMNI_NS(proxyObjectFactory)(User::_PD_repoId) {}
-
virtual ~_pof_User();
-
-
virtual omniObjRef* newObjRef(omniIOR*,omniIdentity*);
-
virtual _CORBA_Boolean is_a(const char*) const;
-
};
-
-
class _impl_User :
-
public virtual omniServant
-
{
-
public:
-
virtual ~_impl_User();
-
-
-
virtual User::Groups* getGroups() = 0;
-
virtual void setGroups(const ::User::Groups& g) = 0;
-
-
public: // Really protected, workaround for xlC
-
virtual _CORBA_Boolean _dispatch(omniCallHandle&);
-
-
private:
-
virtual void* _ptrToInterface(const char*);
-
virtual const char* _mostDerivedRepoId();
-
-
};
-
-
-
-
-
class POA_User :
-
public virtual _impl_User,
-
public virtual ::PortableServer::ServantBase
-
{
-
public:
-
virtual ~POA_User();
-
-
inline ::User_ptr _this() {
-
return (::User_ptr) _do_this(::User::_PD_repoId);
-
}
-
};
-
-
-
-
-
-
-
-
#undef _core_attr
-
#undef _dyn_attr
-
-
-
-
inline void
-
User::_marshalObjRef(::User_ptr obj, cdrStream& s) {
-
omniObjRef::_marshal(obj->_PR_getobj(),s);
-
}
-
-
-
-
-
#ifdef USE_stub_in_nt_dll_NOT_DEFINED_User
-
# undef USE_stub_in_nt_dll
-
# undef USE_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
#ifdef USE_core_stub_in_nt_dll_NOT_DEFINED_User
-
# undef USE_core_stub_in_nt_dll
-
# undef USE_core_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
#ifdef USE_dyn_stub_in_nt_dll_NOT_DEFINED_User
-
# undef USE_dyn_stub_in_nt_dll
-
# undef USE_dyn_stub_in_nt_dll_NOT_DEFINED_User
-
#endif
-
-
#endif // __User_hh__
-
-
I have problems with implementation only a setter to the sequence and I'm not so sure if a getter is ok here.
Anybody?
I thougth to do it in a different way: - class UserImpl : public POA_User
-
{
-
User::Groups groups;
-
//..some other things
-
};
-
-
User::Groups* UserImpl::getGroups()
-
{
-
const size_t size = this->groups.length();
-
User::Groups_var seqOfObjects = new User::Groups(size);
-
seqOfObjects->length(size);
-
for(size_t i=0; i<size; i++)
-
{
-
seqOfObjects[i] = groups[i];
-
}
-
return seqOfObjects._retn();
-
}
-
-
void UserImpl::setGroups(const ::User::Groups& g)
-
{
-
const size_t size = g.length();
-
this->groups.length(size);
-
for(size_t i = 0; i<size; i++)
-
{
-
this->groups[i] = g[i];
-
}
-
}
Is that right?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kiwi |
last post by:
Hello.
I know a getter can return other thing than a field.
I know a setter can do more things than setting a field.
I know there are "setter only" cases and "getter only" cases.
I do use...
|
by: Krzysztof Opała |
last post by:
Hi
I've got my CORBA application written in Borland C++ Builder, using
Visibroker. What I wanna do is get from server a set of strings (the number
of string is not constant). I was trying to do it...
|
by: tshad |
last post by:
I have people telling me that I should set up objects for my tables, but I
am finding the Null problem makes that difficult.
It isn't a big problem if you are not updating the table, but if you...
|
by: Greg Scharlemann |
last post by:
For some reason, I am having trouble retrieving the data that I store
in the object that I have created from a database query. I created
this class Lead (see below). In the php page, I create and...
|
by: Michal Kwiatkowski |
last post by:
Hi,
Code below shows that property() works only if you use it within a class.
------------------------------------------------
class A(object):
pass
a = A()
a.y = 7
|
by: Steve |
last post by:
I generate C# webservices proxy code from WSDL file, it turns out the
classes
generated have public member variables and no getter/setter methods as
follows,
and I am able to get data when...
|
by: Hemant Shah |
last post by:
Folks,
How can I copy sequence objects from one database to another?
I have a script that exports data from one database and loads it into another.
Some of the columns in the database are...
|
by: kronrn |
last post by:
Hi Folks
Can anyone confirm that the code
public string Name
{
get;
set;
}
|
by: Softhideki |
last post by:
Good Day!!!
For alll
I have problem for create a script to copy a sequence of way automatic to copy a sequence of oracle database for other oracle database.
Anyone help me , how can...
|
by: nelsonbrodyk |
last post by:
Hey all,
Just curious, I want to make the "set" in a property obsolete, but not the get or the property. Is there a way to do this?
Public string FirstName {
get;
set;
}
works fine, but...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |