Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * For LWP filter architecture prototype
59 : ************************************************************************/
60 : /*************************************************************************
61 : * Change History
62 : Jan 2005 Created
63 : ************************************************************************/
64 :
65 : #include "lwpobjid.hxx"
66 : #include "lwpfilehdr.hxx"
67 : #include "lwpobjfactory.hxx"
68 : #include "lwpglobalmgr.hxx"
69 :
70 12306 : LwpObjectID::LwpObjectID(sal_uInt32 low, sal_uInt16 high)
71 12306 : :m_nLow(low), m_nHigh(high), m_nIndex(0), m_bIsCompressed(sal_False)
72 : {
73 12306 : }
74 : /**
75 : * @descr Read object id with format: low(4bytes)+high(2bytes) from stream
76 : * for LWP7 record
77 : */
78 12 : sal_uInt32 LwpObjectID::Read(LwpSvStream *pStrm)
79 : {
80 12 : *pStrm >> m_nLow;
81 12 : *pStrm >> m_nHigh;
82 12 : return DiskSize();
83 : }
84 : /**
85 : * @descr Read object id with format: low(4bytes)+high(2bytes) from object stream
86 : */
87 115 : sal_uInt32 LwpObjectID::Read(LwpObjectStream *pObj)
88 : {
89 115 : m_nLow = pObj->QuickReaduInt32();
90 115 : m_nHigh = pObj->QuickReaduInt16();
91 115 : return DiskSize();
92 : }
93 : /**
94 : * @descr Read object id with indexed format from stream
95 : * if index>0, lowid is get from time table per the index
96 : * else index+lowid+highid
97 : */
98 938 : sal_uInt32 LwpObjectID::ReadIndexed(LwpSvStream *pStrm)
99 : {
100 : //note the m_nLow store the index instead of time from the timetable as in LWP
101 938 : m_bIsCompressed = sal_False;
102 938 : if( LwpFileHeader::m_nFileRevision < 0x000B)
103 : {
104 0 : return Read(pStrm);
105 : }
106 :
107 938 : *pStrm >> m_nIndex;
108 :
109 938 : if (m_nIndex)
110 : {
111 920 : m_bIsCompressed = sal_True;
112 : //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
113 920 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
114 920 : LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
115 920 : LwpIndexManager* pIdxMgr = pFactory->GetIndexManager();
116 920 : m_nLow = pIdxMgr->GetObjTime( (sal_uInt16)m_nIndex);
117 : }
118 : else
119 : {
120 18 : *pStrm >> m_nLow;
121 : }
122 938 : *pStrm >> m_nHigh;
123 938 : return DiskSizeIndexed();
124 : }
125 :
126 : /**
127 : * @descr Read object id with indexed format from object stream
128 : * if index>0, lowid is get from time table per the index
129 : * else index+lowid+highid
130 : */
131 7097 : sal_uInt32 LwpObjectID::ReadIndexed(LwpObjectStream *pStrm)
132 : {
133 7097 : m_bIsCompressed = sal_False;
134 7097 : if(LwpFileHeader::m_nFileRevision < 0x000B)
135 : {
136 0 : return Read(pStrm);
137 : }
138 :
139 7097 : m_nIndex = pStrm->QuickReaduInt8();
140 7097 : if (m_nIndex)
141 : {
142 4767 : m_bIsCompressed = sal_True;
143 : //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
144 4767 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
145 4767 : LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
146 4767 : LwpIndexManager* pIdxMgr = pFactory->GetIndexManager();
147 4767 : m_nLow = pIdxMgr->GetObjTime( (sal_uInt16)m_nIndex);
148 : }
149 : else
150 2330 : m_nLow = pStrm->QuickReaduInt32();
151 7095 : m_nHigh = pStrm->QuickReaduInt16();
152 7095 : return DiskSizeIndexed();
153 : }
154 : /**
155 : * @descr Read object id with compressed format from object stream
156 : * if diff == 255: 255+lowid+highid
157 : * else lowid equals to the lowid of previous low id
158 : * and high id = the high id of previous id + diff +1
159 : */
160 2211 : sal_uInt32 LwpObjectID::ReadCompressed( LwpObjectStream* pObj, LwpObjectID &prev )
161 : {
162 2211 : sal_uInt8 diff = pObj->QuickReaduInt8();
163 2211 : sal_uInt32 len=1;
164 :
165 2211 : if (diff == 255)
166 : {
167 88 : len += Read(pObj);
168 : }
169 : else
170 : {
171 2123 : m_nLow = prev.GetLow();
172 2123 : m_nHigh = prev.GetHigh() + diff +1;
173 : }
174 2211 : return len;
175 : }
176 : /**
177 : * @descr return the size of indexed object id
178 : */
179 8971 : sal_uInt32 LwpObjectID::DiskSizeIndexed() const
180 : {
181 : return sizeof(sal_uInt8)
182 : + ((m_nIndex != 0) ? 0 : sizeof(m_nLow))
183 8971 : + sizeof(m_nHigh);
184 : }
185 : /**
186 : * @descr return the size of object id with format: low(4bytes)+high(2bytes)
187 : */
188 133 : sal_uInt32 LwpObjectID::DiskSize() const
189 : {
190 133 : return sizeof(m_nLow) + sizeof(m_nHigh);
191 : }
192 : /**
193 : * @descr get object from object factory per the object id
194 : */
195 13904 : LwpObject* LwpObjectID::obj(VO_TYPE tag) const
196 : {
197 13904 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
198 13904 : LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
199 13904 : if(IsNull())
200 : {
201 1497 : return NULL;
202 : }
203 12407 : LwpObject* pObj = pObjMgr->QueryObject(*this);
204 12404 : if( tag!=VO_INVALID && (pObj) )
205 : {
206 1915 : if(static_cast<sal_uInt32>(tag) != pObj->GetTag())
207 : {
208 9 : pObj=NULL;
209 : }
210 : }
211 12404 : return(pObj);
212 : }
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|