Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:19:09

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),
0027         myPosition(0)
0028   {
0029     Next();
0030   }
0031 
0032   //! Return TRUE if iterator points to a value.
0033   bool More() const { return !mySubId.IsEmpty(); }
0034 
0035   //! Return current value.
0036   const TCollection_AsciiString& Value() const { return mySubId; }
0037 
0038   //! Find the next value.
0039   void Next();
0040 
0041 private:
0042   // Disable assignment operator.
0043   XCAFPrs_DocumentIdIterator& operator=(const XCAFPrs_DocumentIdIterator&) = delete;
0044 
0045 private:
0046   const TCollection_AsciiString& myPath;     //!< full path
0047   TCollection_AsciiString        mySubId;    //!< current value
0048   int                            myPosition; //!< last processed new-line symbol
0049 };
0050 
0051 //=================================================================================================
0052 
0053 inline void XCAFPrs_DocumentIdIterator::Next()
0054 {
0055   for (int aCharIndex = myPosition + 1; aCharIndex <= myPath.Length(); ++aCharIndex)
0056   {
0057     if (myPath.Value(aCharIndex) == '/')
0058     {
0059       // intermediate items have trailing dot and separator before the next item
0060       const int aLen = aCharIndex - myPosition - 2;
0061       if (aLen < 1)
0062       {
0063         return; // assert - should never happen for valid IDs!
0064       }
0065 
0066       mySubId    = myPath.SubString(myPosition + 1, aCharIndex - 2);
0067       myPosition = aCharIndex;
0068       return;
0069     }
0070   }
0071   if (myPosition < myPath.Length())
0072   {
0073     // last item has only trailing dot
0074     mySubId    = myPath.SubString(myPosition + 1, myPath.Length() - 1);
0075     myPosition = myPath.Length();
0076   }
0077   else
0078   {
0079     mySubId.Clear();
0080     myPosition = myPath.Length();
0081   }
0082 }
0083 
0084 #endif // _XCAFPrs_DocumentIdIterator_HeaderFile