0022627: Change OCCT memory management defaults
[occt.git] / src / UTL / UTL.cxx
CommitLineData
7fd59977 1// File: UTL.cxx
2// Created: Mon Nov 24 07:53:49 1997
3// Author: Mister rmi
4// <rmi@frilox.paris1.matra-dtv.fr>
5
6
7#include <UTL.ixx>
8#include <OSD_Host.hxx>
9#include <OSD_Path.hxx>
10#include <TCollection_ExtendedString.hxx>
11#include <TCollection_AsciiString.hxx>
12#include <Resource_Unicode.hxx>
13#include <OSD_Environment.hxx>
14#include <OSD_FileIterator.hxx>
15#include <OSD_File.hxx>
16#include <OSD_Protection.hxx>
17#include <OSD_SingleProtection.hxx>
18#define MaxChar 10000
19
20
21static Standard_Character longtc[MaxChar];
22static Standard_PCharacter aLongCString = longtc;
23static TCollection_ExtendedString outExtendedString;
24
25static TCollection_AsciiString ASCII(const TCollection_ExtendedString& anXString) {
26 Resource_Unicode::ConvertUnicodeToFormat(anXString,aLongCString,MaxChar);
27 return TCollection_AsciiString(aLongCString);
28}
29
30
31static TCollection_ExtendedString UNICODE(const TCollection_AsciiString& aCString) {
32 Resource_Unicode::ConvertFormatToUnicode(aCString.ToCString(),outExtendedString);
33 return outExtendedString;
34}
35
36TCollection_ExtendedString UTL::xgetenv(const Standard_CString aCString) {
37 TCollection_ExtendedString x;
38 OSD_Environment theEnv(aCString);
39 TCollection_AsciiString theValue=theEnv.Value();
40 if( ! theValue.IsEmpty()) x=UNICODE(theValue);
41 return x;
42}
43TCollection_ExtendedString UTL::Extension(const TCollection_ExtendedString& aFileName) {
44 OSD_Path p = OSD_Path(ASCII(aFileName));
45
46 TCollection_AsciiString theExtension=p.Extension();
47
48 TCollection_AsciiString theGoodExtension=theExtension;;
49
50 if(TCollection_AsciiString(theExtension.Value(1))==".")
51 theGoodExtension=theExtension.Split(1);
52
53 return UNICODE(theGoodExtension);
54}
55Storage_Error UTL::OpenFile(Storage_BaseDriver& aDriver, const TCollection_ExtendedString& aFileName, const Storage_OpenMode aMode) {
56 return aDriver.Open(ASCII(aFileName),aMode);
57}
58
59void UTL::AddToUserInfo(const Handle(Storage_Data)& aData, const TCollection_ExtendedString& anInfo) {
60 aData->AddToUserInfo(ASCII(anInfo));
61}
62OSD_Path UTL::Path(const TCollection_ExtendedString& aFileName) {
63
64// cout << "Path : " << aFileName << endl;
65// TCollection_AsciiString theAciiString=ASCII(aFileName);
66// OSD_Path p = OSD_Path(theAciiString);
67 OSD_Path p = OSD_Path(ASCII(aFileName));
68 return p;
69}
70TCollection_ExtendedString UTL::Disk(const OSD_Path& aPath) {
71 return UNICODE(aPath.Disk());
72}
73TCollection_ExtendedString UTL::Trek(const OSD_Path& aPath) {
74 return UNICODE(aPath.Trek());
75}
76TCollection_ExtendedString UTL::Name(const OSD_Path& aPath) {
77 return UNICODE(aPath.Name());
78}
79TCollection_ExtendedString UTL::Extension(const OSD_Path& aPath) {
80 return UNICODE(aPath.Extension());
81}
82OSD_FileIterator UTL::FileIterator(const OSD_Path& aPath, const TCollection_ExtendedString& aMask) {
83 OSD_FileIterator it = OSD_FileIterator(aPath,ASCII(aMask));
84 return it;
85}
86TCollection_ExtendedString UTL::LocalHost() {
87 OSD_Host h;
88 return UNICODE(h.HostName());
89}
90TCollection_ExtendedString UTL::ExtendedString(const TCollection_AsciiString& anAsciiString) {
91 return UNICODE(anAsciiString);
92}
93Standard_GUID UTL::GUID(const TCollection_ExtendedString& anXString) {
94 return Standard_GUID(TCollection_AsciiString(anXString,'?').ToCString());
95}
96Standard_Boolean UTL::Find(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
97 return aResourceManager->Find(ASCII(aResourceName).ToCString());
98}
99TCollection_ExtendedString UTL::Value(const Handle(Resource_Manager)& aResourceManager, const TCollection_ExtendedString& aResourceName) {
100 return UNICODE(aResourceManager->Value(ASCII(aResourceName).ToCString()));
101}
102
103Standard_Integer UTL::IntegerValue(const TCollection_ExtendedString& anExtendedString) {
104 TCollection_AsciiString a=ASCII(anExtendedString);
105 return a.IntegerValue();
106}
107Standard_CString UTL::CString(const TCollection_ExtendedString& anExtendedString) {
108 static TCollection_AsciiString theValue;
109 theValue=ASCII(anExtendedString);
110 return theValue.ToCString();
111}
112Standard_Boolean UTL::IsReadOnly(const TCollection_ExtendedString& aFileName) {
113
114 switch (OSD_File(UTL::Path(aFileName)).Protection().User()) {
115 case OSD_W:
116 case OSD_RW:
117 case OSD_WX:
118 case OSD_RWX:
119 case OSD_RWD:
120 case OSD_WXD:
121 case OSD_RWXD:
122 return Standard_False;
123 default:
124 return Standard_True;
125 }
126}