--- trunk/tengDissertation/Appendix.tex 2006/06/08 19:54:33 2826 +++ trunk/tengDissertation/Appendix.tex 2006/06/08 22:39:54 2835 @@ -129,20 +129,21 @@ is declared as designs, such as lifespan control \textit{etc}, we only use the static data approach in {\sc OOPSE}. {\tt IntegratorFactory} class is declared as -\begin{lstlisting}[float,caption={[A classic Singleton design pattern implementation(I)] Declaration of {\tt IntegratorFactory} class.},label={appendixScheme:singletonDeclaration}] +\begin{lstlisting}[float,caption={[A classic Singleton design pattern implementation(I)] The declaration of of simple Singleton pattern.},label={appendixScheme:singletonDeclaration}] class IntegratorFactory { - public: - static IntegratorFactory* getInstance(); - protected: - IntegratorFactory(); - private: - static IntegratorFactory* instance_; +public: + static IntegratorFactory* + getInstance(); +protected: + IntegratorFactory(); +private: + static IntegratorFactory* instance_; }; \end{lstlisting} The corresponding implementation is -\begin{lstlisting}[float,caption={[A classic implementation of Singleton design pattern (II)] Implementation of {\tt IntegratorFactory} class.},label={appendixScheme:singletonImplementation}] +\begin{lstlisting}[float,caption={[A classic implementation of Singleton design pattern (II)] The implementation of simple Singleton pattern.},label={appendixScheme:singletonImplementation}] IntegratorFactory::instance_ = NULL; @@ -168,66 +169,58 @@ implemented by delegating the creation operation to th with the problem of creating objects without specifying the exact class of object that will be created. Factory Method is typically implemented by delegating the creation operation to the subclasses. +{\tt Integrator} class Parameterized Factory pattern where factory +method ({\tt createIntegrator} member function) creates products +based on the identifier (see +List.~\ref{appendixScheme:factoryDeclaration}). If the identifier +has been already registered, the factory method will invoke the +corresponding creator (see List.~\ref{integratorCreator}) which +utilizes the modern C++ template technique to avoid subclassing. +\begin{lstlisting}[float,caption={[The implementation of Parameterized Factory pattern (I)]Source code of {\tt IntegratorFactory} class.},label={appendixScheme:factoryDeclaration}] -Registers a creator with a type identifier. Looks up the type -identifier in the internal map. If it is found, it invokes the -corresponding creator for the type identifier and returns its -result. -\begin{lstlisting}[float,caption={[The implementation of Factory pattern (I)].},label={appendixScheme:factoryDeclaration}] - class IntegratorFactory { - public: - typedef std::map CreatorMapType; +public: + typedef std::map CreatorMapType; - bool registerIntegrator(IntegratorCreator* creator); + bool registerIntegrator(IntegratorCreator* creator) { + return creatorMap_.insert(creator->getIdent(), creator).second; + } - Integrator* createIntegrator(const string& id, SimInfo* info); + Integrator* createIntegrator(const string& id, SimInfo* info) { + Integrator* result = NULL; + CreatorMapType::iterator i = creatorMap_.find(id); + if (i != creatorMap_.end()) { + result = (i->second)->create(info); + } + return result; + } - private: - CreatorMapType creatorMap_; +private: + CreatorMapType creatorMap_; }; - \end{lstlisting} +\begin{lstlisting}[float,caption={[The implementation of Parameterized Factory pattern (III)]Source code of creator classes.},label={appendixScheme:integratorCreator}] -\begin{lstlisting}[float,caption={[The implementation of Factory pattern (II)].},label={appendixScheme:factoryDeclarationImplementation}] - -bool IntegratorFactory::unregisterIntegrator(const string& id) { - return creatorMap_.erase(id) == 1; -} - -Integrator* IntegratorFactory::createIntegrator(const string& id, - SimInfo* info) { - CreatorMapType::iterator i = creatorMap_.find(id); - if (i != creatorMap_.end()) { - return (i->second)->create(info); - } else { - return NULL; - } -} - -\end{lstlisting} - -\begin{lstlisting}[float,caption={[The implementation of Factory pattern (III)].},label={appendixScheme:integratorCreator}] - class IntegratorCreator { - public: +public: IntegratorCreator(const string& ident) : ident_(ident) {} const string& getIdent() const { return ident_; } virtual Integrator* create(SimInfo* info) const = 0; - private: +private: string ident_; }; template class IntegratorBuilder : public IntegratorCreator { - public: - IntegratorBuilder(const string& ident) : IntegratorCreator(ident) {} - virtual Integrator* create(SimInfo* info) const { - return new ConcreteIntegrator(info); - } +public: + IntegratorBuilder(const string& ident) + : IntegratorCreator(ident) {} + virtual Integrator* create(SimInfo* info) const { + return new ConcreteIntegrator(info); + } }; \end{lstlisting} @@ -236,92 +229,104 @@ interfaces of the elements. In other words, one can a The purpose of the Visitor Pattern is to encapsulate an operation that you want to perform on the elements. The operation being performed on a structure can be switched without changing the -interfaces of the elements. In other words, one can add virtual +interfaces of the elements. In other words, one can add virtual functions into a set of classes without modifying their interfaces. -The UML class diagram of Visitor patten is shown in -Fig.~\ref{appendixFig:visitorUML}. {\tt Dump2XYZ} program in -Sec.~\ref{appendixSection:Dump2XYZ} uses Visitor pattern -extensively. +Fig.~\ref{appendixFig:visitorUML} demonstrates the structure of +Visitor pattern which is used extensively in {\tt Dump2XYZ}. In +order to convert an OOPSE dump file, a series of distinct and +unrelated operations are performed on different StuntDoubles. +Visitor allows one to keep related operations together by packing +them into one class. {\tt BaseAtomVisitor} is a typical example of +visitor in {\tt Dump2XYZ} program{see +List.~\ref{appendixScheme:visitor}}. In contrast to the operations, +the object structure or element classes rarely change(See +Fig.~\ref{oopseFig:heirarchy} and +List.~\ref{appendixScheme:element}). + \begin{figure} \centering \includegraphics[width=\linewidth]{visitor.eps} -\caption[The architecture of {\sc OOPSE}] {Overview of the structure -of {\sc OOPSE}} \label{appendixFig:visitorUML} +\caption[The UML class diagram of Visitor patten] {The UML class +diagram of Visitor patten.} \label{appendixFig:visitorUML} \end{figure} \begin{lstlisting}[float,caption={[The implementation of Visitor pattern (I)]Source code of the visitor classes.},label={appendixScheme:visitor}] class BaseVisitor{ - public: - virtual void visit(Atom* atom); - virtual void visit(DirectionalAtom* datom); - virtual void visit(RigidBody* rb); +public: + virtual void visit(Atom* atom); + virtual void visit(DirectionalAtom* datom); + virtual void visit(RigidBody* rb); }; +class BaseAtomVisitor:public BaseVisitor{ public: + virtual void visit(Atom* atom); + virtual void visit(DirectionalAtom* datom); + virtual void visit(RigidBody* rb); +}; + \end{lstlisting} \begin{lstlisting}[float,caption={[The implementation of Visitor pattern (II)]Source code of the element classes.},label={appendixScheme:element}] class StuntDouble { - public: - virtual void accept(BaseVisitor* v) = 0; +public: + virtual void accept(BaseVisitor* v) = 0; }; class Atom: public StuntDouble { - public: - virtual void accept{BaseVisitor* v*} { - v->visit(this); - } +public: + virtual void accept{BaseVisitor* v*} { + v->visit(this); + } }; class DirectionalAtom: public Atom { - public: - virtual void accept{BaseVisitor* v*} { - v->visit(this); - } +public: + virtual void accept{BaseVisitor* v*} { + v->visit(this); + } }; class RigidBody: public StuntDouble { - public: - virtual void accept{BaseVisitor* v*} { - v->visit(this); - } +public: + virtual void accept{BaseVisitor* v*} { + v->visit(this); + } }; \end{lstlisting} + \section{\label{appendixSection:concepts}Concepts} OOPSE manipulates both traditional atoms as well as some objects that {\it behave like atoms}. These objects can be rigid collections of atoms or atoms which have orientational degrees of -freedom. Here is a diagram of the class heirarchy: - -\begin{figure} -\centering -\includegraphics[width=3in]{heirarchy.eps} -\caption[Class heirarchy for StuntDoubles in {\sc oopse}-3.0]{ \\ -The class heirarchy of StuntDoubles in {\sc oopse}-3.0. The -selection syntax allows the user to select any of the objects that -are descended from a StuntDouble.} \label{oopseFig:heirarchy} -\end{figure} - -\begin{itemize} -\item A {\bf StuntDouble} is {\it any} object that can be manipulated by the -integrators and minimizers. -\item An {\bf Atom} is a fundamental point-particle that can be moved around during a simulation. -\item A {\bf DirectionalAtom} is an atom which has {\it orientational} as well as translational degrees of freedom. -\item A {\bf RigidBody} is a collection of {\bf Atom}s or {\bf -DirectionalAtom}s which behaves as a single unit. -\end{itemize} - -Every Molecule, Atom and DirectionalAtom in {\sc OOPSE} have their -own names which are specified in the {\tt .md} file. In contrast, -RigidBodies are denoted by their membership and index inside a -particular molecule: [MoleculeName]\_RB\_[index] (the contents -inside the brackets depend on the specifics of the simulation). The -names of rigid bodies are generated automatically. For example, the -name of the first rigid body in a DMPC molecule is DMPC\_RB\_0. +freedom. A diagram of the class heirarchy is illustrated in +Fig.~\ref{oopseFig:heirarchy}. Every Molecule, Atom and +DirectionalAtom in {\sc OOPSE} have their own names which are +specified in the {\tt .md} file. In contrast, RigidBodies are +denoted by their membership and index inside a particular molecule: +[MoleculeName]\_RB\_[index] (the contents inside the brackets depend +on the specifics of the simulation). The names of rigid bodies are +generated automatically. For example, the name of the first rigid +body in a DMPC molecule is DMPC\_RB\_0. +%\begin{figure} +%\centering +%\includegraphics[width=\linewidth]{heirarchy.eps} +%\caption[Class heirarchy for ojects in {\sc OOPSE}]{ A diagram of +%the class heirarchy. +%\begin{itemize} +%\item A {\bf StuntDouble} is {\it any} object that can be manipulated by the +%integrators and minimizers. +%\item An {\bf Atom} is a fundamental point-particle that can be moved around during a simulation. +%\item A {\bf DirectionalAtom} is an atom which has {\it orientational} as well as translational degrees of freedom. +%\item A {\bf RigidBody} is a collection of {\bf Atom}s or {\bf +%DirectionalAtom}s which behaves as a single unit. +%\end{itemize} +%} \label{oopseFig:heirarchy} +%\end{figure} \section{\label{appendixSection:syntax}Syntax of the Select Command}