Skip to content

Commit

Permalink
Store data dictionaries in shared_ptr so we don't have to worry about…
Browse files Browse the repository at this point in the history
… cleanup
  • Loading branch information
orenmnero committed Sep 12, 2014
1 parent 577b9f2 commit 194c1ba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/C++/DataDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ DataDictionary::~DataDictionary()
FieldPresenceMap::const_iterator iter = presenceMap.begin();
for ( ; iter != presenceMap.end(); ++iter )
delete iter->second.second;
}
}
}

DataDictionary& DataDictionary::operator=( const DataDictionary& rhs )
Expand Down
8 changes: 4 additions & 4 deletions src/C++/DataDictionaryProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DataDictionaryProvider::DataDictionaryProvider( const DataDictionaryProvider& co
const DataDictionary& DataDictionaryProvider::getSessionDataDictionary
(const BeginString& beginString) const throw( DataDictionaryNotFound )
{
std::map<std::string, const DataDictionary*>::const_iterator find =
std::map<std::string, std::shared_ptr<DataDictionary> >::const_iterator find =
m_transportDictionaries.find(beginString);
if( find != m_transportDictionaries.end() )
return *find->second;
Expand All @@ -48,7 +48,7 @@ const DataDictionary& DataDictionaryProvider::getSessionDataDictionary
const DataDictionary& DataDictionaryProvider::getApplicationDataDictionary
(const ApplVerID& applVerID) const throw( DataDictionaryNotFound )
{
std::map<std::string, const DataDictionary*>::const_iterator find =
std::map<std::string, std::shared_ptr<DataDictionary> >::const_iterator find =
m_applicationDictionaries.find(applVerID);
if( find != m_applicationDictionaries.end() )
return *find->second;
Expand All @@ -57,13 +57,13 @@ const DataDictionary& DataDictionaryProvider::getApplicationDataDictionary
}

void DataDictionaryProvider::addTransportDataDictionary
(const BeginString& beginString, const DataDictionary * pDD)
(const BeginString& beginString, std::shared_ptr<DataDictionary> pDD)
{
m_transportDictionaries[beginString.getValue()] = pDD;
}

void DataDictionaryProvider::addApplicationDataDictionary
(const ApplVerID& applVerID, const DataDictionary * pDD)
(const ApplVerID& applVerID, std::shared_ptr<DataDictionary> pDD)
{
m_applicationDictionaries[applVerID.getValue()] = pDD;
}
Expand Down
13 changes: 9 additions & 4 deletions src/C++/DataDictionaryProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ class DataDictionaryProvider
const DataDictionary& getApplicationDataDictionary(const ApplVerID& applVerID) const
throw( DataDictionaryNotFound );

void addTransportDataDictionary(const BeginString& beginString, const DataDictionary*);
void addApplicationDataDictionary(const ApplVerID& applVerID, const DataDictionary*);
void addTransportDataDictionary(const BeginString& beginString, std::shared_ptr<DataDictionary>);
void addApplicationDataDictionary(const ApplVerID& applVerID, std::shared_ptr<DataDictionary>);

void addTransportDataDictionary(const BeginString& beginString, const std::string& path)
{ addTransportDataDictionary(beginString, std::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
void addApplicationDataDictionary(const ApplVerID& applVerID, const std::string& path)
{ addApplicationDataDictionary(applVerID, std::shared_ptr<DataDictionary>( new DataDictionary(path) )); }

private:
std::map<std::string, const DataDictionary*> m_transportDictionaries;
std::map<std::string, const DataDictionary*> m_applicationDictionaries;
std::map<std::string, std::shared_ptr<DataDictionary> > m_transportDictionaries;
std::map<std::string, std::shared_ptr<DataDictionary> > m_applicationDictionaries;
DataDictionary emptyDataDictionary;
};
}
Expand Down
26 changes: 11 additions & 15 deletions src/C++/SessionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ namespace FIX
{
SessionFactory::~SessionFactory()
{
Dictionaries::iterator i = m_dictionaries.begin();
for ( ; i != m_dictionaries.end(); ++i )
delete *i;
}

Session* SessionFactory::create( const SessionID& sessionID,
Expand Down Expand Up @@ -206,25 +203,24 @@ void SessionFactory::destroy( Session* pSession )
delete pSession;
}

const DataDictionary * SessionFactory::createDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
const std::string& settingsKey) throw(ConfigError)
std::shared_ptr<DataDictionary> SessionFactory::createDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
const std::string& settingsKey) throw(ConfigError)
{
DataDictionary * pDD = 0;
std::shared_ptr<DataDictionary> pDD;
std::string path = settings.getString( settingsKey );
PathToDictionary::iterator i = m_pathToDictionary.find( path );
if ( i != m_pathToDictionary.end() )
Dictionaries::iterator i = m_dictionaries.find( path );
if ( i != m_dictionaries.end() )
{
pDD = i->second;
}
else
{
pDD = new DataDictionary( path );
m_pathToDictionary[ path ] = pDD;
pDD = std::shared_ptr<DataDictionary>(new DataDictionary( path ));
m_dictionaries[ path ] = pDD;
}

DataDictionary * pCopyOfDD = new DataDictionary(*pDD);
m_dictionaries.push_back(pCopyOfDD);
std::shared_ptr<DataDictionary> pCopyOfDD = std::shared_ptr<DataDictionary>(new DataDictionary(*pDD));

if( settings.has( VALIDATE_FIELDS_OUT_OF_ORDER ) )
pCopyOfDD->checkFieldsOutOfOrder( settings.getBool( VALIDATE_FIELDS_OUT_OF_ORDER ) );
Expand All @@ -240,7 +236,7 @@ void SessionFactory::processFixtDataDictionaries(const SessionID& sessionID,
const Dictionary& settings,
DataDictionaryProvider& provider) throw(ConfigError)
{
const DataDictionary * pDataDictionary = createDataDictionary(sessionID, settings, TRANSPORT_DATA_DICTIONARY);
std::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, TRANSPORT_DATA_DICTIONARY);
provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);

for(Dictionary::const_iterator data = settings.begin(); data != settings.end(); ++data)
Expand Down Expand Up @@ -271,7 +267,7 @@ void SessionFactory::processFixDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
DataDictionaryProvider& provider) throw(ConfigError)
{
const DataDictionary * pDataDictionary = createDataDictionary(sessionID, settings, DATA_DICTIONARY);
std::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, DATA_DICTIONARY);
provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
provider.addApplicationDataDictionary(Message::toApplVerID(sessionID.getBeginString()), pDataDictionary);
}
Expand Down
10 changes: 4 additions & 6 deletions src/C++/SessionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ class SessionFactory
void destroy( Session* pSession );

