7fd59977 |
1 | // File: PCDM_ReferenceIterator.cxx |
2 | // Created: Mon Dec 1 08:07:09 1997 |
3 | // Author: Jean-Louis Frenkel |
4 | // <rmi@frilox.paris1.matra-dtv.fr> |
5 | // modified: <szy@opencascade.com> |
6 | |
7 | #include <PCDM_ReferenceIterator.ixx> |
8 | #include <Storage_Data.hxx> |
9 | #include <UTL.hxx> |
10 | #include <CDM_Document.hxx> |
11 | #include <CDM_Application.hxx> |
12 | #include <PCDM_RetrievalDriver.hxx> |
13 | #include <PCDM_Reference.hxx> |
14 | #include <OSD_Path.hxx> |
15 | |
16 | #ifdef WNT |
17 | # include <tchar.h> |
18 | #endif // WNT |
19 | |
20 | //======================================================================= |
21 | //function : PCDM_ReferenceIterator |
22 | //purpose : |
23 | //======================================================================= |
24 | |
25 | PCDM_ReferenceIterator::PCDM_ReferenceIterator (const Handle(CDM_MessageDriver)& theMsgDriver) { |
26 | myMessageDriver = theMsgDriver; |
27 | } |
28 | |
29 | //======================================================================= |
30 | //function : LoadReferences |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocument, |
35 | const Handle(CDM_MetaData)& aMetaData, |
36 | const Handle(CDM_Application)& anApplication, |
37 | const Standard_Boolean UseStorageConfiguration) { |
38 | for (Init(aMetaData);More();Next()) { |
39 | aDocument->CreateReference(MetaData(UseStorageConfiguration),ReferenceIdentifier(), |
40 | anApplication,DocumentVersion(),UseStorageConfiguration); |
41 | } |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Init |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | void PCDM_ReferenceIterator::Init(const Handle(CDM_MetaData)& theMetaData) { |
50 | |
51 | myReferences.Clear(); |
52 | // mod. by szy |
53 | PCDM_RetrievalDriver::References(theMetaData->FileName(), myReferences, |
54 | myMessageDriver); |
55 | myIterator=1; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : More |
60 | //purpose : |
61 | //======================================================================= |
62 | |
63 | Standard_Boolean PCDM_ReferenceIterator::More() const { |
64 | return myIterator <= myReferences.Length(); |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : Next |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | void PCDM_ReferenceIterator::Next() { |
73 | myIterator++; |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : MetaData |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) const { |
82 | |
83 | TCollection_ExtendedString theFolder,theName; |
84 | TCollection_ExtendedString theFile=myReferences(myIterator).FileName(); |
85 | TCollection_ExtendedString f(theFile); |
86 | #ifndef WNT |
87 | |
88 | Standard_Integer i= f.SearchFromEnd("/"); |
89 | TCollection_ExtendedString n = f.Split(i); |
90 | f.Trunc(f.Length()-1); |
91 | theFolder = f; |
92 | theName = n; |
93 | #else |
94 | OSD_Path p = UTL::Path(f); |
95 | Standard_ExtCharacter chr; |
96 | TCollection_ExtendedString dir, dirRet, name; |
97 | |
98 | dir = UTL::Disk(p); |
99 | dir += UTL::Trek(p); |
100 | |
101 | for ( int i = 1; i <= dir.Length (); ++i ) { |
102 | |
103 | chr = dir.Value ( i ); |
104 | |
105 | switch ( chr ) { |
106 | |
107 | case _TEXT( '|' ): |
108 | dirRet += _TEXT( "/" ); |
109 | break; |
110 | |
111 | case _TEXT( '^' ): |
112 | |
113 | dirRet += _TEXT( ".." ); |
114 | break; |
115 | |
116 | default: |
117 | dirRet += chr; |
118 | |
119 | } |
120 | } |
121 | theFolder = dirRet; |
122 | theName = UTL::Name(p); theName+= UTL::Extension(p); |
123 | #endif // WNT |
124 | |
125 | return CDM_MetaData::LookUp(theFolder,theName,theFile,theFile,UTL::IsReadOnly(theFile)); |
126 | } |
127 | //======================================================================= |
128 | //function : ReferenceIdentifier |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | Standard_Integer PCDM_ReferenceIterator::ReferenceIdentifier() const { |
133 | return myReferences(myIterator).ReferenceIdentifier(); |
134 | } |
135 | //======================================================================= |
136 | //function : DocumentVersion |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | Standard_Integer PCDM_ReferenceIterator::DocumentVersion() const { |
141 | return myReferences(myIterator).DocumentVersion(); |
142 | } |