471,066 Members | 1,183 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Many Text Relocations In Shared Object

I have a Shared Object which its sole purpose is to create objects of
a certain type and return a pointer to the object to the user.
Therefore, the user becomes the owner of this object and is resposible
for deleting it. It utilizes the factory pattern to create the
objects. The problem is that I am finding it nearly impossible to get
rid of my Text Relocations. I'm using the -Kpic and -ztext options
(which, of course, makes my link-edit fail). Here's the code:

MsgFactory.h

namespace MDS
{
class Message;
}

// Message factory interface
class MsgFactory
{
public:

MsgFactory() {};

virtual ~MsgFactory() {};

virtual MDS::Message* getNewMsg() = 0;

private:
};
// Actual message factory implementation
template< typename MSG_TYPE >
class MsgFactoryImpl : public MsgFactory
{

public:

//! MsgFactoryImpl constructs the actual message factory and
adds itself to the MsgFactoryTable
/*!
\param cId unsigned char that identifies the message's id
*/
MsgFactoryImpl( unsigned char cId )
{
MsgFactoryTable::getInstance().addMsgFactory( cId, this );
};
virtual ~MsgFactoryImpl() {}; /*!< DESTRUCTOR */
//! getNewMessage creates a message of the templated type
/*!
\returns Message* to the new empty message
*/
MDS::Message *getNewMsg()
{
// create and return the new Message*
MSG_TYPE *pMsg = new MSG_TYPE;

return pMsg;
}

private:

};

// Table of MsgFactory pointers - keeps a map of global Message
Factories
// MsgFactoryTable is a singleton
class MsgFactoryTable
{
public:

//! getInstance gets the single object
/*!
\returns MsgFactoryTable&
*/
//static MsgFactoryTable & getInstance();
//! getMsgFactory retrieves an actual Message Factory
/*!
\param msgType unsigned char that identifies the message factory's id
\returns MsgFactory* to the actual MsgFactoryImpl
*/
MsgFactory * getMsgFactory( unsigned char msgType ) const
{
std::map< unsigned char, MsgFactory * >::const_iterator it;

it = m_mapMsgFactories.find( msgType );

if ( it != m_mapMsgFactories.end() )
{
// return the message factory
return it -> second;
}
else
{
return NULL;
}
}
//! addMsgFactory adds a factory to the map
/*!
\param msgType unsigned char that that identifies the message
factory's id
\param pMsgFactory MsgFactory* that points to the actual message
factory
*/
void addMsgFactory( unsigned char msgType, MsgFactory *
pMsgFactory )
{
// add the factory to the map
m_mapMsgFactories[ msgType ] = pMsgFactory;
}

protected:

MsgFactoryTable() {}

private:

std::map< unsigned char, MsgFactory * > m_mapMsgFactories; /*!<
map to store the MsgFactory objects in */

};

//} // namespace MDS

#endif /* MDSMsgFactory_H_ */

-------------------

MsgFactory.cpp

namespace MDS
{
class Message;
}

// Message factory interface
class MsgFactory
{
public:

MsgFactory() {};

virtual ~MsgFactory() {};

virtual MDS::Message* getNewMsg() = 0;

private:
};
// Actual message factory implementation
template< typename MSG_TYPE >
class MsgFactoryImpl : public MsgFactory
{

public:

//! MsgFactoryImpl constructs the actual message factory and
adds itself to the MsgFactoryTable
/*!
\param cId unsigned char that identifies the message's id
*/
MsgFactoryImpl( unsigned char cId )
{
//std::cout << "Creating Factory with ID" << cId << std::endl;
//MsgFactoryTable oTable = MsgFactoryTable::getInstance();

//MsgFactoryTable::getInstance().addMsgFactory( cId, this );
};
virtual ~MsgFactoryImpl() {}; /*!< DESTRUCTOR */
//! getNewMessage creates a message of the templated type
/*!
\returns Message* to the new empty message
*/
MDS::Message *getNewMsg()
{
// create and return the new Message*
MSG_TYPE *pMsg = new MSG_TYPE;

return pMsg;
}

private:

};

// Table of MsgFactory pointers - keeps a map of global Message
Factories
// MsgFactoryTable is a singleton
class MsgFactoryTable
{
public:

//! getInstance gets the single object
/*!
\returns MsgFactoryTable&
*/
//static MsgFactoryTable & getInstance();
//! getMsgFactory retrieves an actual Message Factory
/*!
\param msgType unsigned char that identifies the message factory's id
\returns MsgFactory* to the actual MsgFactoryImpl
*/
MsgFactory * getMsgFactory( unsigned char msgType ) const
{
std::map< unsigned char, MsgFactory * >::const_iterator it;

it = m_mapMsgFactories.find( msgType );

if ( it != m_mapMsgFactories.end() )
{
// return the message factory
return it -> second;
}
else
{
return NULL;
}
}
//! addMsgFactory adds a factory to the map
/*!
\param msgType unsigned char that that identifies the message
factory's id
\param pMsgFactory MsgFactory* that points to the actual message
factory
*/
void addMsgFactory( unsigned char msgType, MsgFactory *
pMsgFactory )
{
// add the factory to the map
m_mapMsgFactories[ msgType ] = pMsgFactory;
}

protected:

MsgFactoryTable() {}

private:

std::map< unsigned char, MsgFactory * > m_mapMsgFactories; /*!<
map to store the MsgFactory objects in */

};

//} // namespace MDS

#endif /* MDSMsgFactory_H_ */

-----------

IterMapFactory.cpp

#include "MsgFactory.h"
#include "IterMap.h"

namespace MDS
{
// create the global message factory
MsgFactoryImpl< IterMap > g_IterMapFactory( IterMap::PROTOCOL );
}

------------

If I get rid of the MsgFactoryImpl instance in IterMapFactory.cxx then
all of my text relocations go away altogether. If I leave that line in
and comment out the getNewMsg function in the MsgFactory and
MsgFactoryImpl classes in MsgFactory.h then I get only a few text
relocations.

I thoroughly appreciate any help I can get.
Jul 22 '05 #1
1 1525

"Gregg Altschul" <ga*******@factset.com> wrote in message
news:2c*************************@posting.google.co m...
I have a Shared Object which its sole purpose is to create objects of
a certain type and return a pointer to the object to the user.
Therefore, the user becomes the owner of this object and is resposible
for deleting it. It utilizes the factory pattern to create the
objects. The problem is that I am finding it nearly impossible to get
rid of my Text Relocations. I'm using the -Kpic and -ztext options
(which, of course, makes my link-edit fail). Here's the code:


Perhaps others understand what you mean, but...what's a "Text Relocation"?

-Howard
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Srijit Kumar Bhadra | last post: by
6 posts views Thread by pankaj.khandelwal | last post: by
2 posts views Thread by tshad | last post: by
10 posts views Thread by One Handed Man [ OHM ] | last post: by
13 posts views Thread by Nak | last post: by
4 posts views Thread by Jan Nielsen | last post: by
4 posts views Thread by Ken Soenen | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.