private:
typedef std::map < std::string, DataDictionary* > PathToDictionary;
typedef std::vector<DataDictionary*> Dictionaries;
typedef std::map < std::string, std::shared_ptr<DataDictionary> > Dictionaries;

const DataDictionary * createDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
const std::string& settingsKey) throw(ConfigError);
std::shared_ptr<DataDictionary> createDataDictionary(const SessionID& sessionID,
const Dictionary& settings,
const std::string& settingsKey) throw(ConfigError);

void processFixtDataDictionaries(const SessionID& sessionID,
const Dictionary& settings,
Expand All @@ -80,7 +79,6 @@ class SessionFactory
Application& m_application;
MessageStoreFactory& m_messageStoreFactory;
LogFactory* m_pLogFactory;
PathToDictionary m_pathToDictionary;
Dictionaries m_dictionaries;
};
}
Expand Down
16 changes: 8 additions & 8 deletions src/C++/test/SessionTestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ struct sessionFixture : public TestCallback
TimeRange sessionTime( startTime, endTime );

DataDictionaryProvider provider;
provider.addTransportDataDictionary( sessionID.getBeginString(), new DataDictionary("../spec/FIX42.xml") );
provider.addTransportDataDictionary( sessionID.getBeginString(), "../spec/FIX42.xml" );
object = new Session( *this, factory, sessionID, provider,
sessionTime, heartBtInt, 0 );
object->setResponder( this );
Expand Down Expand Up @@ -391,9 +391,9 @@ struct sessionT11Fixture : public TestCallback
TimeRange sessionTime( startTime, endTime );

