Many Text Relocations In Shared Object

G

Gregg Altschul

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.
 
H

Howard

Gregg Altschul said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top