0022972: Eliminate macro definitions that has compiler-provided analogs (WNT and...
[occt.git] / src / PCDM / PCDM_ReferenceIterator.cxx
CommitLineData
b311480e 1// Created on: 1997-12-01
2// Created by: Jean-Louis Frenkel
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 <CDM_Application.hxx>
42cf5bc1 19#include <CDM_Document.hxx>
20#include <CDM_MessageDriver.hxx>
21#include <CDM_MetaData.hxx>
7fd59977 22#include <OSD_Path.hxx>
42cf5bc1 23#include <PCDM_Reference.hxx>
24#include <PCDM_ReferenceIterator.hxx>
25#include <PCDM_RetrievalDriver.hxx>
26#include <Standard_Type.hxx>
27#include <Storage_Data.hxx>
28#include <UTL.hxx>
7fd59977 29
57c28b61 30#ifdef _MSC_VER
7fd59977 31# include <tchar.h>
57c28b61 32#endif // _MSC_VER
7fd59977 33
34//=======================================================================
35//function : PCDM_ReferenceIterator
36//purpose :
37//=======================================================================
38
c24d4017 39PCDM_ReferenceIterator::PCDM_ReferenceIterator (const Handle(CDM_MessageDriver)& theMsgDriver) :
40 myIterator(0)
41{
7fd59977 42 myMessageDriver = theMsgDriver;
43}
44
45//=======================================================================
46//function : LoadReferences
47//purpose :
48//=======================================================================
49
50void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocument,
51 const Handle(CDM_MetaData)& aMetaData,
52 const Handle(CDM_Application)& anApplication,
53 const Standard_Boolean UseStorageConfiguration) {
54 for (Init(aMetaData);More();Next()) {
55 aDocument->CreateReference(MetaData(UseStorageConfiguration),ReferenceIdentifier(),
56 anApplication,DocumentVersion(),UseStorageConfiguration);
57 }
58}
59
60//=======================================================================
61//function : Init
62//purpose :
63//=======================================================================
64
65void PCDM_ReferenceIterator::Init(const Handle(CDM_MetaData)& theMetaData) {
66
67 myReferences.Clear();
68 // mod. by szy
69 PCDM_RetrievalDriver::References(theMetaData->FileName(), myReferences,
70 myMessageDriver);
71 myIterator=1;
72}
73
74//=======================================================================
75//function : More
76//purpose :
77//=======================================================================
78
79Standard_Boolean PCDM_ReferenceIterator::More() const {
80 return myIterator <= myReferences.Length();
81}
82
83//=======================================================================
84//function : Next
85//purpose :
86//=======================================================================
87
88void PCDM_ReferenceIterator::Next() {
89 myIterator++;
90}
91
92//=======================================================================
93//function : MetaData
94//purpose :
95//=======================================================================
96
97Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) const {
98
99 TCollection_ExtendedString theFolder,theName;
100 TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
101 TCollection_ExtendedString f(theFile);
57c28b61 102#ifndef _WIN32
7fd59977 103
104 Standard_Integer i= f.SearchFromEnd("/");
105 TCollection_ExtendedString n = f.Split(i);
106 f.Trunc(f.Length()-1);
107 theFolder = f;
108 theName = n;
109#else
110 OSD_Path p = UTL::Path(f);
111 Standard_ExtCharacter chr;
112 TCollection_ExtendedString dir, dirRet, name;
113
114 dir = UTL::Disk(p);
115 dir += UTL::Trek(p);
116
117 for ( int i = 1; i <= dir.Length (); ++i ) {
118
119 chr = dir.Value ( i );
120
121 switch ( chr ) {
122
123 case _TEXT( '|' ):
124 dirRet += _TEXT( "/" );
125 break;
126
127 case _TEXT( '^' ):
128
129 dirRet += _TEXT( ".." );
130 break;
131
132 default:
133 dirRet += chr;
134
135 }
136 }
137 theFolder = dirRet;
138 theName = UTL::Name(p); theName+= UTL::Extension(p);
57c28b61 139#endif // _WIN32
7fd59977 140
141 return CDM_MetaData::LookUp(theFolder,theName,theFile,theFile,UTL::IsReadOnly(theFile));
142}
143//=======================================================================
144//function : ReferenceIdentifier
145//purpose :
146//=======================================================================
147
148Standard_Integer PCDM_ReferenceIterator::ReferenceIdentifier() const {
149 return myReferences(myIterator).ReferenceIdentifier();
150}
151//=======================================================================
152//function : DocumentVersion
153//purpose :
154//=======================================================================
155
156Standard_Integer PCDM_ReferenceIterator::DocumentVersion() const {
157 return myReferences(myIterator).DocumentVersion();
158}