CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
IdArraysIO.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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
30namespace OdDbId
31{
32 // Note: Direct using of ids.resize(pFiler->rdInt32())
33 // produce memory allocation error in case of invalid size value.
34 // So read data in parts to get exception with invalid data.
35#define ODA_IDREAD_PAGESIZE 0xffff
36
37
38
40// This is workaround for MSVC 6 bug: http://support.microsoft.com/kb/240871
41// "If all the template parameters are not used in function arguments or return type
42// of a template function, the template functions are not overloaded correctly."
43// ODA defect 5270
44
45#if (defined (_MSC_VER) && _MSC_VER == 1200)
46 #define TEMPLATE_FUNC_RET_TYPE R*
47 #define TEMPLATE_FUNC_RETURN return 0;
48#else
49 #define TEMPLATE_FUNC_RET_TYPE void
50 #define TEMPLATE_FUNC_RETURN
51#endif
52
53 template< class R, class A>
54 inline TEMPLATE_FUNC_RET_TYPE rdArray(OdDbDwgFiler* pFiler, A& ids, bool bSkipDuplicates = false)
55 {
56 OdUInt32 nIdsSize = pFiler->rdInt32();
57 if (pFiler->filerType() != OdDbFiler::kFileFiler)
58 {
59 ids.resize(nIdsSize);
60 typename A::iterator pCurr = ids.begin();
61 for (unsigned i = 0; i < nIdsSize; ++i)
62 {
63 OdDbObjectId id = R::read(pFiler);
64 *pCurr++ = id;
65 }
66 }
67 else
68 {
69 ids.resize(0);
70 OdUInt32 nIdsPagedSize = 0, nIndex = 0;
71 if (!bSkipDuplicates)
72 {
73 do
74 {
75 nIdsPagedSize = odmin(nIdsPagedSize + ODA_IDREAD_PAGESIZE, nIdsSize);
76 ids.reserve(nIdsPagedSize);
77 for ( ; nIndex < nIdsPagedSize; ++nIndex)
78 {
79 OdDbObjectId id = R::read(pFiler);
80 if (!id.isNull())
81 ids.append(id);
82 }
83 }
84 while (nIdsPagedSize < nIdsSize);
85 }
86 else
87 {
88 do
89 {
90 nIdsPagedSize = odmin(nIdsPagedSize + ODA_IDREAD_PAGESIZE, nIdsSize);
91 ids.reserve(nIdsPagedSize);
92 for ( ; nIndex < nIdsPagedSize; ++nIndex)
93 {
94 OdDbObjectId id = R::read(pFiler);
95 if (!id.isNull() && !ids.contains(id))
96 ids.append(id);
97 }
98 }
99 while (nIdsPagedSize < nIdsSize);
100 }
101 }
103 }
104
105 template< class R, class A>
106 inline TEMPLATE_FUNC_RET_TYPE wrArray(OdDbDwgFiler* pFiler, const A& ids)
107 {
108 typename A::const_iterator pCurr = ids.begin();
109 unsigned long i = ids.size();
110
111 if ( pFiler->filerType() != OdDbFiler::kFileFiler )
112 {
113 pFiler->wrInt32(ids.size());
114 while ( i-- )
115 R::write(pFiler, *pCurr++);
116 }
117 else
118 {
119 unsigned long count = 0;
120 while ( i-- )
121 {
122 if ( !pCurr->isErased() )
123 {
124 R::write(pFiler, *pCurr);
125 count++;
126 }
127 ++pCurr;
128 }
129 pFiler->wrInt32(count);
130 }
132 }
133
135 {
137 {
138 return pFiler->rdHardPointerId();
139 }
140 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
141 {
142 pFiler->wrHardPointerId( id );
143 }
144 };
146 {
148 {
149 return pFiler->rdSoftPointerId();
150 }
151 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
152 {
153 pFiler->wrSoftPointerId( id );
154 }
155 };
157 {
159 {
160 return pFiler->rdHardOwnershipId();
161 }
162 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
163 {
164 pFiler->wrHardOwnershipId( id );
165 }
166 };
168 {
170 {
171 return pFiler->rdSoftOwnershipId();
172 }
173 static void write( OdDbDwgFiler* pFiler, const OdDbObjectId& id )
174 {
175 pFiler->wrSoftOwnershipId( id );
176 }
177 };
178}
179
180#endif //_IDARRAYREAD_H_
#define TEMPLATE_FUNC_RET_TYPE
Definition IdArraysIO.h:49
#define ODA_IDREAD_PAGESIZE
Definition IdArraysIO.h:35
#define TEMPLATE_FUNC_RETURN
Definition IdArraysIO.h:50
ODRX_CONSTEXPR const T & odmin(const T &a, const T &b)
Definition OdPlatform.h:64
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:83
GLsizei GLsizei * count
Definition gles2_ext.h:276
TEMPLATE_FUNC_RET_TYPE rdArray(OdDbDwgFiler *pFiler, A &ids, bool bSkipDuplicates=false)
Definition IdArraysIO.h:54
TEMPLATE_FUNC_RET_TYPE wrArray(OdDbDwgFiler *pFiler, const A &ids)
Definition IdArraysIO.h:106
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition IdArraysIO.h:158
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition IdArraysIO.h:162
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition IdArraysIO.h:140
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition IdArraysIO.h:136
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition IdArraysIO.h:173
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition IdArraysIO.h:169
static void write(OdDbDwgFiler *pFiler, const OdDbObjectId &id)
Definition IdArraysIO.h:151
static OdDbObjectId read(OdDbDwgFiler *pFiler)
Definition IdArraysIO.h:147