0031918: Application Framework - New binary format for fast reading part of OCAF...
[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>
83ae3591 20#include <Message_Messenger.hxx>
42cf5bc1 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
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(PCDM_ReferenceIterator,Standard_Transient)
31
57c28b61 32#ifdef _MSC_VER
7fd59977 33# include <tchar.h>
57c28b61 34#endif // _MSC_VER
7fd59977 35
36//=======================================================================
37//function : PCDM_ReferenceIterator
38//purpose :
39//=======================================================================
40
83ae3591 41PCDM_ReferenceIterator::PCDM_ReferenceIterator (const Handle(Message_Messenger)& theMsgDriver) :
c24d4017 42 myIterator(0)
43{
7fd59977 44 myMessageDriver = theMsgDriver;
45}
46
47//=======================================================================
48//function : LoadReferences
49//purpose :
50//=======================================================================
51
52void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocument,
53 const Handle(CDM_MetaData)& aMetaData,
54 const Handle(CDM_Application)& anApplication,
55 const Standard_Boolean UseStorageConfiguration) {
8a39adb7 56 for (Init(aMetaData);More();Next())
57 {
58 aDocument->CreateReference(MetaData(anApplication->MetaDataLookUpTable(),UseStorageConfiguration),
59 ReferenceIdentifier(),anApplication,DocumentVersion(),UseStorageConfiguration);
7fd59977 60 }
61}
62
63//=======================================================================
64//function : Init
65//purpose :
66//=======================================================================
67
68void PCDM_ReferenceIterator::Init(const Handle(CDM_MetaData)& theMetaData) {
69
70 myReferences.Clear();
71 // mod. by szy
72 PCDM_RetrievalDriver::References(theMetaData->FileName(), myReferences,
73 myMessageDriver);
74 myIterator=1;
75}
76
77//=======================================================================
78//function : More
79//purpose :
80//=======================================================================
81
82Standard_Boolean PCDM_ReferenceIterator::More() const {
83 return myIterator <= myReferences.Length();
84}
85
86//=======================================================================
87//function : Next
88//purpose :
89//=======================================================================
90
91void PCDM_ReferenceIterator::Next() {
92 myIterator++;
93}
94
95//=======================================================================
96//function : MetaData
97//purpose :
98//=======================================================================
99
8a39adb7 100Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(CDM_MetaDataLookUpTable& theLookUpTable,
101 const Standard_Boolean ) const
102{
7fd59977 103
104 TCollection_ExtendedString theFolder,theName;
105 TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
106 TCollection_ExtendedString f(theFile);
57c28b61 107#ifndef _WIN32
7fd59977 108
109 Standard_Integer i= f.SearchFromEnd("/");
110 TCollection_ExtendedString n = f.Split(i);
111 f.Trunc(f.Length()-1);
112 theFolder = f;
113 theName = n;
114#else
115 OSD_Path p = UTL::Path(f);
116 Standard_ExtCharacter chr;
117 TCollection_ExtendedString dir, dirRet, name;
118
119 dir = UTL::Disk(p);
120 dir += UTL::Trek(p);
121
122 for ( int i = 1; i <= dir.Length (); ++i ) {
123
124 chr = dir.Value ( i );
125
126 switch ( chr ) {
7c65581d 127
128 case '|':
129 dirRet += "/";
7fd59977 130 break;
7c65581d 131
132 case '^':
133
134 dirRet += "..";
7fd59977 135 break;
136
137 default:
138 dirRet += chr;
139
140 }
141 }
142 theFolder = dirRet;
143 theName = UTL::Name(p); theName+= UTL::Extension(p);
57c28b61 144#endif // _WIN32
7fd59977 145
8a39adb7 146 return CDM_MetaData::LookUp(theLookUpTable, theFolder, theName, theFile, theFile, UTL::IsReadOnly(theFile));
7fd59977 147}
8a39adb7 148
7fd59977 149//=======================================================================
150//function : ReferenceIdentifier
151//purpose :
152//=======================================================================
153
154Standard_Integer PCDM_ReferenceIterator::ReferenceIdentifier() const {
155 return myReferences(myIterator).ReferenceIdentifier();
156}
157//=======================================================================
158//function : DocumentVersion
159//purpose :
160//=======================================================================
161
162Standard_Integer PCDM_ReferenceIterator::DocumentVersion() const {
163 return myReferences(myIterator).DocumentVersion();
164}