// $Revision: 1.2 $ //------------------------------------------------------------------------------ // // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. // // Project: Atomic Model // File: AtomicModel.h // Build/Version: 1.0.0 // // Description: MAtomicModelOn serves an abstract base class for model // objects that hold one, atomic piece of data. // // MAtomicSelectionOn serves as abstract base class for // selection objects that specify the entire value object // owned by an atomic model object. MAtomicSelectionOn // contains the abstract protocol required to access the // model data from a selection. If possible, use it as the // target of your command. That way your command will // work with other kinds of models which implement // MAtomicSelectionOn's methods in other ways. // // TAtomicModelOn is a templatized concrete model wrapper // for a single polymorphic object of any type. AType // must have the Taligent Type Extension macros. Here are // some possible instantiations: // TAtomicModelOn myModel; // TAtomicModelOn myGraphicModel; // TAtomicModelOn myTextModel; // // TAtomicSelectionOn is a whole-model selection for an // atomic model on a value object of any type. // // TAtomicModelException defines the errors that can be // generated by the Atomic Model classes. // //------------------------------------------------------------------------------ #ifndef TaligentSamples_ATOMICMODEL #define TaligentSamples_ATOMICMODEL #ifndef Taligent_COMPOUNDDOCUMENT #include #endif #ifndef Taligent_BASICDOCUMENTCOMMAND #include #endif #ifndef Taligent_COMPOUNDDOCUMENTCOMMAND #include #endif template class MAtomicSelectionOn; //============================================================================== // MAtomicModelOn template class MAtomicModelOn { public: TaligentTypeExtensionTemplateDeclarationsMacro_Abstract(MAtomicModelOn,AType) public: virtual ~MAtomicModelOn(); virtual const AType* GetValueForReading() const = 0; virtual AType* GetValueForWriting() = 0; virtual void SetValue(const AType& newValue) = 0; virtual AType* CopyValue() const = 0; virtual void AdoptValue(AType* adoptedNewValue) = 0; virtual AType* SwapValue(AType* adoptedNewValue) = 0; virtual void SwapContents(MAtomicModelOn& other) = 0; virtual MAtomicSelectionOn* CreateAtomicSelectionOn() const = 0; virtual void NotifyValueChanged() = 0; // Produces SelectedContentsReplaced notification. //.......................................................................... // Lookup functions static const MAtomicModelOn* LookupForReading(const TModelReference& model); static MAtomicModelOn* LookupForWriting(const TModelReference& model); protected: MAtomicModelOn(); }; //============================================================================== // MAtomicSelectionOn template class MAtomicSelectionOn { public: TaligentTypeExtensionTemplateDeclarationsMacro_Abstract(MAtomicSelectionOn,AType) public: virtual ~MAtomicSelectionOn(); virtual const MAtomicModelOn* GetAtomicModelOnForReading() const = 0; virtual MAtomicModelOn* GetAtomicModelOnForWriting() = 0; //.......................................................................... // These functions delegate to the model protocol, with an // additional check for the selection being empty or undefined.) virtual const AType* GetValueForReading() const; virtual AType* GetValueForWriting(); virtual void SetValue(const AType& newValue); virtual AType* CopyValue() const; virtual void AdoptValue(AType* adoptedNewValue); virtual AType* SwapValue(AType* adoptedNewValue); virtual void SwapContents(MAtomicModelOn& other); protected: MAtomicSelectionOn(); void CheckValueSelected() const; }; //============================================================================== // TAtomicModelOn template class TAtomicModelOn : public TModel, public MAtomicModelOn { public: TaligentTypeExtensionTemplateDeclarationsMacro(TAtomicModelOn,AType) public: TAtomicModelOn(AType* adopt); TAtomicModelOn(const AType& copy); TAtomicModelOn(const TAtomicModelOn& source); virtual ~TAtomicModelOn(); TAtomicModelOn& operator=(const TAtomicModelOn& source); virtual TStream & operator>>=(TStream& toStream) const; virtual TStream & operator<<=(TStream& fromStream); //.......................................................................... // TModel overides virtual TModelSelection* CreateSelection() const; // Returns default selection (non-empty, defined). virtual HashResult ContentHash() const; virtual bool IsContentEqual(const TModel& other) const; virtual bool IsOrphanable() const; // Returns false //.......................................................................... // MAtomicModelOn overrides virtual const AType* GetValueForReading() const; virtual AType* GetValueForWriting(); virtual void SetValue(const AType& newValue); virtual AType* CopyValue() const; virtual void AdoptValue(AType* adoptedNewValue); virtual AType* SwapValue(AType* adoptedNewValue); virtual void SwapContents(MAtomicModelOn& other); virtual MAtomicSelectionOn* CreateAtomicSelectionOn() const; void NotifyValueChanged(); // SelectedContentsReplaced //.......................................................................... // Lookup functions static const TAtomicModelOn* LookupForReading(const TModelReference& model); static TAtomicModelOn* LookupForWriting(const TModelReference& model); protected: TAtomicModelOn(); // For streaming only. private: enum {kOriginalVersion}; AType* fValue; }; //============================================================================== // TAtomicSelectionOn template class TAtomicSelectionOn : public TModelSelection, public MDataExchanger, public MAtomicSelectionOn { public: TaligentTypeExtensionTemplateDeclarationsMacro(TAtomicSelectionOn,AType) public: TAtomicSelectionOn( const TModelReference& theModel); TAtomicSelectionOn( const TAtomicSelectionOn& other); virtual ~TAtomicSelectionOn(); TAtomicSelectionOn& operator=(const TAtomicSelectionOn& other); //.......................................................................... // MAtomicValueOn overrides - If the selection is empty or undefined, // these methods will throw TAtomicModelException::kNoValueSelected. virtual const MAtomicModelOn* GetAtomicModelOnForReading() const; virtual MAtomicModelOn* GetAtomicModelOnForWriting(); protected: TAtomicSelectionOn(); //.......................................................................... // MDataExchanger overrides virtual TModel* HandleCopyData(const TTypeDescription& type) const; virtual void HandleCopyDataInto(TModel& otherModel) const; virtual TModel* HandleReplaceData(TModel* adoptedNewData); virtual TModel* HandleOrphanData(); private: enum {kOriginalVersion}; }; //============================================================================== // TAtomicModelException class TAtomicModelException : public TStandardException { public: TaligentTypeExtensionDeclarationsMacro(TAtomicModelException) public: enum ErrorCode { kCannotStoreNIL = 0x01, kCannotOrphanData = 0x02, kNoValueSelected = 0x03 }; TAtomicModelException(const TAtomicModelException& source); TAtomicModelException(ErrorCode error); virtual ~TAtomicModelException(); TAtomicModelException& operator=(const TAtomicModelException& source); virtual void Throw() const; ErrorCode GetReason() const; protected: TAtomicModelException(); // For streaming only. }; #ifndef TaligentSamples_ATOMICMODELIMP #include #endif #endif