DataDictionaryProvider provider;
provider.addTransportDataDictionary( sessionID.getBeginString(), new DataDictionary("../spec/FIXT11.xml") );
provider.addApplicationDataDictionary( ApplVerID(ApplVerID_FIX50), new DataDictionary("../spec/FIX50.xml") );
provider.addApplicationDataDictionary( ApplVerID(ApplVerID_FIX42), new DataDictionary("../spec/FIX42.xml") );
provider.addTransportDataDictionary( sessionID.getBeginString(), "../spec/FIXT11.xml" );
provider.addApplicationDataDictionary( ApplVerID(ApplVerID_FIX50), "../spec/FIX50.xml" );
provider.addApplicationDataDictionary( ApplVerID(ApplVerID_FIX42), "../spec/FIX42.xml" );
object = new Session( *this, factory, sessionID, provider,
sessionTime, heartBtInt, 0 );
object->setSenderDefaultApplVerID( FIX::Message::toApplVerID(BeginString("FIX.5.0")) );
Expand Down Expand Up @@ -615,7 +615,7 @@ TEST_FIXTURE(acceptorFixture, callDisconnect)
TEST_FIXTURE(sessionFixture, doesSessionExist)
{
DataDictionaryProvider provider;
provider.addTransportDataDictionary( BeginString("FIX.4.2"), new DataDictionary() );
provider.addTransportDataDictionary( BeginString("FIX.4.2"), std::shared_ptr<DataDictionary>(new DataDictionary()) );

Session * pSession1 = new Session
( *this, factory, SessionID( BeginString( "FIX.4.2" ),
Expand Down Expand Up @@ -686,7 +686,7 @@ TEST_FIXTURE(sessionFixture, doesSessionExist)
TEST_FIXTURE(sessionFixture, lookupSession)
{
DataDictionaryProvider provider;
provider.addTransportDataDictionary( BeginString("FIX.4.2"), new DataDictionary() );
provider.addTransportDataDictionary( BeginString("FIX.4.2"), std::shared_ptr<DataDictionary>(new DataDictionary()) );

Session* pSession1 = new Session
( *this, factory, SessionID( BeginString( "FIX.4.2" ),
Expand Down Expand Up @@ -741,7 +741,7 @@ TEST_FIXTURE(sessionFixture, lookupSession)
TEST_FIXTURE(sessionFixture, registerSession)
{
DataDictionaryProvider provider;
provider.addTransportDataDictionary( BeginString("FIX.4.2"), new DataDictionary() );
provider.addTransportDataDictionary( BeginString("FIX.4.2"), std::shared_ptr<DataDictionary>(new DataDictionary()) );

Session* pSession = new Session
( *this, factory, SessionID( BeginString( "FIX.4.2" ),
Expand Down Expand Up @@ -1355,7 +1355,7 @@ struct initiatorCreatedBeforeStartTimeFixture : public TestCallback
SessionID sessionID( BeginString( "FIX.4.2" ), SenderCompID( "MJKG" ), TargetCompID( "IZZY" ) );

DataDictionaryProvider provider;
provider.addTransportDataDictionary( sessionID.getBeginString(), new DataDictionary("../spec/FIX42.xml") );
provider.addTransportDataDictionary( sessionID.getBeginString(), "../spec/FIX42.xml" );
object = new Session( *this, memStoreFactory, sessionID, provider, sessionTime, HEARTBTINT, 0 );
}

Expand Down

0 comments on commit 194c1ba

Please sign in to comment.