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 12240 : LwpObjectID::LwpObjectID(sal_uInt32 low, sal_uInt16 high)
71 12240 : :m_nLow(low), m_nHigh(high), m_nIndex(0), m_bIsCompressed(false)
72 : {
73 12240 : }
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->ReadUInt32( m_nLow );
81 12 : pStrm->ReadUInt16( 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 932 : 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 932 : m_bIsCompressed = false;
102 932 : if( LwpFileHeader::m_nFileRevision < 0x000B)
103 : {
104 0 : return Read(pStrm);
105 : }
106 :
107 932 : pStrm->ReadUInt8( m_nIndex );
108 :
109 932 : if (m_nIndex)
110 : {
111 914 : m_bIsCompressed = true;
112 : //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
113 914 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
114 914 : LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
115 914 : LwpIndexManager& rIdxMgr = pFactory->GetIndexManager();
116 914 : m_nLow = rIdxMgr.GetObjTime( (sal_uInt16)m_nIndex);
117 : }
118 : else
119 : {
120 18 : pStrm->ReadUInt32( m_nLow );
121 : }
122 932 : pStrm->ReadUInt16( m_nHigh );
123 932 : 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 7052 : sal_uInt32 LwpObjectID::ReadIndexed(LwpObjectStream *pStrm)
132 : {
133 7052 : m_bIsCompressed = false;
134 7052 : if(LwpFileHeader::m_nFileRevision < 0x000B)
135 : {
136 0 : return Read(pStrm);
137 : }
138 :
139 7052 : m_nIndex = pStrm->QuickReaduInt8();
140 7052 : if (m_nIndex)
141 : {
142 4737 : m_bIsCompressed = true;
143 : //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
144 4737 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
145 4737 : LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
146 4737 : LwpIndexManager& rIdxMgr = pFactory->GetIndexManager();
147 4737 : m_nLow = rIdxMgr.GetObjTime( (sal_uInt16)m_nIndex);
148 : }
149 : else
150 2315 : m_nLow = pStrm->QuickReaduInt32();
151 7050 : m_nHigh = pStrm->QuickReaduInt16();
152 7050 : 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 8914 : sal_uInt32 LwpObjectID::DiskSizeIndexed() const
180 : {
181 : return sizeof(sal_uInt8)
182 8914 : + ((m_nIndex != 0) ? 0 : sizeof(m_nLow))
183 17828 : + sizeof(m_nHigh);
184 : }
185 : /**
186 : * @descr get object from object factory per the object id
187 : */
188 13615 : rtl::Reference<LwpObject> LwpObjectID::obj(VO_TYPE tag) const
189 : {
190 13615 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
191 13615 : LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
192 13615 : if(IsNull())
193 : {
194 1447 : return NULL;
195 : }
196 12168 : rtl::Reference<LwpObject> pObj = pObjMgr->QueryObject(*this);
197 12165 : if( tag!=VO_INVALID && (pObj.is()) )
198 : {
199 1903 : if(static_cast<sal_uInt32>(tag) != pObj->GetTag())
200 : {
201 9 : pObj.clear();
202 : }
203 : }
204 12165 : return pObj;
205 : }
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|