update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpobjid.cxx
blob12711d5a703e11f098798bf1096b67de6bd56be4
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
56 * @file
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Jan 2005 Created
62 ************************************************************************/
65 #ifndef _LWPOBJECTID_HXX
66 #include "lwpobjid.hxx"
67 #endif
69 #include "lwpfilehdr.hxx"
70 #include "lwpobjfactory.hxx"
71 #include "lwpglobalmgr.hxx"
73 LwpObjectID::LwpObjectID(sal_uInt32 low, sal_uInt16 high)
74 :m_nLow(low), m_nHigh(high), m_bIsCompressed(sal_False), m_nIndex(0)
77 /**
78 * @descr Read object id with format: low(4bytes)+high(2bytes) from stream
79 * for LWP7 record
81 sal_uInt32 LwpObjectID::Read(LwpSvStream *pStrm)
83 pStrm->Read(&m_nLow, sizeof(m_nLow));
84 pStrm->Read(&m_nHigh, sizeof(m_nHigh));
85 return DiskSize();
87 /**
88 * @descr Read object id with format: low(4bytes)+high(2bytes) from object stream
90 sal_uInt32 LwpObjectID::Read(LwpObjectStream *pObj)
92 pObj->QuickRead(&m_nLow, sizeof(m_nLow));
93 pObj->QuickRead(&m_nHigh, sizeof(m_nHigh));
94 return DiskSize();
96 /**
97 * @descr Read object id with indexed format from stream
98 * if index>0, lowid is get from time table per the index
99 * else index+lowid+highid
101 sal_uInt32 LwpObjectID::ReadIndexed(LwpSvStream *pStrm)
103 //note the m_nLow store the index instead of time from the timetable as in LWP
104 m_bIsCompressed = sal_False;
105 if( LwpFileHeader::m_nFileRevision < 0x000B)
107 return Read(pStrm);
110 pStrm->Read(&m_nIndex, sizeof(m_nIndex));
112 if (m_nIndex)
114 m_bIsCompressed = sal_True;
115 //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
116 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
117 LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
118 LwpIndexManager* pIdxMgr = pFactory->GetIndexManager();
119 m_nLow = pIdxMgr->GetObjTime( (sal_uInt16)m_nIndex);
121 else
123 pStrm->Read(&m_nLow, sizeof(m_nLow));
125 pStrm->Read(&m_nHigh, sizeof(m_nHigh));
126 return DiskSizeIndexed();
130 * @descr Read object id with indexed format from object stream
131 * if index>0, lowid is get from time table per the index
132 * else index+lowid+highid
134 sal_uInt32 LwpObjectID::ReadIndexed(LwpObjectStream *pStrm)
136 m_bIsCompressed = sal_False;
137 if(LwpFileHeader::m_nFileRevision < 0x000B)
139 return Read(pStrm);
142 pStrm->QuickRead(&m_nIndex, sizeof(m_nIndex));
143 if (m_nIndex)
145 m_bIsCompressed = sal_True;
146 //m_nLow = index; //note the m_nLow stores the index instead of the actual time id
147 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
148 LwpObjectFactory* pFactory = pGlobal->GetLwpObjFactory();
149 LwpIndexManager* pIdxMgr = pFactory->GetIndexManager();
150 m_nLow = pIdxMgr->GetObjTime( (sal_uInt16)m_nIndex);
152 else
154 pStrm->QuickRead(&m_nLow, sizeof(m_nLow));
156 pStrm->QuickRead(&m_nHigh, sizeof(m_nHigh));
157 return DiskSizeIndexed();
160 * @descr Read object id with compressed format from stream
161 * if diff == 255: 255+lowid+highid
162 * else lowid equals to the lowid of previous low id
163 * and high id = the high id of previous id + diff +1
165 sal_uInt32 LwpObjectID::ReadCompressed( LwpSvStream* pStrm, LwpObjectID &prev )
167 sal_uInt32 len=0;
168 sal_uInt8 diff;
170 len = pStrm->Read( &diff, sizeof(diff));
171 if (diff == 255)
173 len += Read(pStrm);
175 else
177 m_nLow = prev.GetLow();
178 m_nHigh = prev.GetHigh() + diff +1;
180 return len;
183 * @descr Read object id with compressed format from object stream
184 * if diff == 255: 255+lowid+highid
185 * else lowid equals to the lowid of previous low id
186 * and high id = the high id of previous id + diff +1
188 sal_uInt32 LwpObjectID::ReadCompressed( LwpObjectStream* pObj, LwpObjectID &prev )
191 sal_uInt32 len=0;
192 sal_uInt8 diff;
194 len += pObj->QuickRead( &diff, sizeof(diff));
196 if (diff == 255)
198 len += Read(pObj);
200 else
202 m_nLow = prev.GetLow();
203 m_nHigh = prev.GetHigh() + diff +1;
205 return len;
208 * @descr return the size of indexed object id
210 sal_uInt32 LwpObjectID::DiskSizeIndexed() const
212 return sizeof(sal_uInt8)
213 + (((0 < m_nIndex) && (m_nIndex <= 255)) ? 0 : sizeof(m_nLow))
214 + sizeof(m_nHigh);
217 * @descr return the size of object id with format: low(4bytes)+high(2bytes)
219 sal_uInt32 LwpObjectID::DiskSize() const
221 return sizeof(m_nLow) + sizeof(m_nHigh);
224 * @descr get object from object factory per the object id
226 LwpObject* LwpObjectID::obj(VO_TYPE tag) const
228 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
229 LwpObjectFactory* pObjMgr = pGlobal->GetLwpObjFactory();
230 if(IsNull())
232 return NULL;
234 LwpObject* pObj = pObjMgr->QueryObject(*this);
235 if( tag!=VO_INVALID && (pObj) )
237 if(tag!=pObj->GetTag())
239 pObj=NULL;
242 return(pObj);
245 * @descr returns a buffer that contains the highid + lowid
247 sal_Char* LwpObjectID::GetBuffer(sal_Char *buf)
249 buf[0] = m_nHigh && 0xFF00;
250 buf[1] = m_nHigh && 0x00FF;
251 buf[2] = m_nLow && 0xFF000000;
252 buf[3] = m_nLow && 0x00FF0000;
253 buf[4] = m_nLow && 0x0000FF00;
254 buf[5] = m_nLow && 0x000000FF;
255 return buf;