Skip to content

Commit f659bcc

Browse files
committed
frmts/iso8211: const correctness fixes
1 parent 2443461 commit f659bcc

File tree

12 files changed

+128
-90
lines changed

12 files changed

+128
-90
lines changed

frmts/adrg/adrgdataset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ ADRGDataset *ADRGDataset::OpenDataset(const char *pszGENFileName,
613613
}
614614
CPLDebug("ADRG", "BAD=%s", osBAD.c_str());
615615

616-
DDFSubfieldDefn *subfieldDefn = fieldDefn->GetSubfield(14);
616+
const DDFSubfieldDefn *subfieldDefn = fieldDefn->GetSubfield(14);
617617
if (!(strcmp(subfieldDefn->GetName(), "TIF") == 0 &&
618618
(subfieldDefn->GetFormat())[0] == 'A'))
619619
{

frmts/adrg/srpdataset.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ bool SRPDataset::GetFromRecord(const char *pszFileName, DDFRecord *record)
537537
if (field == nullptr)
538538
return false;
539539

540-
DDFFieldDefn *fieldDefn = field->GetFieldDefn();
541-
DDFSubfieldDefn *subfieldDefn = fieldDefn->FindSubfieldDefn("TSI");
540+
const DDFFieldDefn *fieldDefn = field->GetFieldDefn();
541+
const DDFSubfieldDefn *subfieldDefn =
542+
fieldDefn->FindSubfieldDefn("TSI");
542543
if (subfieldDefn == nullptr)
543544
return false;
544545

frmts/iso8211/8211dump.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int main(int nArgc, char **papszArgv)
177177
printf(">\n");
178178
for (int iSubField = 0; iSubField < nSubfieldCount; iSubField++)
179179
{
180-
DDFSubfieldDefn *poSubFieldDefn =
180+
const DDFSubfieldDefn *poSubFieldDefn =
181181
poFieldDefn->GetSubfield(iSubField);
182182
printf(" <DDFSubfieldDefn name=\"%s\" format=\"%s\"/>\n",
183183
poSubFieldDefn->GetName(), poSubFieldDefn->GetFormat());
@@ -204,8 +204,8 @@ int main(int nArgc, char **papszArgv)
204204
int nFieldCount = poRecord->GetFieldCount();
205205
for (int iField = 0; iField < nFieldCount; iField++)
206206
{
207-
DDFField *poField = poRecord->GetField(iField);
208-
DDFFieldDefn *poDefn = poField->GetFieldDefn();
207+
const DDFField *poField = poRecord->GetField(iField);
208+
const DDFFieldDefn *poDefn = poField->GetFieldDefn();
209209
const char *pszFieldName = poDefn->GetName();
210210
printf(" <DDFField name=\"%s\"", pszFieldName);
211211
if (poField->GetRepeatCount() > 1)
@@ -229,7 +229,7 @@ int main(int nArgc, char **papszArgv)
229229
iSubField < poDefn->GetSubfieldCount(); iSubField++)
230230
{
231231
int nBytesConsumed;
232-
DDFSubfieldDefn *poSubFieldDefn =
232+
const DDFSubfieldDefn *poSubFieldDefn =
233233
poDefn->GetSubfield(iSubField);
234234
const char *pszSubFieldName = poSubFieldDefn->GetName();
235235
printf(" <DDFSubfield name=\"%s\" ",

frmts/iso8211/8211view.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include <algorithm>
1717

18-
static void ViewRecordField(DDFField *poField);
19-
static int ViewSubfield(DDFSubfieldDefn *poSFDefn, const char *pachFieldData,
20-
int nBytesRemaining);
18+
static void ViewRecordField(const DDFField *poField);
19+
static int ViewSubfield(const DDFSubfieldDefn *poSFDefn,
20+
const char *pachFieldData, int nBytesRemaining);
2121

2222
/* **********************************************************************/
2323
/* main() */
@@ -79,7 +79,7 @@ int main(int nArgc, char **papszArgv)
7979
/* ------------------------------------------------------------ */
8080
for (int iField = 0; iField < poRecord->GetFieldCount(); iField++)
8181
{
82-
DDFField *poField = poRecord->GetField(iField);
82+
const DDFField *poField = poRecord->GetField(iField);
8383

8484
ViewRecordField(poField);
8585
}
@@ -92,10 +92,10 @@ int main(int nArgc, char **papszArgv)
9292
/* Dump the contents of a field instance in a record. */
9393
/* **********************************************************************/
9494

95-
static void ViewRecordField(DDFField *poField)
95+
static void ViewRecordField(const DDFField *poField)
9696

9797
{
98-
DDFFieldDefn *poFieldDefn = poField->GetFieldDefn();
98+
const DDFFieldDefn *poFieldDefn = poField->GetFieldDefn();
9999

100100
// Report general information about the field.
101101
printf(" Field %s: %s\n", poFieldDefn->GetName(),
@@ -121,7 +121,7 @@ static void ViewRecordField(DDFField *poField)
121121
/* -------------------------------------------------------- */
122122
for (int iSF = 0; iSF < poFieldDefn->GetSubfieldCount(); iSF++)
123123
{
124-
DDFSubfieldDefn *poSFDefn = poFieldDefn->GetSubfield(iSF);
124+
const DDFSubfieldDefn *poSFDefn = poFieldDefn->GetSubfield(iSF);
125125
int nBytesConsumed =
126126
ViewSubfield(poSFDefn, pachFieldData, nBytesRemaining);
127127

@@ -135,8 +135,8 @@ static void ViewRecordField(DDFField *poField)
135135
/* ViewSubfield() */
136136
/* **********************************************************************/
137137

138-
static int ViewSubfield(DDFSubfieldDefn *poSFDefn, const char *pachFieldData,
139-
int nBytesRemaining)
138+
static int ViewSubfield(const DDFSubfieldDefn *poSFDefn,
139+
const char *pachFieldData, int nBytesRemaining)
140140

141141
{
142142
int nBytesConsumed = 0;

frmts/iso8211/ddffield.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ void DDFField::Dump(FILE *fp)
131131
* by the application.
132132
*/
133133

134-
const char *DDFField::GetSubfieldData(DDFSubfieldDefn *poSFDefn,
135-
int *pnMaxBytes, int iSubfieldIndex)
134+
const char *DDFField::GetSubfieldData(const DDFSubfieldDefn *poSFDefn,
135+
int *pnMaxBytes, int iSubfieldIndex) const
136136

137137
{
138138
if (poSFDefn == nullptr)
@@ -149,7 +149,7 @@ const char *DDFField::GetSubfieldData(DDFSubfieldDefn *poSFDefn,
149149
{
150150
for (int iSF = 0; iSF < poDefn->GetSubfieldCount(); iSF++)
151151
{
152-
DDFSubfieldDefn *poThisSFDefn = poDefn->GetSubfield(iSF);
152+
const DDFSubfieldDefn *poThisSFDefn = poDefn->GetSubfield(iSF);
153153

154154
if (nDataSize <= iOffset)
155155
{
@@ -195,7 +195,7 @@ const char *DDFField::GetSubfieldData(DDFSubfieldDefn *poSFDefn,
195195
* for a demonstration of handling repeated fields properly.
196196
*/
197197

198-
int DDFField::GetRepeatCount()
198+
int DDFField::GetRepeatCount() const
199199

200200
{
201201
if (!poDefn->IsRepeating())
@@ -227,7 +227,7 @@ int DDFField::GetRepeatCount()
227227
const int iOffsetBefore = iOffset;
228228
for (int iSF = 0; iSF < poDefn->GetSubfieldCount(); iSF++)
229229
{
230-
DDFSubfieldDefn *poThisSFDefn = poDefn->GetSubfield(iSF);
230+
const DDFSubfieldDefn *poThisSFDefn = poDefn->GetSubfield(iSF);
231231

232232
int nBytesConsumed = 0;
233233
if (poThisSFDefn->GetWidth() > nDataSize - iOffset)
@@ -298,7 +298,7 @@ const char *DDFField::GetInstanceData(int nInstance, int *pnInstanceSize)
298298
/* -------------------------------------------------------------------- */
299299
int nBytesRemaining1 = 0;
300300
int nBytesRemaining2 = 0;
301-
DDFSubfieldDefn *poFirstSubfield = poDefn->GetSubfield(0);
301+
const DDFSubfieldDefn *poFirstSubfield = poDefn->GetSubfield(0);
302302

303303
const char *pachWrkData =
304304
GetSubfieldData(poFirstSubfield, &nBytesRemaining1, nInstance);
@@ -311,7 +311,7 @@ const char *DDFField::GetInstanceData(int nInstance, int *pnInstanceSize)
311311
/* -------------------------------------------------------------------- */
312312
if (pnInstanceSize != nullptr)
313313
{
314-
DDFSubfieldDefn *poLastSubfield =
314+
const DDFSubfieldDefn *poLastSubfield =
315315
poDefn->GetSubfield(poDefn->GetSubfieldCount() - 1);
316316

317317
const char *pachLastData =

frmts/iso8211/ddffielddefn.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ int DDFFieldDefn::ApplyFormats()
837837
* @return The subfield pointer, or NULL if there isn't any such subfield.
838838
*/
839839

840-
DDFSubfieldDefn *DDFFieldDefn::FindSubfieldDefn(const char *pszMnemonic)
840+
const DDFSubfieldDefn *
841+
DDFFieldDefn::FindSubfieldDefn(const char *pszMnemonic) const
841842

842843
{
843844
for (int i = 0; i < nSubfieldCount; i++)
@@ -863,7 +864,7 @@ DDFSubfieldDefn *DDFFieldDefn::FindSubfieldDefn(const char *pszMnemonic)
863864
* @return The subfield pointer, or NULL if the index is out of range.
864865
*/
865866

866-
DDFSubfieldDefn *DDFFieldDefn::GetSubfield(int i)
867+
const DDFSubfieldDefn *DDFFieldDefn::GetSubfield(int i) const
867868

868869
{
869870
if (i < 0 || i >= nSubfieldCount)

frmts/iso8211/ddfmodule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void DDFModule::Dump(FILE *fp)
526526
* the DDFModule, and should not be deleted by application code.
527527
*/
528528

529-
DDFFieldDefn *DDFModule::FindFieldDefn(const char *pszFieldName)
529+
const DDFFieldDefn *DDFModule::FindFieldDefn(const char *pszFieldName) const
530530

531531
{
532532
int i;

frmts/iso8211/ddfrecord.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ int DDFRecord::ReadHeader()
693693
* the next record read.
694694
*/
695695

696-
DDFField *DDFRecord::FindField(const char *pszName, int iFieldIndex)
696+
const DDFField *DDFRecord::FindField(const char *pszName, int iFieldIndex) const
697697

698698
{
699699
for (int i = 0; i < nFieldCount; i++)
700700
{
701-
DDFFieldDefn *poFieldDefn = paoFields[i].GetFieldDefn();
701+
const DDFFieldDefn *poFieldDefn = paoFields[i].GetFieldDefn();
702702
if (poFieldDefn && EQUAL(poFieldDefn->GetName(), pszName))
703703
{
704704
if (iFieldIndex == 0)
@@ -723,7 +723,7 @@ DDFField *DDFRecord::FindField(const char *pszName, int iFieldIndex)
723723
* @return A DDFField pointer, or NULL if the index is out of range.
724724
*/
725725

726-
DDFField *DDFRecord::GetField(int i)
726+
const DDFField *DDFRecord::GetField(int i) const
727727

728728
{
729729
if (i < 0 || i >= nFieldCount)
@@ -754,7 +754,7 @@ DDFField *DDFRecord::GetField(int i)
754754

755755
int DDFRecord::GetIntSubfield(const char *pszField, int iFieldIndex,
756756
const char *pszSubfield, int iSubfieldIndex,
757-
int *pnSuccess)
757+
int *pnSuccess) const
758758

759759
{
760760
int nDummyErr = FALSE;
@@ -767,14 +767,14 @@ int DDFRecord::GetIntSubfield(const char *pszField, int iFieldIndex,
767767
/* -------------------------------------------------------------------- */
768768
/* Fetch the field. If this fails, return zero. */
769769
/* -------------------------------------------------------------------- */
770-
DDFField *poField = FindField(pszField, iFieldIndex);
770+
const DDFField *poField = FindField(pszField, iFieldIndex);
771771
if (poField == nullptr)
772772
return 0;
773773

774774
/* -------------------------------------------------------------------- */
775775
/* Get the subfield definition */
776776
/* -------------------------------------------------------------------- */
777-
DDFSubfieldDefn *poSFDefn =
777+
const DDFSubfieldDefn *poSFDefn =
778778
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
779779
if (poSFDefn == nullptr)
780780
return 0;
@@ -839,14 +839,14 @@ double DDFRecord::GetFloatSubfield(const char *pszField, int iFieldIndex,
839839
/* -------------------------------------------------------------------- */
840840
/* Fetch the field. If this fails, return zero. */
841841
/* -------------------------------------------------------------------- */
842-
DDFField *poField = FindField(pszField, iFieldIndex);
842+
const DDFField *poField = FindField(pszField, iFieldIndex);
843843
if (poField == nullptr)
844844
return 0;
845845

846846
/* -------------------------------------------------------------------- */
847847
/* Get the subfield definition */
848848
/* -------------------------------------------------------------------- */
849-
DDFSubfieldDefn *poSFDefn =
849+
const DDFSubfieldDefn *poSFDefn =
850850
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
851851
if (poSFDefn == nullptr)
852852
return 0;
@@ -911,14 +911,14 @@ const char *DDFRecord::GetStringSubfield(const char *pszField, int iFieldIndex,
911911
/* -------------------------------------------------------------------- */
912912
/* Fetch the field. If this fails, return zero. */
913913
/* -------------------------------------------------------------------- */
914-
DDFField *poField = FindField(pszField, iFieldIndex);
914+
const DDFField *poField = FindField(pszField, iFieldIndex);
915915
if (poField == nullptr)
916916
return nullptr;
917917

918918
/* -------------------------------------------------------------------- */
919919
/* Get the subfield definition */
920920
/* -------------------------------------------------------------------- */
921-
DDFSubfieldDefn *poSFDefn =
921+
const DDFSubfieldDefn *poSFDefn =
922922
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
923923
if (poSFDefn == nullptr)
924924
return nullptr;
@@ -1635,7 +1635,7 @@ int DDFRecord::SetStringSubfield(const char *pszField, int iFieldIndex,
16351635
/* -------------------------------------------------------------------- */
16361636
/* Get the subfield definition */
16371637
/* -------------------------------------------------------------------- */
1638-
DDFSubfieldDefn *poSFDefn =
1638+
const DDFSubfieldDefn *poSFDefn =
16391639
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
16401640
if (poSFDefn == nullptr)
16411641
return FALSE;
@@ -1745,7 +1745,7 @@ int DDFRecord::SetIntSubfield(const char *pszField, int iFieldIndex,
17451745
/* -------------------------------------------------------------------- */
17461746
/* Get the subfield definition */
17471747
/* -------------------------------------------------------------------- */
1748-
DDFSubfieldDefn *poSFDefn =
1748+
const DDFSubfieldDefn *poSFDefn =
17491749
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
17501750
if (poSFDefn == nullptr)
17511751
return FALSE;
@@ -1853,7 +1853,7 @@ int DDFRecord::SetFloatSubfield(const char *pszField, int iFieldIndex,
18531853
/* -------------------------------------------------------------------- */
18541854
/* Get the subfield definition */
18551855
/* -------------------------------------------------------------------- */
1856-
DDFSubfieldDefn *poSFDefn =
1856+
const DDFSubfieldDefn *poSFDefn =
18571857
poField->GetFieldDefn()->FindSubfieldDefn(pszSubfield);
18581858
if (poSFDefn == nullptr)
18591859
return FALSE;

frmts/iso8211/ddfsubfielddefn.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void DDFSubfieldDefn::Dump(FILE *fp)
245245
*/
246246

247247
int DDFSubfieldDefn::GetDataLength(const char *pachSourceData, int nMaxBytes,
248-
int *pnConsumedBytes)
248+
int *pnConsumedBytes) const
249249

250250
{
251251
if (!bIsVariable)
@@ -363,6 +363,9 @@ int DDFSubfieldDefn::GetDataLength(const char *pachSourceData, int nMaxBytes,
363363
* types other than DDFString, including data past zero chars. This is
364364
* the standard way of extracting DDFBinaryString subfields for instance.<p>
365365
*
366+
* CAUTION: this method is not thread safe as it updates mutable member
367+
* variables.
368+
*
366369
* @param pachSourceData The pointer to the raw data for this field. This
367370
* may have come from DDFRecord::GetData(), taking into account skip factors
368371
* over previous subfields data.
@@ -383,7 +386,7 @@ int DDFSubfieldDefn::GetDataLength(const char *pachSourceData, int nMaxBytes,
383386

384387
const char *DDFSubfieldDefn::ExtractStringData(const char *pachSourceData,
385388
int nMaxBytes,
386-
int *pnConsumedBytes)
389+
int *pnConsumedBytes) const
387390

388391
{
389392
int nLength = GetDataLength(pachSourceData, nMaxBytes, pnConsumedBytes);
@@ -437,7 +440,8 @@ const char *DDFSubfieldDefn::ExtractStringData(const char *pachSourceData,
437440
*/
438441

439442
double DDFSubfieldDefn::ExtractFloatData(const char *pachSourceData,
440-
int nMaxBytes, int *pnConsumedBytes)
443+
int nMaxBytes,
444+
int *pnConsumedBytes) const
441445

442446
{
443447
switch (pszFormatString[0])
@@ -578,7 +582,7 @@ double DDFSubfieldDefn::ExtractFloatData(const char *pachSourceData,
578582
*/
579583

580584
int DDFSubfieldDefn::ExtractIntData(const char *pachSourceData, int nMaxBytes,
581-
int *pnConsumedBytes)
585+
int *pnConsumedBytes) const
582586

583587
{
584588
switch (pszFormatString[0])
@@ -703,7 +707,8 @@ int DDFSubfieldDefn::ExtractIntData(const char *pachSourceData, int nMaxBytes,
703707
* @param fp File to write report to.
704708
*/
705709

706-
void DDFSubfieldDefn::DumpData(const char *pachData, int nMaxBytes, FILE *fp)
710+
void DDFSubfieldDefn::DumpData(const char *pachData, int nMaxBytes,
711+
FILE *fp) const
707712

708713
{
709714
if (nMaxBytes < 0)

0 commit comments

Comments
 (0)