Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:20

0001 // Created by: DAUTRY Philippe
0002 // Copyright (c) 1997-1999 Matra Datavision
0003 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _TDF_Data_HeaderFile
0017 #define _TDF_Data_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_Type.hxx>
0021 
0022 #include <TDF_LabelNodePtr.hxx>
0023 #include <Standard_Integer.hxx>
0024 #include <TColStd_ListOfInteger.hxx>
0025 #include <TDF_HAllocator.hxx>
0026 #include <Standard_Transient.hxx>
0027 #include <TDF_Label.hxx>
0028 #include <Standard_OStream.hxx>
0029 #include <NCollection_DataMap.hxx>
0030 class TDF_Delta;
0031 class TDF_Label;
0032 
0033 
0034 class TDF_Data;
0035 DEFINE_STANDARD_HANDLE(TDF_Data, Standard_Transient)
0036 
0037 //! This class is used to manipulate a complete independent,
0038 //! self sufficient data structure and its services:
0039 //!
0040 //! Access to the root label;
0041 //!
0042 //! Opens, aborts, commits a transaction;
0043 //!
0044 //! Generation and use of Delta, depending on the time.
0045 //! This class uses a special allocator
0046 //! (see LabelNodeAllocator() method)
0047 //! for more efficient allocation of objects in memory.
0048 class TDF_Data : public Standard_Transient
0049 {
0050 
0051 public:
0052 
0053   
0054   //! A new and empty Data structure.
0055   Standard_EXPORT TDF_Data();
0056   
0057   //! Returns the root label of the Data structure.
0058     const TDF_Label Root() const;
0059   
0060   //! Returns the current transaction number.
0061   Standard_Integer Transaction() const;
0062   
0063   //! Returns the current tick. It is incremented each Commit.
0064     Standard_Integer Time() const;
0065   
0066   //! Returns true if <aDelta> is applicable HERE and NOW.
0067   Standard_EXPORT Standard_Boolean IsApplicable (const Handle(TDF_Delta)& aDelta) const;
0068   
0069   //! Apply <aDelta> to undo a set of attribute modifications.
0070   //!
0071   //! Optional <withDelta> set to True indicates a
0072   //! Delta Set must be generated. (See above)
0073   Standard_EXPORT Handle(TDF_Delta) Undo (const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta = Standard_False);
0074   
0075   Standard_EXPORT void Destroy();
0076 ~TDF_Data()
0077 {
0078   Destroy();
0079 }
0080   
0081   //! Returns the undo mode status.
0082     Standard_Boolean NotUndoMode() const;
0083   
0084   //! Dumps the Data on <aStream>.
0085     Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const;
0086 Standard_OStream& operator<< (Standard_OStream& anOS) const
0087 {
0088   return Dump(anOS);
0089 }
0090   
0091   //! Sets modification mode.
0092     void AllowModification (const Standard_Boolean isAllowed);
0093   
0094   //! returns modification mode.
0095     Standard_Boolean IsModificationAllowed() const;
0096   
0097   //! Initializes a mechanism for fast access to the labels by their entries.
0098   //! The fast access is useful for large documents and often access to the labels 
0099   //! via entries. Internally, a table of entry - label is created, 
0100   //! which allows to obtain a label by its entry in a very fast way.
0101   //! If the mechanism is turned off, the internal table is cleaned.
0102   //! New labels are added to the table, if the mechanism is on
0103   //! (no need to re-initialize the mechanism).
0104   Standard_EXPORT void SetAccessByEntries (const Standard_Boolean aSet);
0105 
0106   //! Returns a status of mechanism for fast access to the labels via entries.
0107   Standard_Boolean IsAccessByEntries() const { return myAccessByEntries; }
0108 
0109   //! Returns a label by an entry.
0110   //! Returns Standard_False, if such a label doesn't exist
0111   //! or mechanism for fast access to the label by entry is not initialized.
0112   Standard_Boolean GetLabel (const TCollection_AsciiString& anEntry, TDF_Label& aLabel) { return myAccessByEntriesTable.Find(anEntry, aLabel); }
0113 
0114   //! An internal method. It is used internally on creation of new labels.
0115   //! It adds a new label into internal table for fast access to the labels by entry.
0116   Standard_EXPORT void RegisterLabel (const TDF_Label& aLabel);
0117 
0118   //! Returns TDF_HAllocator, which is an
0119   //! incremental allocator used by
0120   //! TDF_LabelNode.
0121   //! This allocator is used to
0122   //! manage TDF_LabelNode objects,
0123   //! but it can also be used for
0124   //! allocating memory to
0125   //! application-specific data (be
0126   //! careful because this
0127   //! allocator does not release
0128   //! the memory).
0129   //! The benefits of this
0130   //! allocation scheme are
0131   //! noticeable when dealing with
0132   //! large OCAF documents, due to:
0133   //! 1.    Very quick allocation of
0134   //! objects (memory heap is not
0135   //! used, the algorithm that
0136   //! replaces it is very simple).
0137   //! 2.    Very quick destruction of
0138   //! objects (memory is released not
0139   //! by destructors of TDF_LabelNode,
0140   //! but rather by the destructor of
0141   //! TDF_Data).
0142   //! 3.  TDF_LabelNode objects do not
0143   //! fragmentize the memory; they are
0144   //! kept compactly in a number of
0145   //! arrays of 16K each.
0146   //! 4.    Swapping is reduced on large
0147   //! data, because each document now
0148   //! occupies a smaller number of
0149   //! memory pages.
0150     const TDF_HAllocator& LabelNodeAllocator() const;
0151 
0152   //! Dumps the content of me into the stream
0153   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0154 
0155 friend class TDF_Transaction;
0156 friend class TDF_LabelNode;
0157 
0158 
0159   DEFINE_STANDARD_RTTIEXT(TDF_Data,Standard_Transient)
0160 
0161 protected:
0162 
0163 
0164 
0165 
0166 private:
0167 
0168   //! Fixes order of Attributes' Deltas to perform undo/redo without exceptions:
0169   //! puts OnRemoval deltas to the end of the list.
0170   void FixOrder(const Handle(TDF_Delta)& theDelta);
0171   
0172   //! Increments the transaction number and returns it.
0173   Standard_EXPORT Standard_Integer OpenTransaction();
0174   
0175   //! Decrements the transaction number and commits the
0176   //! modifications.
0177   //!
0178   //! Raises if there is no current transaction.
0179   //!
0180   //! Optional <withDelta> set to True indicates a
0181   //! Delta must be generated.
0182   Standard_EXPORT Handle(TDF_Delta) CommitTransaction (const Standard_Boolean withDelta = Standard_False);
0183   
0184   //! Decrements the transaction number and commits the
0185   //! modifications until AND including the transaction
0186   //! <untilTransaction>.
0187   Standard_EXPORT Handle(TDF_Delta) CommitUntilTransaction (const Standard_Integer untilTransaction, const Standard_Boolean withDelta = Standard_False);
0188   
0189   //! Decrements the transaction number and forgets the
0190   //! modifications.
0191   //!
0192   //! Raises if there is no current transaction.
0193   Standard_EXPORT void AbortTransaction();
0194   
0195   //! Decrements the transaction number and forgets the
0196   //! modifications until AND including the transaction
0197   //! <untilTransaction>.
0198   Standard_EXPORT void AbortUntilTransaction (const Standard_Integer untilTransaction);
0199   
0200   //! Decrements the transaction number and commits the
0201   //! modifications. Used to implement the recursif
0202   //! commit process. The returned boolean says how many
0203   //! attributes (new, modified or deleted) has been
0204   //! committed from the previous transaction into the
0205   //! current one.
0206   Standard_EXPORT Standard_Integer CommitTransaction (const TDF_Label& aLabel, const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta);
0207 
0208   TDF_LabelNodePtr myRoot;
0209   Standard_Integer myTransaction;
0210   Standard_Integer myNbTouchedAtt;
0211   Standard_Boolean myNotUndoMode;
0212   Standard_Integer myTime;
0213   TColStd_ListOfInteger myTimes;
0214   TDF_HAllocator myLabelNodeAllocator;
0215   Standard_Boolean myAllowModification;
0216   Standard_Boolean myAccessByEntries;
0217   NCollection_DataMap<TCollection_AsciiString, TDF_Label> myAccessByEntriesTable;
0218 };
0219 
0220 
0221 #include <TDF_Data.lxx>
0222 
0223 
0224 
0225 
0226 
0227 #endif // _TDF_Data_HeaderFile