Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Author: Kirill Gavrilov
0002 // Copyright (c) 2017-2019 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _XCAFPrs_DocumentIdIterator_HeaderFile
0016 #define _XCAFPrs_DocumentIdIterator_HeaderFile
0017 
0018 #include <XCAFPrs_Style.hxx>
0019 
0020 //! Auxiliary tool for iterating through Path identification string.
0021 class XCAFPrs_DocumentIdIterator
0022 {
0023 public:
0024   //! Main constructor.
0025   XCAFPrs_DocumentIdIterator (const TCollection_AsciiString& thePath)
0026   : myPath (thePath), myPosition (0)
0027   {
0028     Next();
0029   }
0030 
0031   //! Return TRUE if iterator points to a value.
0032   bool More() const { return !mySubId.IsEmpty(); }
0033 
0034   //! Return current value.
0035   const TCollection_AsciiString& Value() const { return mySubId; }
0036 
0037   //! Find the next value.
0038   void Next();
0039 
0040 private:
0041 
0042   // Disable assignment operator.
0043   XCAFPrs_DocumentIdIterator& operator= (const XCAFPrs_DocumentIdIterator& );
0044 
0045 private:
0046   const TCollection_AsciiString& myPath;     //!< full path
0047   TCollection_AsciiString        mySubId;    //!< current value
0048   Standard_Integer               myPosition; //!< last processed new-line symbol
0049 };
0050 
0051 // =======================================================================
0052 // function : Next
0053 // purpose  :
0054 // =======================================================================
0055 inline void XCAFPrs_DocumentIdIterator::Next()
0056 {
0057   for (Standard_Integer aCharIndex = myPosition + 1; aCharIndex <= myPath.Length(); ++aCharIndex)
0058   {
0059     if (myPath.Value (aCharIndex) == '/')
0060     {
0061       // intermediate items have trailing dot and separator before the next item
0062       const Standard_Integer aLen = aCharIndex - myPosition - 2;
0063       if (aLen < 1)
0064       {
0065         return; // assert - should never happen for valid IDs!
0066       }
0067 
0068       mySubId = myPath.SubString (myPosition + 1, aCharIndex - 2);
0069       myPosition = aCharIndex;
0070       return;
0071     }
0072   }
0073   if (myPosition < myPath.Length())
0074   {
0075     // last item has only trailing dot
0076     mySubId = myPath.SubString (myPosition + 1, myPath.Length() - 1);
0077     myPosition = myPath.Length();
0078   }
0079   else
0080   {
0081     mySubId.Clear();
0082     myPosition = myPath.Length();
0083   }
0084 }
0085 
0086 #endif // _XCAFPrs_DocumentIdIterator_HeaderFile