Warnings on vc14 were eliminated
[occt.git] / src / UTL / UTL.cxx
CommitLineData
b311480e 1// Created on: 1997-11-24
2// Created by: Mister rmi
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <OSD_Environment.hxx>
7fd59977 19#include <OSD_File.hxx>
42cf5bc1 20#include <OSD_FileIterator.hxx>
21#include <OSD_Host.hxx>
22#include <OSD_Path.hxx>
7fd59977 23#include <OSD_Protection.hxx>
24#include <OSD_SingleProtection.hxx>
42cf5bc1 25#include <Resource_Manager.hxx>
26#include <Resource_Unicode.hxx>
27#include <Standard_GUID.hxx>
28#include <Storage_BaseDriver.hxx>
29#include <Storage_Data.hxx>
30#include <TCollection_AsciiString.hxx>
31#include <TCollection_ExtendedString.hxx>
32#include <UTL.hxx>
7fd59977 33
34TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
35 TCollection_ExtendedString x;
36 OSD_Environment theEnv(aCString);
37 TCollection_AsciiString theValue=theEnv.Value();
d9ff84e8 38 if( ! theValue.IsEmpty())
39 x = TCollection_ExtendedString(theValue);
7fd59977 40 return x;
41}
7fd59977 42
d9ff84e8 43TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName)
44{
45 TCollection_AsciiString aFileNameU(aFileName);
46 OSD_Path p = OSD_Path(aFileNameU);
47 TCollection_AsciiString theExtension = p.Extension();
48 if (theExtension.Value(1) == '.')
49 theExtension.Remove(1, 1);
50 return TCollection_ExtendedString(theExtension);
7fd59977 51}
d9ff84e8 52
53Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver,
54 const TCollection_ExtendedString& aFileName,
55 const Storage_OpenMode aMode)
56{
57 return aDriver.Open(TCollection_AsciiString(aFileName),aMode);
7fd59977 58}
59
d9ff84e8 60void UTL::AddToUserInfo(const Handle(Storage_Data)& aData,
61 const TCollection_ExtendedString& anInfo)
62{
63 aData->AddToUserInfo(TCollection_AsciiString(anInfo));
7fd59977 64}
7fd59977 65
d9ff84e8 66OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName)
67{
68 OSD_Path p = OSD_Path(TCollection_AsciiString(aFileName));
7fd59977 69 return p;
70}
d9ff84e8 71
72TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath)
73{
74 return TCollection_ExtendedString(aPath.Disk());
7fd59977 75}
d9ff84e8 76
77TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath)
78{
79 return TCollection_ExtendedString(aPath.Trek());
7fd59977 80}
d9ff84e8 81
82TCollection_ExtendedString UTL::Name(const OSD_Path& aPath)
83{
84 return TCollection_ExtendedString(aPath.Name());
7fd59977 85}
d9ff84e8 86
87TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath)
88{
89 return TCollection_ExtendedString(aPath.Extension());
7fd59977 90}
d9ff84e8 91
92OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask)
93{
94 OSD_FileIterator it = OSD_FileIterator(aPath,TCollection_AsciiString(aMask));
7fd59977 95 return it;
96}
d9ff84e8 97
98TCollection_ExtendedString UTL::LocalHost()
99{
7fd59977 100 OSD_Host h;
d9ff84e8 101 return TCollection_ExtendedString(h.HostName());
7fd59977 102}
d9ff84e8 103
104TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString)
105{
106 return TCollection_ExtendedString(anAsciiString);
7fd59977 107}
d9ff84e8 108
109Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString)
110{
7fd59977 111 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
112}
d9ff84e8 113
114Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager,
115 const TCollection_ExtendedString& aResourceName)
116{
117 return aResourceManager->Find(TCollection_AsciiString(aResourceName).ToCString());
118}
119
120TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager,
121 const TCollection_ExtendedString& aResourceName)
122{
123 TCollection_AsciiString aResourceNameU(aResourceName);
124 return TCollection_ExtendedString(aResourceManager->Value(aResourceNameU.ToCString()),
125 Standard_True);
7fd59977 126}
127
d9ff84e8 128Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString)
129{
130 TCollection_AsciiString a(anExtendedString);
7fd59977 131 return a.IntegerValue();
132}
d9ff84e8 133
134Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString)
135{
7fd59977 136 static TCollection_AsciiString theValue;
d9ff84e8 137 theValue = TCollection_AsciiString(anExtendedString);
7fd59977 138 return theValue.ToCString();
139}
7fd59977 140
d9ff84e8 141Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName)
142{
7fd59977 143 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
144 case OSD_W:
145 case OSD_RW:
146 case OSD_WX:
147 case OSD_RWX:
148 case OSD_RWD:
149 case OSD_WXD:
150 case OSD_RWXD:
151 return Standard_False;
152 default:
153 return Standard_True;
154 }
155}