|
From: <mor...@us...> - 2008-11-18 15:24:43
|
Revision: 3289
http://ecell.svn.sourceforge.net/ecell/?rev=3289&view=rev
Author: moriyoshi
Date: 2008-11-18 15:24:36 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
* Let Model take ownership of all the Entities it manages from Systems,
* Make every EcsObject have a pointer to the Model object.
* Add a handle facility so that the frontend can retrieve any objects in one
path, without deeply traversing the structure.
* Remove theLoggerVector from EcsObject and make LoggerBroker hold each
list of Loggers per Entity.
* Add a quick test for LoggerBroker.
* Remove theLoggerVector from Stepper, as there's no need to build it
beforehand.
* Plug leaks in PropertyInterface and EcsObject that were caused by
PropertySlots.
Modified Paths:
--------------
ecell3/branches/ecell-3.1/ecell/libecs/Defs.hpp.in
ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.cpp
ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Entity.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Entity.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.hpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.cpp
ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Model.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Model.hpp
ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.hpp
ecell3/branches/ecell-3.1/ecell/libecs/Stepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Stepper.hpp
ecell3/branches/ecell-3.1/ecell/libecs/System.cpp
ecell3/branches/ecell-3.1/ecell/libecs/System.hpp
ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.cpp
ecell3/branches/ecell-3.1/ecell/libecs/Util.hpp
ecell3/branches/ecell-3.1/ecell/libecs/tests/Makefile.am
Added Paths:
-----------
ecell3/branches/ecell-3.1/ecell/libecs/Handle.hpp
ecell3/branches/ecell-3.1/ecell/libecs/tests/LoggerBroker_test.cpp
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Defs.hpp.in
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Defs.hpp.in 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Defs.hpp.in 2008-11-18 15:24:36 UTC (rev 3289)
@@ -557,10 +557,6 @@
// containers
DECLARE_VECTOR( Polymorph, PolymorphVector );
-DECLARE_VECTOR( VariablePtr, VariableVector );
-DECLARE_VECTOR( ProcessPtr, ProcessVector );
-DECLARE_VECTOR( SystemPtr, SystemVector );
-DECLARE_VECTOR( StepperPtr, StepperVector );
DECLARE_VECTOR( LoggerPtr, LoggerVector );
// exceptions
Modified: ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/DiscreteEventStepper.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -161,22 +161,16 @@
void DiscreteEventStepper::log()
{
- if( theLoggerVector.empty() )
- {
- return;
- }
-
// call Logger::log() of Loggers that are attached to
// the last fired Process and Variables in its VariableReferenceVector.
const Real aCurrentTime( getCurrentTime() );
ProcessEventCref aLastEvent( theScheduler.getEvent( theLastEventID ) );
- const ProcessCptr aLastProcess( aLastEvent.getProcess() );
+ Process const* aLastProcess( aLastEvent.getProcess() );
- LoggerVectorCref aProcessLoggerVector( aLastProcess->getLoggerVector() );
-
- FOR_ALL( LoggerVector, aProcessLoggerVector )
+ FOR_ALL( LoggerBroker::LoggersPerFullID,
+ aLastProcess->getLoggers() )
{
(*i)->log( aCurrentTime );
}
@@ -194,17 +188,12 @@
i != anEventIDVector.end(); ++i )
{
ProcessEventCref aDependentEvent( theScheduler.getEvent( *i ) );
- ProcessPtr const aDependentProcess( aDependentEvent.getProcess() );
+ Process const* aDependentProcess( aDependentEvent.getProcess() );
-
- LoggerVectorCref aDependentProcessLoggerVector(
- aDependentProcess->getLoggerVector() );
- for ( LoggerVectorConstIterator j(
- aDependentProcessLoggerVector.begin() );
- j != aDependentProcessLoggerVector.end(); ++j )
+ FOR_ALL( LoggerBroker::LoggersPerFullID,
+ aDependentProcess->getLoggers() )
{
- const LoggerPtr aLogger( *j );
- aLogger->log( aCurrentTime );
+ (*i)->log( aCurrentTime );
}
}
@@ -216,10 +205,10 @@
j( aVariableReferenceVector.begin() );
j != aVariableReferenceVector.end(); ++j )
{
- const VariableCptr aVariablePtr( (*j).getVariable() );
- LoggerVectorCref aLoggerVector( aVariablePtr->getLoggerVector() );
+ Variable const* aVariablePtr( (*j).getVariable() );
- FOR_ALL( LoggerVector, aLoggerVector )
+ FOR_ALL( LoggerBroker::LoggersPerFullID,
+ aVariablePtr->getLoggers() )
{
(*i)->log( aCurrentTime );
}
Modified: ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -80,28 +80,7 @@
+ aPropertyName + "]. Get property failed." );
}
-void EcsObject::registerLogger( LoggerPtr aLoggerPtr )
-{
- if( std::find( theLoggerVector.begin(), theLoggerVector.end(), aLoggerPtr )
- == theLoggerVector.end() )
- {
- theLoggerVector.push_back( aLoggerPtr );
- }
-}
-void EcsObject::removeLogger( LoggerPtr aLoggerPtr )
-{
- LoggerVectorIterator i( find( theLoggerVector.begin(),
- theLoggerVector.end(),
- aLoggerPtr ) );
-
- if( i != theLoggerVector.end() )
- {
- theLoggerVector.erase( i );
- }
-}
-
-
void EcsObject::throwNotSetable()
{
THROW_EXCEPTION( AttributeError, "Not setable." );
@@ -119,6 +98,21 @@
return getPropertyInterface().getClassName();
}
+void intrusive_ptr_add_ref( libecs::EcsObject* anEcsObject )
+{
+ // XXX: needs to be atomic
+ ++anEcsObject->theRefCount;
+}
+
+void intrusive_ptr_release( libecs::EcsObject* anEcsObject )
+{
+ // XXX: needs to be atomic
+ if ( --anEcsObject->theRefCount <= 0 )
+ {
+ delete anEcsObject;
+ }
+}
+
#define NULLGETSET_SPECIALIZATION_DEF( TYPE )\
template <> void EcsObject::nullSet<TYPE>( Param<TYPE>::type )\
{\
Modified: ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/EcsObject.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -35,6 +35,7 @@
#define __ECSOBJECT_HPP
#include "libecs/Defs.hpp"
+#include "libecs/Handle.hpp"
#if defined( WIN32 )
// a bit hackish, but works.
@@ -136,6 +137,10 @@
{ \
new(thePropertyInterface) libecs::PropertyInterface<CLASSNAME>( #CLASSNAME, theDMTypeName ); \
} \
+ void CLASSNAME::finalizeModule() \
+ { \
+ reinterpret_cast< libecs::PropertyInterface<CLASSNAME>* >( thePropertyInterface )->~PropertyInterface<CLASSNAME>(); \
+ } \
PropertySlotBaseCptr CLASSNAME::getPropertySlot( libecs::StringCref aPropertyName ) const \
{ \
return _getPropertyInterface().getPropertySlot( aPropertyName ); \
@@ -207,6 +212,7 @@
static libecs::PropertyInterface<CLASSNAME>& _getPropertyInterface(); \
public:\
static void initializeModule(); \
+ static void finalizeModule(); \
static const DynamicModuleInfo* getClassInfoPtr(); \
virtual PropertySlotBaseCptr getPropertySlot( libecs::StringCref aPropertyName ) const; \
virtual void setProperty( libecs::StringCref aPropertyName, libecs::PolymorphCref aValue ); \
@@ -475,6 +481,8 @@
class LIBECS_API EcsObject
{
+ friend void intrusive_ptr_add_ref( EcsObject* );
+ friend void intrusive_ptr_release( EcsObject* );
public:
@@ -484,7 +492,7 @@
}
- EcsObject()
+ EcsObject(): theRefCount( 0 )
{
; // do nothing
}
@@ -494,6 +502,21 @@
; // do nothing
}
+ /**
+ Get a Model object to which this System belongs.
+
+ @return a borrowed pointer to the Model.
+ */
+ Model* getModel() const
+ {
+ return theModel;
+ }
+
+ void setModel( Model* const aModel )
+ {
+ theModel = aModel;
+ }
+
virtual PropertySlotBaseCptr
getPropertySlot( StringCref aPropertyName ) const = 0;
@@ -527,21 +550,20 @@
virtual const PropertyAttributes
defaultGetPropertyAttributes( StringCref aPropertyName ) const;
- void registerLogger( LoggerPtr aLogger );
+ StringCref getClassName() const;
- void removeLogger( LoggerPtr aLogger );
-
- LoggerVectorCref getLoggerVector() const
+ Handle const& getHandle() const
{
- return theLoggerVector;
+ return theHandle;
}
- StringCref getClassName() const;
+ /// @internal
+ void setHandle( Handle const& aHandle )
+ {
+ theHandle = aHandle;
+ }
-public:
-
/// @internal
-
template <typename Type>
void nullSet( typename Param<Type>::type )
{
@@ -549,7 +571,6 @@
}
/// @internal
-
template <typename Type>
const Type nullGet() const
{
@@ -562,10 +583,16 @@
static void throwNotGetable();
protected:
+ Model* theModel;
+ Handle theHandle;
+ int theRefCount;
+};
- LoggerVector theLoggerVector;
+/// @internal
+void intrusive_ptr_add_ref( libecs::EcsObject* anEcsObject );
-};
+/// @internal
+void intrusive_ptr_release( libecs::EcsObject* anEcsObject );
// these specializations of nullSet/nullGet are here to avoid spreading
// inline copies of them around. This reduces sizes of DM .so files a bit.
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Entity.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Entity.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Entity.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -36,8 +36,8 @@
#include "FullID.hpp"
#include "Entity.hpp"
+#include "Model.hpp"
-
namespace libecs
{
@@ -81,4 +81,22 @@
return aSystemPath;
}
+LoggerBroker::LoggersPerFullID
+Entity::getLoggers() const
+{
+ LoggerBroker::PerFullIDMap* aLoggerMap(
+ theLoggerMap ? theLoggerMap:
+ &getModel()->getLoggerBroker().theEmptyPerFullIDMap );
+ return LoggerBroker::LoggersPerFullID(
+ LoggerBroker::PerFullIDLoggerIterator(
+ aLoggerMap->begin(),
+ SelectSecond< LoggerBroker::PerFullIDMap::value_type >() ),
+ LoggerBroker::PerFullIDLoggerIterator(
+ aLoggerMap->end(),
+ SelectSecond< LoggerBroker::PerFullIDMap::value_type >() )
+ );
+ // return getModel()->getLoggerBroker().getLoggersByFullID( getFullID() );
+}
+
+
} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Entity.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Entity.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Entity.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -36,8 +36,8 @@
#include "libecs/EntityType.hpp"
#include "libecs/EcsObject.hpp"
#include "libecs/PropertyInterface.hpp"
+#include "libecs/LoggerBroker.hpp"
-
/**
@addtogroup entities The Entities.
Entities.
@@ -54,6 +54,7 @@
*/
LIBECS_DM_CLASS( Entity, EcsObject )
{
+ friend class LoggerBroker;
public:
LIBECS_DM_OBJECT_ABSTRACT( Entity )
@@ -170,6 +171,11 @@
/**
+ Get loggers associated to this Entity
+ */
+ LoggerBroker::LoggersPerFullID getLoggers() const;
+
+ /**
@internal
Set a supersystem of this Entity.
@@ -184,6 +190,13 @@
theSuperSystem = supersystem;
}
+ protected:
+
+ void setLoggerMap( LoggerBroker::PerFullIDMap* anLoggerMap )
+ {
+ theLoggerMap = anLoggerMap;
+ }
+
private:
// hide them
@@ -191,10 +204,10 @@
EntityRef operator=( EntityRef );
private:
- SystemPtr theSuperSystem;
-
- String theID;
- String theName;
+ SystemPtr theSuperSystem;
+ LoggerBroker::PerFullIDMap* theLoggerMap;
+ String theID;
+ String theName;
};
} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Exceptions.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -97,35 +97,36 @@
// system errors
DEFINE_EXCEPTION( UnexpectedError, Exception );
-DEFINE_EXCEPTION( NotFound, Exception );
-DEFINE_EXCEPTION( IOException, Exception );
+DEFINE_EXCEPTION( NotFound, Exception );
+DEFINE_EXCEPTION( IOException, Exception );
DEFINE_EXCEPTION( NotImplemented, Exception );
-DEFINE_EXCEPTION( Instantiation, Exception );
+DEFINE_EXCEPTION( Instantiation, Exception );
DEFINE_EXCEPTION( AssertionFailed, Exception );
-DEFINE_EXCEPTION( AlreadyExist, Exception );
-DEFINE_EXCEPTION( ValueError, Exception );
-DEFINE_EXCEPTION( TypeError, Exception );
-DEFINE_EXCEPTION( OutOfRange, Exception );
-DEFINE_EXCEPTION( IllegalOperation, Exception );
+DEFINE_EXCEPTION( AlreadyExist, Exception );
+DEFINE_EXCEPTION( ValueError, Exception );
+DEFINE_EXCEPTION( TypeError, Exception );
+DEFINE_EXCEPTION( OutOfRange, Exception );
+DEFINE_EXCEPTION( IllegalOperation, Exception );
+DEFINE_EXCEPTION( TooManyItems, Exception );
// simulation errors
DEFINE_EXCEPTION( SimulationError, Exception );
-DEFINE_EXCEPTION( InitializationFailed, SimulationError );
-DEFINE_EXCEPTION( RangeError, SimulationError );
+DEFINE_EXCEPTION( InitializationFailed, SimulationError );
+DEFINE_EXCEPTION( RangeError, SimulationError );
// PropertySlot errors
-DEFINE_EXCEPTION( PropertyException, Exception );
-DEFINE_EXCEPTION( NoSlot, PropertyException );
+DEFINE_EXCEPTION( PropertyException, Exception );
+DEFINE_EXCEPTION( NoSlot, PropertyException );
DEFINE_EXCEPTION( AttributeError, PropertyException );
// Introspection errors
-DEFINE_EXCEPTION( NoInfoField, Exception );
+DEFINE_EXCEPTION( NoInfoField, Exception );
// FullID errors
-DEFINE_EXCEPTION( BadID, Exception );
-DEFINE_EXCEPTION( BadSystemPath, BadID );
-DEFINE_EXCEPTION( InvalidEntityType, BadID);
+DEFINE_EXCEPTION( BadID, Exception );
+DEFINE_EXCEPTION( BadSystemPath, BadID );
+DEFINE_EXCEPTION( InvalidEntityType, BadID);
/**
Added: ecell3/branches/ecell-3.1/ecell/libecs/Handle.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Handle.hpp (rev 0)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Handle.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -0,0 +1,85 @@
+//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+//
+// This file is part of the E-Cell System
+//
+// Copyright (C) 1996-2008 Keio University
+// Copyright (C) 2005-2008 The Molecular Sciences Institute
+//
+//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+//
+//
+// E-Cell System is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// E-Cell System is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with E-Cell System -- see the file COPYING.
+// If not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+//END_HEADER
+//
+// written by Moriyoshi Koizumi <mo...@sf...>,
+// E-Cell Project.
+//
+
+#ifndef __LIBECS_HANDLE_HPP
+#define __LIBECS_HANDLE_HPP
+
+class Handle
+{
+public:
+ Handle( int hdl ): hdl_( hdl ) {}
+
+ Handle(): hdl_( INVALID_HANDLE_VALUE ) {}
+
+ bool isValid() const
+ {
+ return hdl_ != INVALID_HANDLE_VALUE;
+ }
+
+ bool operator==( Handle const& rhs ) const
+ {
+ if ( hdl_ == rhs.hdl_ )
+ return true;
+ }
+
+ bool operator!=( Handle const& rhs ) const
+ {
+ return !operator==( rhs );
+ }
+
+ bool operator<( Handle const& rhs ) const
+ {
+ return hdl_ < rhs.hdl_;
+ }
+
+ bool operator>=( Handle const& rhs ) const
+ {
+ return !operator<( rhs );
+ }
+
+ bool operator>( Handle const& rhs ) const
+ {
+ return hdl_ > rhs.hdl_;
+ }
+
+ bool operator<=( Handle const& rhs ) const
+ {
+ return !operator>( rhs );
+ }
+
+private:
+ unsigned int hdl_;
+
+public:
+ static const unsigned int INVALID_HANDLE_VALUE = static_cast< unsigned int > ( -1 );
+};
+
+#endif /* __LIBECS_HANDLE_HPP */
Property changes on: ecell3/branches/ecell-3.1/ecell/libecs/Handle.hpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -33,6 +33,9 @@
#include "ecell_config.h"
#endif /* HAVE_CONFIG_H */
+#include <algorithm>
+#include <functional>
+
#include "libecs.hpp"
#include "Entity.hpp"
@@ -56,35 +59,59 @@
LoggerBroker::~LoggerBroker()
{
- FOR_ALL_SECOND( LoggerMap, theLoggerMap, ~Logger );
+ std::for_each( begin(), end(),
+ ComposeUnary(
+ DeletePtr< Logger >(),
+ SelectSecond< iterator::value_type >() ) );
}
void LoggerBroker::flush()
{
- FOR_ALL_SECOND( LoggerMap, theLoggerMap, flush );
+ std::for_each( begin(), end(),
+ ComposeUnary(
+ std::mem_fun( &Logger::flush ),
+ SelectSecond< iterator::value_type >() ) );
}
LoggerPtr LoggerBroker::getLogger( FullPNCref aFullPN ) const
{
- LoggerMapConstIterator aLoggerMapIterator( theLoggerMap.find( aFullPN ) );
+ LoggerMap::const_iterator anOuterIter(
+ theLoggerMap.find( aFullPN.getFullID() ) );
- if( aLoggerMapIterator == theLoggerMap.end() )
+ if( anOuterIter == theLoggerMap.end() )
{
THROW_EXCEPTION( NotFound, "Logger [" + aFullPN.getString()
+ "] not found." );
}
- return aLoggerMapIterator->second;
+ PerFullIDMap::const_iterator anInnerIter(
+ anOuterIter->second.find( aFullPN.getPropertyName() ) );
+
+ if( anInnerIter == anOuterIter->second.end() )
+ {
+ THROW_EXCEPTION( NotFound, "Logger [" + aFullPN.getString()
+ + "] not found." );
+ }
+
+ return anInnerIter->second;
}
-
LoggerPtr LoggerBroker::createLogger( FullPNCref aFullPN,
Logger::Policy const& aPolicy )
{
- if( theLoggerMap.find( aFullPN ) != theLoggerMap.end() )
+ LoggerMap::const_iterator anOuterIter(
+ theLoggerMap.find( aFullPN.getFullID() ) );
+
+ if( anOuterIter != theLoggerMap.end() )
{
- THROW_EXCEPTION( AlreadyExist, "Logger [" + aFullPN.getString()
- + "] already exist." );
+ PerFullIDMap::const_iterator anInnerIter(
+ anOuterIter->second.find( aFullPN.getPropertyName() ) );
+
+ if( anInnerIter != anOuterIter->second.end() )
+ {
+ THROW_EXCEPTION( AlreadyExist, "Logger [" + aFullPN.getString()
+ + "] already exist." );
+ }
}
EntityPtr anEntityPtr( theModel.getEntity( aFullPN.getFullID() ) );
@@ -99,13 +126,100 @@
LoggerPtr aNewLogger( new Logger( aLoggerAdapter, aPolicy ) );
- anEntityPtr->registerLogger( aNewLogger );
- theLoggerMap[ aFullPN ] = aNewLogger;
- // it should have at least one datapoint to work correctly.
- aNewLogger->log( theModel.getCurrentTime() );
- aNewLogger->flush();
+ std::pair< LoggerMap::iterator, bool > anInnerMap(
+ theLoggerMap.insert(
+ LoggerMap::value_type( aFullPN.getFullID(), PerFullIDMap() ) ) );
+ try
+ {
+ ( (*anInnerMap.first).second )[ aFullPN.getPropertyName() ] = aNewLogger;
+ if ( anInnerMap.second )
+ anEntityPtr->setLoggerMap( &( *anInnerMap.first ).second );
+
+ // it should have at least one datapoint to work correctly.
+ aNewLogger->log( theModel.getCurrentTime() );
+ aNewLogger->flush();
+ }
+ catch ( std::exception const& )
+ {
+ if ( anInnerMap.second )
+ {
+ anEntityPtr->setLoggerMap( 0 );
+ theLoggerMap.erase( anInnerMap.first );
+ }
+ delete aNewLogger;
+ throw;
+ }
+
return aNewLogger;
}
+void LoggerBroker::removeLogger( FullPNCref aFullPN )
+{
+ LoggerMap::iterator anOuterIter(
+ theLoggerMap.find( aFullPN.getFullID() ) );
+
+ if( anOuterIter == theLoggerMap.end() )
+ {
+ THROW_EXCEPTION( NotFound, "Logger [" + aFullPN.getString()
+ + "] not found." );
+ }
+
+ PerFullIDMap::iterator anInnerIter(
+ anOuterIter->second.find( aFullPN.getPropertyName() ) );
+
+ if( anInnerIter == anOuterIter->second.end() )
+ {
+ THROW_EXCEPTION( NotFound, "Logger [" + aFullPN.getString()
+ + "] not found." );
+ }
+
+ anOuterIter->second.erase( anInnerIter );
+ if ( anOuterIter->second.empty() )
+ {
+ EntityPtr anEntityPtr( theModel.getEntity( aFullPN.getFullID() ) );
+ anEntityPtr->setLoggerMap( 0 );
+ theLoggerMap.erase( anOuterIter );
+ }
+
+ delete (*anInnerIter).second;
+}
+
+LoggerBroker::LoggersPerFullID
+LoggerBroker::getLoggersByFullID( FullID const& aFullID )
+{
+ LoggerMap::iterator anOuterIter( theLoggerMap.find( aFullID ) );
+ PerFullIDMap& anInnerMap(
+ anOuterIter == theLoggerMap.end() ? theEmptyPerFullIDMap:
+ anOuterIter->second );
+
+ return LoggersPerFullID(
+ PerFullIDLoggerIterator(
+ anInnerMap.begin(),
+ SelectSecond< LoggerMap::value_type::second_type::value_type >() ),
+ PerFullIDLoggerIterator(
+ anInnerMap.end(),
+ SelectSecond< LoggerMap::value_type::second_type::value_type >() )
+ );
+}
+
+LoggerBroker::ConstLoggersPerFullID
+LoggerBroker::getLoggersByFullID( FullID const& aFullID ) const
+{
+ LoggerMap::const_iterator anOuterIter( theLoggerMap.find( aFullID ) );
+ PerFullIDMap const& anInnerMap(
+ anOuterIter == theLoggerMap.end() ? theEmptyPerFullIDMap:
+ anOuterIter->second );
+
+ return ConstLoggersPerFullID(
+ PerFullIDLoggerConstIterator(
+ anInnerMap.begin(),
+ SelectSecond< LoggerMap::value_type::second_type::value_type >() ),
+ PerFullIDLoggerConstIterator(
+ anInnerMap.end(),
+ SelectSecond< LoggerMap::value_type::second_type::value_type >() )
+ );
+}
+
+
} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/LoggerBroker.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -34,8 +34,15 @@
#define __LOGGER_BROKER_HPP
#include <map>
-
+#include <utility>
#include <boost/noncopyable.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/transform_iterator.hpp>
#include "libecs/Defs.hpp"
#include "libecs/FullID.hpp"
@@ -62,9 +69,157 @@
*/
class LIBECS_API LoggerBroker
{
+ friend class Entity;
public:
- DECLARE_MAP( const FullPN, LoggerPtr, std::less<const FullPN>, LoggerMap );
+ typedef std::map< const FullID, std::map< String, Logger* >,
+ std::less< const FullID > > LoggerMap;
+ typedef LoggerMap::value_type::second_type PerFullIDMap;
+
+ template< typename Tderived_, typename Tconstness_ >
+ struct iterator_base
+ {
+ typedef std::bidirectional_iterator_tag iterator_category;
+ typedef std::ptrdiff_t difference_type;
+ typedef std::pair<
+ FullPN const,
+ typename boost::mpl::if_<
+ Tconstness_,
+ typename boost::add_const< Logger >::type,
+ Logger >::type* > value_type;
+ typedef void pointer;
+ typedef std::pair<
+ FullPN const,
+ typename boost::mpl::if_<
+ Tconstness_,
+ typename boost::add_const< Logger >::type,
+ Logger >::type* > reference;
+
+ typedef typename boost::mpl::if_< Tconstness_,
+ typename LoggerMap::const_iterator,
+ typename LoggerMap::iterator >::type
+ outer_iterator_type;
+ typedef typename boost::mpl::if_< Tconstness_,
+ typename outer_iterator_type::value_type::second_type::const_iterator,
+ typename outer_iterator_type::value_type::second_type::iterator >::type
+ inner_iterator_type;
+ typedef std::pair< outer_iterator_type, inner_iterator_type >
+ iterator_pair;
+
+ typedef iterator_base base_type;
+
+ template< typename Trange_ >
+ iterator_base( iterator_pair const& aPair, Trange_& anOuterRange )
+ : thePair( aPair ), theOuterRange( boost::begin( anOuterRange ),
+ boost::end( anOuterRange )) {}
+
+ Tderived_& operator++()
+ {
+ ++thePair.second;
+ if ( thePair.first->second.end() == thePair.second )
+ {
+ if ( theOuterRange.end() == thePair.first )
+ {
+ thePair.second = theOuterRange.begin()->second.begin();
+ }
+ else
+ {
+ ++thePair.first;
+ thePair.second = thePair.first->second.begin();
+ }
+ }
+
+ return *static_cast< Tderived_* >( this );
+ }
+
+ Tderived_ operator++(int)
+ {
+ Tderived_ retval( *this );
+ ++(*this);
+ return retval;
+ }
+
+ Tderived_& operator--()
+ {
+ if ( thePair.first->second.begin() == thePair.second
+ || theOuterRange.end() == thePair.first )
+ {
+ if ( theOuterRange.begin() != thePair.first )
+ {
+ --thePair.first;
+ thePair.second = thePair.first->second.end();
+ }
+ }
+ --thePair.second;
+
+ return *static_cast< Tderived_* >( this );
+ }
+
+ Tderived_ operator--(int)
+ {
+ Tderived_ retval( *this );
+ --(*this);
+ return retval;
+ }
+
+ bool operator==(Tderived_ const& rhs) const
+ {
+ return thePair.first == rhs.thePair.first &&
+ ( thePair.first == theOuterRange.end()
+ || thePair.second == rhs.thePair.second );
+ }
+
+ bool operator!=(Tderived_ const& rhs) const
+ {
+ return !operator==(rhs);
+ }
+
+ reference operator*()
+ {
+ return std::make_pair(
+ FullPN( thePair.first->first, thePair.second->first ),
+ thePair.second->second );
+ }
+
+ public:
+ iterator_pair thePair;
+ boost::iterator_range< outer_iterator_type > theOuterRange;
+ };
+
+ struct iterator
+ : iterator_base< iterator, boost::mpl::bool_< false > >
+ {
+ iterator( base_type const& that ): base_type( that ) {}
+
+ template< typename Trange_ >
+ iterator( iterator_pair const& aPair, Trange_& anOuterRange )
+ : base_type( aPair, anOuterRange ) {}
+ };
+
+ struct const_iterator
+ : iterator_base< const_iterator, boost::mpl::bool_< true > >
+ {
+ const_iterator( base_type const& that ): base_type( that ) {}
+
+ template< typename Trange_ >
+ const_iterator( iterator_pair const& aPair,
+ Trange_ const& anOuterRange )
+ : base_type( aPair, anOuterRange ) {}
+ };
+
+ typedef boost::transform_iterator<
+ SelectSecond< PerFullIDMap::iterator::value_type >,
+ PerFullIDMap::iterator > PerFullIDLoggerIterator;
+
+ typedef boost::transform_iterator<
+ SelectSecond< PerFullIDMap::const_iterator::value_type >,
+ PerFullIDMap::const_iterator > PerFullIDLoggerConstIterator;
+
+ typedef boost::iterator_range< PerFullIDLoggerIterator > LoggersPerFullID;
+
+ typedef boost::iterator_range< PerFullIDLoggerConstIterator > ConstLoggersPerFullID;
+
+public:
LoggerBroker( Model const& aModel );
~LoggerBroker();
@@ -94,6 +249,8 @@
LoggerPtr createLogger( FullPNCref aFullPN, Logger::Policy const& aParamList );
+ void removeLogger( FullPNCref aFullPN );
+
/**
Flush the data in all the Loggers immediately.
@@ -104,28 +261,56 @@
*/
void flush();
- /**
- Get a const reference to the LoggerMap.
+ iterator begin()
+ {
+ return iterator(
+ iterator::iterator_pair(
+ theLoggerMap.begin(),
+ theLoggerMap.begin()->second.begin() ),
+ theLoggerMap );
+ }
- Use this method for const operations such as LoggerMap::size()
- and LoggerMap::begin().
+ iterator end()
+ {
+ return iterator(
+ iterator::iterator_pair(
+ theLoggerMap.end(),
+ theLoggerMap.begin()->second.end() ),
+ theLoggerMap );
+ }
- @return a const reference to the LoggerMap.
- */
+ const_iterator begin() const
+ {
+ return const_iterator(
+ const_iterator::iterator_pair(
+ theLoggerMap.begin(),
+ theLoggerMap.begin()->second.begin() ),
+ theLoggerMap );
+ }
- LoggerMapCref getLoggerMap() const
+ const_iterator end() const
{
- return theLoggerMap;
+ return const_iterator(
+ const_iterator::iterator_pair(
+ theLoggerMap.end(),
+ theLoggerMap.begin()->second.end() ),
+ theLoggerMap );
}
+ LoggersPerFullID getLoggersByFullID( FullID const& aFullID );
+
+ ConstLoggersPerFullID getLoggersByFullID( FullID const& aFullID ) const;
+
private:
/// non-copyable
LoggerBroker( LoggerBroker const& );
private:
- LoggerMap theLoggerMap;
- Model const& theModel;
+ LoggerMap theLoggerMap;
+ PerFullIDMap theEmptyPerFullIDMap;
+ Model const& theModel;
};
+
} // namespace libecs
/** @} */
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Model.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Model.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Model.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -52,6 +52,7 @@
Model::Model( StaticModuleMaker< EcsObject >& maker )
: theCurrentTime( 0.0 ),
+ theNextHandleVal( 0 ),
theLoggerBroker( *this ),
theRootSystemPtr(0),
theSystemStepper(),
@@ -116,33 +117,58 @@
SystemPtr aContainerSystemPtr( getSystem( aFullID.getSystemPath() ) );
- ProcessPtr aProcessPtr( NULLPTR );
- SystemPtr aSystemPtr ( NULLPTR );
- VariablePtr aVariablePtr( NULLPTR );
-
switch( aFullID.getEntityType() )
{
case EntityType::VARIABLE:
- aVariablePtr = theVariableMaker.make( aClassname );
- aVariablePtr->setID( aFullID.getID() );
- aContainerSystemPtr->registerVariable( aVariablePtr );
- return;
+ {
+ Variable* aVariablePtr( theVariableMaker.make( aClassname ) );
+ aVariablePtr->setID( aFullID.getID() );
+ aVariablePtr->setModel( this );
+ Handle nextHandle( generateNextHandle() );
+ theObjectMap.insert(
+ std::make_pair(
+ nextHandle,
+ boost::intrusive_ptr< EcsObject >(
+ aVariablePtr, true ) ) );
+ aVariablePtr->setHandle( nextHandle );
+ aContainerSystemPtr->registerVariable( aVariablePtr );
+ return;
+ }
case EntityType::PROCESS:
- aProcessPtr = theProcessMaker.make( aClassname );
- aProcessPtr->setID( aFullID.getID() );
- aContainerSystemPtr->registerProcess( aProcessPtr );
- return;
+ {
+ Process* aProcessPtr( theProcessMaker.make( aClassname ) );
+ aProcessPtr->setID( aFullID.getID() );
+ aProcessPtr->setModel( this );
+ Handle nextHandle( generateNextHandle() );
+ theObjectMap.insert(
+ std::make_pair(
+ nextHandle,
+ boost::intrusive_ptr< EcsObject >(
+ aProcessPtr, true ) ) );
+ aProcessPtr->setHandle( nextHandle );
+ aContainerSystemPtr->registerProcess( aProcessPtr );
+ return;
+ }
case EntityType::SYSTEM:
- aSystemPtr = theSystemMaker.make( aClassname );
- aSystemPtr->setID( aFullID.getID() );
- aSystemPtr->setModel( this );
- aContainerSystemPtr->registerSystem( aSystemPtr );
- return;
+ {
+ System* aSystemPtr( theSystemMaker.make( aClassname ) );
+ aSystemPtr->setID( aFullID.getID() );
+ aSystemPtr->setModel( this );
+ Handle nextHandle( generateNextHandle() );
+ theObjectMap.insert(
+ std::make_pair(
+ nextHandle,
+ boost::intrusive_ptr< EcsObject >(
+ aSystemPtr, true ) ) );
+ aSystemPtr->setHandle( nextHandle );
+ aContainerSystemPtr->registerSystem( aSystemPtr );
+ return;
+ }
}
- THROW_EXCEPTION( InvalidEntityType, "bad EntityType specified." );
+ THROW_EXCEPTION( InvalidEntityType, "Invalid EntityType specified." );
}
@@ -234,7 +260,7 @@
}
-void Model::checkStepper( SystemCptr const aSystem ) const
+void Model::checkStepper( System const* const aSystem ) const
{
if( aSystem->getStepper() == NULLPTR )
{
@@ -243,7 +269,7 @@
aSystem->getFullID().getString() + "]." );
}
- for( SystemMapConstIterator i( aSystem->getSystemMap().begin() ) ;
+ for( System::SystemMapConstIterator i( aSystem->getSystemMap().begin() ) ;
i != aSystem->getSystemMap().end() ; ++i )
{
// check it recursively
@@ -252,11 +278,11 @@
}
-void Model::initializeSystems( SystemPtr const aSystem )
+void Model::initializeSystems( System* const aSystem )
{
aSystem->initialize();
- for( SystemMapConstIterator i( aSystem->getSystemMap().begin() );
+ for( System::SystemMapConstIterator i( aSystem->getSystemMap().begin() );
i != aSystem->getSystemMap().end() ; ++i )
{
// initialize recursively
@@ -264,7 +290,7 @@
}
}
-void Model::checkSizeVariable( SystemCptr const aSystem )
+void Model::checkSizeVariable( System const* const aSystem )
{
FullID aRootSizeFullID( "Variable:/:SIZE" );
@@ -342,4 +368,11 @@
theScheduler.step();
}
+Handle Model::generateNextHandle()
+{
+ if ( Handle::INVALID_HANDLE_VALUE == ++theNextHandleVal )
+ THROW_EXCEPTION( TooManyItems, "Too many entities or steppers created" );
+ return Handle( theNextHandleVal );
+}
+
} // namespace libecs
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Model.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Model.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Model.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -42,6 +42,7 @@
#include "libecs/LoggerBroker.hpp"
#include "libecs/Stepper.hpp"
#include "libecs/SystemStepper.hpp"
+#include "libecs/Handle.hpp"
/**
@addtogroup model The Model.
@@ -55,10 +56,6 @@
namespace libecs
{
-DECLARE_ASSOCVECTOR( String, StepperPtr, std::less< const String >,
- StepperMap );
-
-
/**
Model class represents a simulation model.
@@ -66,6 +63,9 @@
*/
class LIBECS_API Model
{
+public:
+ DECLARE_ASSOCVECTOR( String, StepperPtr, std::less< const String >,
+ StepperMap );
protected:
typedef EventScheduler< StepperEvent > StepperEventScheduler;
typedef StepperEventScheduler::EventIndex EventIndex;
@@ -73,7 +73,6 @@
typedef EcsObjectMaker< System > SystemMaker;
typedef EcsObjectMaker< Variable > VariableMaker;
typedef EcsObjectMaker< Process > ProcessMaker;
-
public:
Model( StaticModuleMaker< EcsObject >& maker );
~Model();
@@ -158,16 +157,24 @@
@param aFullID a FullID of the requested Entity.
@return A borrowed pointer to an Entity specified by the FullID.
*/
- EntityPtr getEntity( FullIDCref aFullID ) const;
+ Entity* getEntity( FullIDCref aFullID ) const;
/**
+ Retrieves an Entity object by the handle.
+
+ @param handle the handle of the requested Entity.
+ @return A borrowed pointer to an Entity specified by the FullID.
+ */
+ Entity* getEntity( int handle ) const;
+
+ /**
Retrieves a System object pointed by the SystemPath.
@param aSystemPath a SystemPath of the requested System.
@return A borrowed pointer to a System.
*/
- SystemPtr getSystem( SystemPathCref aSystemPath ) const;;
+ System* getSystem( SystemPath const& aSystemPath ) const;;
/**
@@ -273,6 +280,8 @@
void checkSizeVariable( SystemCptr const aSystem );
+ Handle generateNextHandle();
+
static void initializeSystems( SystemPtr const aSystem );
public:
@@ -281,14 +290,19 @@
private:
Time theCurrentTime;
- StepperPtr theLastStepper;
+ Stepper* theLastStepper;
StepperEventScheduler theScheduler;
LoggerBroker theLoggerBroker;
- System *theRootSystemPtr;
+ std::map< Handle, boost::intrusive_ptr< EcsObject > > theObjectMap;
+ unsigned int theNextHandleVal;
+ System* theRootSystemPtr;
+
+ std::vector< Entity* > theDeletionQueue;
+
SystemStepper theSystemStepper;
StepperMap theStepperMap;
Modified: ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/PropertyInterface.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -107,7 +107,9 @@
public:
virtual ~PropertyInterfaceBase()
{
- ; // do nothing
+ std::for_each( thePropertySlotMap.begin(), thePropertySlotMap.end(),
+ ComposeUnary( DeletePtr< PropertySlotBase >(),
+ SelectSecond< PropertySlotMap::value_type >() ) );
}
/**
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Stepper.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Stepper.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Stepper.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -36,6 +36,7 @@
#include <functional>
#include <algorithm>
#include <limits>
+#include <boost/bind.hpp>
#include "Util.hpp"
#include "Variable.hpp"
@@ -59,7 +60,6 @@
: theReadWriteVariableOffset( 0 ),
theReadOnlyVariableOffset( 0 ),
theDiscreteProcessOffset( 0 ),
- theModel( NULLPTR ),
theSchedulerIndex( -1 ),
thePriority( 0 ),
theCurrentTime( 0.0 ),
@@ -87,17 +87,9 @@
//
updateVariableVector();
-
// size of the value buffer == the number of *all* variables.
// (not just read or write variables)
theValueBuffer.resize( theVariableVector.size() );
-
- updateLoggerVector();
-
-
- // Don't call
- // createInterpolants();
- // here: only DifferentialSteppers need this.
}
@@ -252,49 +244,6 @@
}
-void Stepper::updateLoggerVector()
-{
- EntityVector anEntityVector;
- anEntityVector.reserve( theProcessVector.size()
- + getReadOnlyVariableOffset()
- + theSystemVector.size() );
-
- // copy theProcessVector
- std::copy( theProcessVector.begin(), theProcessVector.end(),
- std::back_inserter( anEntityVector ) );
-
- // append theVariableVector
- std::copy( theVariableVector.begin(),
- theVariableVector.begin() + theReadOnlyVariableOffset,
- std::back_inserter( anEntityVector ) );
-
- // append theSystemVector
- std::copy( theSystemVector.begin(), theSystemVector.end(),
- std::back_inserter( anEntityVector ) );
-
-
- theLoggerVector.clear();
-
- // Scan all the relevant Entities, and find loggers
- for( EntityVectorConstIterator i( anEntityVector.begin() );
- i != anEntityVector.end() ; ++i )
- {
- EntityPtr anEntityPtr( *i );
-
- LoggerVectorCref aLoggerVector( anEntityPtr->getLoggerVector() );
-
- if( ! aLoggerVector.empty() )
- {
- theLoggerVector.insert( theLoggerVector.end(),
- aLoggerVector.begin(),
- aLoggerVector.end() );
- }
- }
-
- // optimization: sort by memory address.
- std::sort( theLoggerVector.begin(), theLoggerVector.end() );
-}
-
const bool Stepper::isDependentOn( const StepperCptr aStepper )
{
// Every Stepper depends on the SystemStepper.
@@ -417,11 +366,33 @@
void Stepper::log()
{
- // update loggers
- FOR_ALL( LoggerVector, theLoggerVector )
+ for ( ProcessVector::const_iterator i( theProcessVector.begin() ),
+ end( theProcessVector.end() );
+ i != end; ++i )
{
- (*i)->log( theCurrentTime );
+ LoggerBroker::LoggersPerFullID loggers( (*i)->getLoggers() );
+ std::for_each( loggers.begin(), loggers.end(),
+ boost::bind( &Logger::log, _1, theCurrentTime ) );
}
+
+ for ( VariableVector::const_iterator i( theVariableVector.begin() ),
+ end( theVariableVector.begin()
+ + theReadOnlyVariableOffset );
+ i != end; ++i )
+ {
+ LoggerBroker::LoggersPerFullID loggers( (*i)->getLoggers() );
+ std::for_each( loggers.begin(), loggers.end(),
+ boost::bind( &Logger::log, _1, theCurrentTime ) );
+ }
+
+ for ( SystemVector::const_iterator i( theSystemVector.begin() ),
+ end( theSystemVector.end() );
+ i != end; ++i )
+ {
+ LoggerBroker::LoggersPerFullID loggers( (*i)->getLoggers() );
+ std::for_each( loggers.begin(), loggers.end(),
+ boost::bind( &Logger::log, _1, theCurrentTime ) );
+ }
}
GET_METHOD_DEF( Polymorph, WriteVariableList, Stepper )
@@ -467,7 +438,7 @@
return aVector;
}
-const VariableVector::size_type
+const Stepper::VariableVector::size_type
Stepper::getVariableIndex( VariableCptr const aVariable )
{
VariableVectorConstIterator
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Stepper.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Stepper.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Stepper.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -65,6 +65,9 @@
{
public:
DECLARE_VECTOR( Real, RealVector );
+ DECLARE_VECTOR( Variable*, VariableVector );
+ DECLARE_VECTOR( Process*, ProcessVector );
+ DECLARE_VECTOR( System*, SystemVector );
typedef VariableVector::size_type VariableIndex;
@@ -281,19 +284,6 @@
void registerLogger( LoggerPtr );
- ModelPtr getModel() const
- {
- return theModel;
- }
-
- /**
- @internal
- */
- void setModel( ModelPtr const aModel )
- {
- theModel = aModel;
- }
-
void setSchedulerIndex( const int anIndex )
{
theSchedulerIndex = anIndex;
@@ -482,20 +472,9 @@
*/
void createInterpolants();
- /**
- Scan all the relevant Entity objects to this Stepper and construct
- the list of loggers.
-
- The list, theLoggerVector, is used in log() method.
- */
- void updateLoggerVector();
-
-
protected:
SystemVector theSystemVector;
- LoggerVector theLoggerVector;
-
VariableVector theVariableVector;
VariableVector::size_type theReadWriteVariableOffset;
VariableVector::size_type theReadOnlyVariableOffset;
@@ -508,8 +487,6 @@
RealVector theValueBuffer;
private:
- Model* theModel;
-
/** the index on the scheduler */
int theSchedulerIndex;
Modified: ecell3/branches/ecell-3.1/ecell/libecs/System.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/System.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/System.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -110,7 +110,6 @@
System::System()
: theStepper( NULLPTR ),
theSizeVariable( NULLPTR ),
- theModel( NULLPTR ),
theEntityListChanged( false )
{
; // do nothing
@@ -122,27 +121,6 @@
{
getStepper()->removeSystem( this );
}
-
- // delete Processes first.
- for( ProcessMapIterator i( theProcessMap.begin() );
- i != theProcessMap.end() ; ++i )
- {
- delete i->second;
- }
-
- // then Variables.
- for( VariableMapIterator i( theVariableMap.begin() );
- i != theVariableMap.end() ; ++i )
- {
- delete i->second;
- }
-
- // delete sub-systems.
- for( SystemMapIterator i( theSystemMap.begin() );
- i != theSystemMap.end() ; ++i )
- {
- delete i->second;
- }
}
@@ -209,7 +187,8 @@
configureSizeVariable();
}
-ProcessPtr System::getProcess( StringCref anID ) const
+Process*
+System::getProcess( StringCref anID ) const
{
ProcessMapConstIterator i( getProcessMap().find( anID ) );
@@ -225,7 +204,8 @@
}
-VariablePtr System::getVariable( StringCref anID ) const
+Variable*
+System::getVariable( StringCref anID ) const
{
VariableMapConstIterator i( getVariableMap().find( anID ) );
@@ -260,7 +240,8 @@
notifyChangeOfEntityList();
}
-SystemPtr System::getSystem( SystemPathCref aSystemPath ) const
+System*
+System::getSystem( SystemPathCref aSystemPath ) const
{
if( aSystemPath.empty() )
{
@@ -281,7 +262,8 @@
}
-SystemPtr System::getSystem( StringCref anID ) const
+System*
+System::getSystem( StringCref anID ) const
{
if( anID[0] == '.' )
{
Modified: ecell3/branches/ecell-3.1/ecell/libecs/System.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/System.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/System.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -32,11 +32,11 @@
#ifndef __SYSTEM_HPP
#define __SYSTEM_HPP
-#include "libecs/Defs.hpp"
+#include <boost/intrusive_ptr.hpp>
+#include "libecs/Defs.hpp"
#include "libecs/Entity.hpp"
-
/**
@addtogroup entities
@{
@@ -45,15 +45,15 @@
namespace libecs
{
-// Maps used for entry lists
-DECLARE_MAP( const String, VariablePtr, std::less<const String>, VariableMap );
-DECLARE_MAP( const String, ProcessPtr, std::less<const String>, ProcessMap );
-DECLARE_MAP( const String, SystemPtr, std::less<const String>, SystemMap );
-
-
LIBECS_DM_CLASS( System, Entity )
{
public:
+ // Maps used for entry lists
+ DECLARE_MAP( const String, Variable*, std::less<const String>, VariableMap );
+ DECLARE_MAP( const String, Process*, std::less<const String>, ProcessMap );
+ DECLARE_MAP( const String, System*, std::less<const String>, SystemMap );
+
+public:
LIBECS_DM_BASECLASS( System );
LIBECS_DM_OBJECT( System, System )
@@ -79,7 +79,7 @@
@return A pointer to a Stepper object that this System belongs or
NULL pointer if it is not set.
*/
- StepperPtr getStepper() const
+ Stepper* getStepper() const
{
return theStepper;
}
@@ -115,8 +115,8 @@
return getSize() * N_A;
}
- template <class C>
- const std::map<const String,C*,std::less<const String> >& getMap() const;
+ template <class T_>
+ const std::map<const String, T_*, std::less<const String> >& getMap() const;
VariableMapCref getVariableMap() const
{
@@ -141,7 +141,7 @@
@return a borrowed pointer to a Process object in this System named @a id.
*/
- ProcessPtr getProcess( StringCref anID ) const;
+ Process* getProcess( StringCref anID ) const;
/**
@@ -151,7 +151,7 @@
@return a borrowed pointer to a Variable object in this System named @a id.
*/
- VariablePtr getVariable( StringCref anID ) const;
+ Variable* getVariable( StringCref anID ) const;
/**
Find a System pointed by the given SystemPath relative to
@@ -167,7 +167,7 @@
@param aSystemPath A SystemPath object.
@return a borrowed pointer to a System object pointed by aSystemPath.
*/
- SystemPtr getSystem( SystemPathCref anID ) const;
+ System* getSystem( SystemPathCref anID ) const;
/**
@@ -184,7 +184,7 @@
@return a borrowed pointer to a System object in this System
whose ID is anID.
*/
- SystemPtr getSystem( StringCref id ) const;
+ System* getSystem( StringCref id ) const;
/**
@@ -193,7 +193,7 @@
This method steals ownership of the given pointer, and deletes
it if there is an error.
*/
- void registerProcess( ProcessPtr aProcess );
+ void registerProcess( Process* aProcess );
/**
@@ -202,7 +202,7 @@
This method steals ownership of the given pointer, and deletes
it if there is an error.
*/
- void registerVariable( VariablePtr aVariable );
+ void registerVariable( Variable* aVariable );
/**
@@ -211,7 +211,7 @@
This method steals ownership of the given pointer, and deletes
it if there is an error.
*/
- void registerSystem( SystemPtr aSystem );
+ void registerSystem( System* aSystem );
/**
Check if this is a root System.
@@ -229,29 +229,11 @@
*/
virtual const SystemPath getSystemPath() const;
+ Variable const* const getSizeVariable() const;
- /**
- Get a Model object to which this System belongs.
-
- @return a borrowed pointer to the Model.
- */
- ModelPtr getModel() const
- {
- return theModel;
- }
-
-
- void setModel( ModelPtr const aModel )
- {
- theModel = aModel;
- }
-
-
- VariableCptr const getSizeVariable() const;
-
void notifyChangeOfEntityList();
- VariableCptr const findSizeVariable() const;
+ Variable const* const findSizeVariable() const;
void configureSizeVariable();
@@ -261,35 +243,33 @@
GET_METHOD( Polymorph, ProcessList );
protected:
- StepperPtr theStepper;
+ Stepper* theStepper;
private:
- ModelPtr theModel;
+ VariableMap theVariableMap;
+ ProcessMap theProcessMap;
+ SystemMap theSystemMap;
- VariableMap theVariableMap;
- ProcessMap theProcessMap;
- SystemMap theSystemMap;
+ Variable const* theSizeVariable;
- VariableCptr theSizeVariable;
-
- bool theEntityListChanged;
+ bool theEntityListChanged;
};
template <>
-inline VariableMapCref System::getMap() const
+inline System::VariableMapCref System::getMap() const
{
return getVariableMap();
}
template <>
-inline ProcessMapCref System::getMap() const
+inline System::ProcessMapCref System::getMap() const
{
return getProcessMap();
}
template <>
-inline SystemMapCref System::getMap() const
+inline System::SystemMapCref System::getMap() const
{
return getSystemMap();
}
Modified: ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.cpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/SystemStepper.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -73,12 +73,12 @@
setCurrentTime( aTime );
}
-void SystemStepper::integrateVariablesRecursively( SystemPtr const aSystem,
+void SystemStepper::integrateVariablesRecursively( System* aSystem,
RealParam aTime )
{
- FOR_ALL( VariableMap, aSystem->getVariableMap() )
+ FOR_ALL( System::VariableMap, aSystem->getVariableMap() )
{
- VariablePtr const aVariable( i->second );
+ Variable* aVariable( i->second );
if( aVariable->isIntegrationNeeded() )
{
@@ -86,9 +86,9 @@
}
}
- FOR_ALL( SystemMap, aSystem->getSystemMap() )
+ FOR_ALL( System::SystemMap, aSystem->getSystemMap() )
{
- SystemPtr const aSubSystem( i->second );
+ System* aSubSystem( i->second );
integrateVariablesRecursively( aSubSystem, aTime );
}
}
Modified: ecell3/branches/ecell-3.1/ecell/libecs/Util.hpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/Util.hpp 2008-11-17 10:29:01 UTC (rev 3288)
+++ ecell3/branches/ecell-3.1/ecell/libecs/Util.hpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -121,8 +121,138 @@
bool operator()( T x, T y ) const { return *y > *x; }
};
+template < typename T_ >
+struct SelectFirst
+{
+ typedef T_ argument_type;
+ typedef typename T_::first_type result_type;
+ typename T_::first_type& operator()( T_& pair ) const
+ {
+ return pair.first;
+ }
+ typename T_::first_type const& operator()( T_ const& pair ) const
+ {
+ return pair.first;
+ }
+};
+
+template < typename T_ >
+struct SelectSecond
+{
+ typedef T_ argument_type;
+ typedef typename T_::second_type result_type;
+
+ typename T_::second_type& operator()( T_& pair ) const
+ {
+ return pair.second;
+ }
+
+ typename T_::second_type const& operator()( T_ const& pair ) const
+ {
+ return pair.second;
+ }
+};
+
+template < typename Tderived_, typename Tfun1_, typename Tfun2_,
+ typename Tretval_ = typename Tfun1_::result_type >
+struct UnaryComposeImpl
+{
+ typedef typename Tfun2_::argument_type argument_type;
+ typedef typename Tfun1_::result_type result_type;
+
+ UnaryComposeImpl( Tfun1_ const& f1, Tfun2_ const& f2 )
+ : f1_( f1 ), f2_( f2 ) {}
+
+ result_type operator()( argument_type const& val ) const
+ {
+ return f1_( f2_( val ) );
+ }
+
+ result_type operator()( argument_type const& val )
+ {
+ return f1_( f2_( val ) );
+ }
+
+ result_type operator()( argument_type& val ) const
+ {
+ return f1_( f2_( val ) );
+ }
+
+ result_type operator()( argument_type& val )
+ {
+ return f1_( f2_( val ) );
+ }
+
+private:
+ Tfun1_ f1_;
+ Tfun2_ f2_;
+};
+
+template < typename Tderived_, typename Tfun1_, typename Tfun2_ >
+struct UnaryComposeImpl< Tderived_, Tfun1_, Tfun2_, void >
+{
+ typedef typename Tfun2_::argument_type argument_type;
+ typedef void result_type;
+
+ UnaryComposeImpl( Tfun1_ const& f1, Tfun2_ const& f2 )
+ : f1_( f1 ), f2_( f2 ) {}
+
+ void operator()( argument_type const& val ) const
+ {
+ f1_( f2_( val ) );
+ }
+
+ void operator()( argument_type const& val )
+ {
+ f1_( f2_( val ) );
+ }
+
+ void operator()( argument_type& val ) const
+ {
+ f1_( f2_( val ) );
+ }
+
+ void operator()( argument_type& val )
+ {
+ f1_( f2_( val ) );
+ }
+
+private:
+ Tfun1_ f1_;
+ Tfun2_ f2_;
+};
+
+
+template < typename Tfun1_, typename Tfun2_ >
+struct UnaryCompose: public UnaryComposeImpl< UnaryCompose< Tfun1_, Tfun2_ >,
+ Tfun1_, Tfun2_ >
+{
+public:
+ UnaryCompose( Tfun1_ const& f1, Tfun2_ const& f2 )
+ : UnaryComposeImpl< UnaryCompose, Tfun1_, Tfun2_ >( f1, f2 ) {}
+};
+
+template < typename Tfun1_, typename Tfun2_ >
+inline UnaryCompose< Tfun1_, Tfun2_ >
+ComposeUnary( Tfun1_ const& f1, Tfun2_ const& f2 )
+{
+ return UnaryCompose< Tfun1_, Tfun2_ >( f1, f2 );
+}
+
+template < typename T_ >
+struct DeletePtr
+{
+ typedef void result_type;
+ typedef T_* argument_type;
+
+ void operator()( T_* ptr )
+ {
+ delete ptr;
+ }
+};
+
/**
Check if aSequence's size() is within [ aMin, aMax ].
Added: ecell3/branches/ecell-3.1/ecell/libecs/tests/LoggerBroker_test.cpp
===================================================================
--- ecell3/branches/ecell-3.1/ecell/libecs/tests/LoggerBroker_test.cpp (rev 0)
+++ ecell3/branches/ecell-3.1/ecell/libecs/tests/LoggerBroker_test.cpp 2008-11-18 15:24:36 UTC (rev 3289)
@@ -0,0 +1,77 @@
+//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+//
+// This file is part of the E-Cell LoggerBroker
+//
+// Copyright (C) 1996-2008 Keio University
+// Copyright (C) 2005-2008 The Molecular Sciences Institute
+//
+//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+//
+//
+// E-Cell LoggerBroker is free software; you can redistribute it...
[truncated message content] |