Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:43

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 _RWObj_Tools_HeaderFile
0016 #define _RWObj_Tools_HeaderFile
0017 
0018 #include <gp_XYZ.hxx>
0019 #include <Graphic3d_Vec3.hxx>
0020 #include <TCollection_AsciiString.hxx>
0021 
0022 //! Auxiliary tools for OBJ format parser.
0023 namespace RWObj_Tools
0024 {
0025   //! Read 3 float values.
0026   inline bool ReadVec3 (const char*     thePos,
0027                         char*&          theNext,
0028                         Graphic3d_Vec3& theVec)
0029   {
0030     const char* aPos = thePos;
0031     theVec.x() = (float )Strtod (aPos, &theNext);
0032     aPos = theNext;
0033     theVec.y() = (float )Strtod (aPos, &theNext);
0034     aPos = theNext;
0035     theVec.z() = (float )Strtod (aPos, &theNext);
0036     return aPos != theNext;
0037   }
0038 
0039   //! Read 3 double values.
0040   inline bool ReadVec3 (const char* thePos,
0041                         char*&      theNext,
0042                         gp_XYZ&     theVec)
0043   {
0044     const char* aPos = thePos;
0045     theVec.SetX (Strtod (aPos, &theNext));
0046     aPos = theNext;
0047     theVec.SetY (Strtod (aPos, &theNext));
0048     aPos = theNext;
0049     theVec.SetZ (Strtod (aPos, &theNext));
0050     return aPos != theNext;
0051   }
0052 
0053   //! Read string.
0054   inline bool ReadName (const char*              thePos,
0055                         TCollection_AsciiString& theName)
0056   {
0057     Standard_Integer aFrom = 0;
0058     Standard_Integer aTail = (Standard_Integer )std::strlen (thePos) - 1;
0059     if (aTail >= 0 && thePos[aTail] == '\n') { --aTail; }
0060     if (aTail >= 0 && thePos[aTail] == '\r') { --aTail; }
0061     for (; aTail >= 0    && IsSpace (thePos[aTail]); --aTail) {} // RightAdjust
0062     for (; aFrom < aTail && IsSpace (thePos[aFrom]); ++aFrom) {} // LeftAdjust
0063     if (aFrom > aTail)
0064     {
0065       theName.Clear();
0066       return false;
0067     }
0068     theName = TCollection_AsciiString (thePos + aFrom, aTail - aFrom + 1);
0069     return true;
0070   }
0071 
0072   //! Return true if specified char is a white space.
0073   inline bool isSpaceChar (const char theChar)
0074   {
0075     return theChar == ' '
0076         || theChar == '\t';
0077     //return IsSpace (theChar);
0078   }
0079 }
0080 
0081 #endif // _RWObj_Tools_HeaderFile