Warnings on vc14 were eliminated
[occt.git] / src / UTL / UTL.cxx
1 // Created on: 1997-11-24
2 // Created by: Mister rmi
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <OSD_Environment.hxx>
19 #include <OSD_File.hxx>
20 #include <OSD_FileIterator.hxx>
21 #include <OSD_Host.hxx>
22 #include <OSD_Path.hxx>
23 #include <OSD_Protection.hxx>
24 #include <OSD_SingleProtection.hxx>
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>
33
34 TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
35   TCollection_ExtendedString x;
36   OSD_Environment theEnv(aCString);
37   TCollection_AsciiString theValue=theEnv.Value();
38   if( ! theValue.IsEmpty())
39     x = TCollection_ExtendedString(theValue);
40   return x;
41 }
42
43 TCollection_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);
51 }
52
53 Storage_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);
58 }
59
60 void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, 
61                         const TCollection_ExtendedString& anInfo) 
62 {
63   aData->AddToUserInfo(TCollection_AsciiString(anInfo));
64 }
65
66 OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) 
67 {
68   OSD_Path p = OSD_Path(TCollection_AsciiString(aFileName));
69   return p;
70 }
71
72 TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath)
73 {
74   return TCollection_ExtendedString(aPath.Disk());
75 }
76
77 TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath)
78 {
79   return TCollection_ExtendedString(aPath.Trek());
80 }
81
82 TCollection_ExtendedString UTL::Name(const OSD_Path& aPath)
83 {
84   return TCollection_ExtendedString(aPath.Name());
85 }
86
87 TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath)
88 {
89   return TCollection_ExtendedString(aPath.Extension());
90 }
91
92 OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask)
93 {
94   OSD_FileIterator it = OSD_FileIterator(aPath,TCollection_AsciiString(aMask));
95   return it;
96 }
97
98 TCollection_ExtendedString UTL::LocalHost()
99 {
100   OSD_Host h;
101   return TCollection_ExtendedString(h.HostName());
102 }
103
104 TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString)
105 {
106   return TCollection_ExtendedString(anAsciiString);
107 }
108
109 Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString)
110 {
111   return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
112 }
113
114 Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager,
115                            const TCollection_ExtendedString& aResourceName)
116 {
117   return aResourceManager->Find(TCollection_AsciiString(aResourceName).ToCString());
118 }
119
120 TCollection_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);
126 }  
127
128 Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString)
129 {
130   TCollection_AsciiString a(anExtendedString);
131   return a.IntegerValue();
132 }
133
134 Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString)
135 {
136   static TCollection_AsciiString theValue;
137   theValue = TCollection_AsciiString(anExtendedString);
138   return theValue.ToCString();
139 }
140
141 Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName)
142 {
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 }