CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
IdArraysIO.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _IDARRAYREAD_H_
25#define _IDARRAYREAD_H_
26
27namespace OdDbId
28{
29 // Note: Direct using of ids.resize(pFiler->rdInt32())
30 // produce memory allocation error in case of invalid size value.
31 // So read data in parts to get exception with invalid data.
32#define ODA_IDREAD_PAGESIZE 0xffff
33
34
35
37// This is workaround for MSVC 6 bug: http://support.microsoft.com/kb/240871
38// "If all the template parameters are not used in function arguments or return type
39// of a template function, the template functions are not overloaded correctly."
40// ODA defect 5270
41
42#if (defined (_MSC_VER) && _MSC_VER == 1200)
43 #define TEMPLATE_FUNC_RET_TYPE R*
44 #define TEMPLATE_FUNC_RETURN return 0;
45#else
46 #define TEMPLATE_FUNC_RET_TYPE void
47 #define TEMPLATE_FUNC_RETURN
48#endif
49
50 template< class R, class A>
51 inline TEMPLATE_FUNC_RET_TYPE rdArray(OdDbDwgFiler* pFiler, A& ids, bool bSkipDuplicates = false)
52 {
53 OdUInt32 nIdsSize = pFiler->rdInt32();
54 if (pFiler->filerType() != OdDbFiler::kFileFiler)
55 {
56 ids.resize(nIdsSize);
57 typename A::iterator pCurr = ids.begin();
58 for (unsigned i = 0; i < nIdsSize; ++i)
59 {
60 OdDbObjectId id = R::read(pFiler);
61 *pCurr++ = id;
62 }
63 }
64 else
65 {
66 ids.resize(0);
67 OdUInt32 nIdsPagedSize = 0, nIndex = 0;
68 if (!bSkipDuplicates)
69 {
70 do
71 {
72 nIdsPagedSize = odmin(nIdsPagedSize + ODA_IDREAD_PAGESIZE, nIdsSize);
73 ids.reserve(nIdsPagedSize);
74 for ( ; nIndex < nIdsPagedSize; ++nIndex)
75 {
76 OdDbObjectId id = R::read(pFiler);
77 if (!id.isNull())
78 ids.append(id);
79 }
80 }
81 while (nIdsPagedSize < nIdsSize);
82 }
83 else
84 {
85 do
86 {
87 nIdsPagedSize = odmin(nIdsPagedSize + ODA_IDREAD_PAGESIZE, nIdsSize);
88 ids.reserve(nIdsPagedSize);
89 for ( ; nIndex < nIdsPagedSize; ++nIndex)
90 {
91 OdDbObjectId id = R::read(pFiler);
92 if (!id.isNull() && !ids.contains(id))
93 ids.append(id);
94 }
95 }
96 while (nIdsPagedSize < nIdsSize);
97 }
98 }
100 }
101
102 template< class R, class A>
103 inline TEMPLATE_FUNC_RET_TYPE wrArray(OdDbDwgFiler* pFiler, const A& ids)
104 {
105 typename A::const_iterator pCurr = ids.begin();
106 unsigned long i = ids.size();
107
108 if ( pFiler->filerType() != OdDbFiler::kFileFiler )
109 {
110 pFiler->wrInt32(ids.size());
111 while ( i-- )
112 R::write(pFiler, *pCurr++);
113 }
114 else
115 {
116 unsigned long count = 0;
117 while ( i-- )
118 {
119 if ( !pCurr->isErased() )
120 {
121 R::write(pFiler, *pCurr);
122 count++;
123 }
124 ++pCurr;
125 }
126 pFiler->wrInt32(count);
127 }
129 }
130
132 {
134 {
135 return pFiler->rdHardPointerId();
136 }
137 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
138 {
139 pFiler->wrHardPointerId( id );
140 }
141 };
143 {
145 {
146 return pFiler->rdSoftPointerId();
147 }
148 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
149 {
150 pFiler->wrSoftPointerId( id );
151 }
152 };
154 {
156 {
157 return pFiler->rdHardOwnershipId();
158 }
159 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
160 {
161 pFiler->wrHardOwnershipId( id );
162 }
163 };
165 {
167 {
168 return pFiler->rdSoftOwnershipId();
169 }
170 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
171 {
172 pFiler->wrSoftOwnershipId( id );
173 }
174 };
175}
176
177#endif //_IDARRAYREAD_H_
#define TEMPLATE_FUNC_RET_TYPE
Definition: IdArraysIO.h:46
#define ODA_IDREAD_PAGESIZE
Definition: IdArraysIO.h:32
#define TEMPLATE_FUNC_RETURN
Definition: IdArraysIO.h:47
#define odmin(X, Y)
Definition: OdPlatform.h:34
unsigned int OdUInt32
virtual void wrInt32(OdInt32 value)=0
virtual void wrHardOwnershipId(const OdDbObjectId &value)=0
virtual void wrHardPointerId(const OdDbObjectId &value)=0
virtual OdInt32 rdInt32()=0
virtual OdDbObjectId rdSoftPointerId()=0
virtual void wrSoftOwnershipId(const OdDbObjectId &value)=0
virtual OdDbObjectId rdHardOwnershipId()=0
virtual void wrSoftPointerId(const OdDbObjectId &value)=0
virtual OdDbObjectId rdSoftOwnershipId()=0
virtual OdDbObjectId rdHardPointerId()=0
virtual FilerType filerType() const =0
@ kFileFiler
Definition: DbFiler.h:82
GLsizei GLsizei * count
Definition: gles2_ext.h:276
TEMPLATE_FUNC_RET_TYPE rdArray(OdDbDwgFiler *pFiler, A &ids, bool bSkipDuplicates=false)
Definition: IdArraysIO.h:51
TEMPLATE_FUNC_RET_TYPE wrArray(OdDbDwgFiler *pFiler, const A &ids)
Definition: IdArraysIO.h:103
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition: IdArraysIO.h:155
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition: IdArraysIO.h:159
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition: IdArraysIO.h:137
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition: IdArraysIO.h:133
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition: IdArraysIO.h:170
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition: IdArraysIO.h:166
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition: IdArraysIO.h:148
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition: IdArraysIO.h:144