Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2007-03-16
0002 // Created by: Michael SAZONOV
0003 // Copyright (c) 2007-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 // The original implementation Copyright: (C) RINA S.p.A
0017 
0018 #ifndef TObj_TIntSparseArray_HeaderFile
0019 #define TObj_TIntSparseArray_HeaderFile
0020 
0021 
0022 #include <NCollection_SparseArray.hxx>
0023 #include <TDF_Label.hxx>
0024 
0025 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
0026 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
0027 
0028 class Standard_GUID;
0029 
0030 /**
0031  * OCAF Attribute to store a set of positive integer values in the OCAF tree.
0032  * Each value is identified by ID (positive integer).
0033  * The supporting underlying data structure is NCollection_SparseArray of integers.
0034  */
0035 
0036 class TObj_TIntSparseArray : public TDF_Attribute
0037 {
0038  public:
0039 
0040   //! Empty constructor
0041   Standard_EXPORT TObj_TIntSparseArray();
0042 
0043   //! This method is used in implementation of ID()
0044   static Standard_EXPORT const Standard_GUID& GetID();
0045 
0046   //! Returns the ID of this attribute.
0047   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
0048 
0049   //! Creates TObj_TIntSparseArray attribute on given label.
0050   static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
0051                             (const TDF_Label& theLabel);
0052 
0053  public:
0054   //! Methods for access to data
0055 
0056   //! Returns the number of stored values in the set
0057   Standard_Size Size() const
0058   { return myVector.Size(); }
0059 
0060   typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
0061 
0062   //! Returns iterator on objects contained in the set
0063   Iterator GetIterator() const { return Iterator(myVector); }
0064 
0065   //! Returns true if the value with the given ID is present.
0066   Standard_Boolean HasValue (const Standard_Size theId) const
0067   { return myVector.HasValue(theId); }
0068 
0069   //! Returns the value by its ID.
0070   //! Raises an exception if no value is stored with this ID
0071   Standard_Integer Value (const Standard_Size theId) const
0072   { return myVector.Value(theId); }
0073 
0074   //! Sets the value with the given ID.
0075   //! Raises an exception if theId is not positive
0076   Standard_EXPORT void SetValue (const Standard_Size theId,
0077                                  const Standard_Integer theValue);
0078 
0079   //! Unsets the value with the given ID.
0080   //! Raises an exception if theId is not positive
0081   Standard_EXPORT void UnsetValue(const Standard_Size theId);
0082 
0083   //! Clears the set
0084   Standard_EXPORT void Clear ();
0085 
0086  public:
0087   //! Redefined OCAF abstract methods
0088 
0089   //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
0090   //! copy algorithm.
0091   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
0092 
0093   //! Moves this delta into a new other attribute.
0094   Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const Standard_OVERRIDE;
0095 
0096   //! Restores the set using info saved in backup attribute theDelta.
0097   Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta) Standard_OVERRIDE;
0098 
0099   //! This method is used when copying an attribute from a source structure
0100   //! into a target structure.
0101   Standard_EXPORT void Paste(const Handle(TDF_Attribute)&       theInto,
0102                              const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
0103 
0104   //! It is called just before Commit or Abort transaction
0105   //! and does Backup() to create a delta
0106   Standard_EXPORT void BeforeCommitTransaction() Standard_OVERRIDE;
0107 
0108   //! Applies theDelta to this.
0109   Standard_EXPORT void DeltaOnModification
0110                         (const Handle(TDF_DeltaOnModification)& theDelta) Standard_OVERRIDE;
0111 
0112   //! Clears my modification delta; called after application of theDelta
0113   Standard_EXPORT Standard_Boolean AfterUndo
0114                         (const Handle(TDF_AttributeDelta)& theDelta,
0115                          const Standard_Boolean toForce) Standard_OVERRIDE;
0116 
0117  public:
0118   //! Methods to handle the modification delta
0119 
0120   //! Sets the flag pointing to the necessity to maintain a modification delta.
0121   //! It is called by the retrieval driver
0122   void SetDoBackup (const Standard_Boolean toDo)
0123   { myDoBackup = toDo; }
0124 
0125   void ClearDelta ()
0126   { myOldMap.Clear(); }
0127 
0128  private:
0129   //! Internal constant to recognize items in the backup array
0130   //! correspondent to absent values
0131   enum
0132   {
0133     AbsentValue = -1
0134   };
0135 
0136   //! backup one value
0137   void backupValue (const Standard_Size theId,
0138                     const Standard_Integer theCurrValue,
0139                     const Standard_Integer theNewValue);
0140 
0141   TObj_TIntSparseArray_VecOfData myVector;
0142   TObj_TIntSparseArray_MapOfData myOldMap;
0143   Standard_Boolean               myDoBackup;
0144 
0145  public:
0146   //! CASCADE RTTI
0147   DEFINE_STANDARD_RTTIEXT(TObj_TIntSparseArray,TDF_Attribute)
0148 };
0149 
0150 //! Define handle class for TObj_TIntSparseArray
0151 DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
0152 
0153 #endif
0154 
0155 #ifdef _MSC_VER
0156 #pragma once
0157 #endif