Skip to content

Commit

Permalink
changing names and init inline
Browse files Browse the repository at this point in the history
inline default initialization of all those member variables would be better.
and using the m_ prefixing for all of them would also be better for consistency

inline initialization will only work for primitive types though (pointers, integers, doubles, etc). For the C structures like struct MiraMonVectLayerInfo hMiraMonLayerPNT/ARC/POL/etc, memset() to 0 in the constructor is the only practical way
  • Loading branch information
AbelPau committed Apr 4, 2024
1 parent 8e976f6 commit 9679657
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/miramon/ogrmiramon.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class OGRMiraMonLayer final
: public OGRLayer,
public OGRGetNextFeatureThroughRaw<OGRMiraMonLayer>
{
GDALDataset *m_poDS = nullptr;
OGRSpatialReference *m_poSRS = nullptr;
OGRFeatureDefn *poFeatureDefn;
GDALDataset *m_poDS;
OGRSpatialReference *m_poSRS;
OGRFeatureDefn *m_poFeatureDefn;

GUIntBig iNextFID;
GUIntBig m_iNextFID;

// Pointer to one of three possible MiraMon layers: points,
// arcs or polygons. Every time a feature is read this pointer
Expand Down
97 changes: 49 additions & 48 deletions ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
VSILFILE *fp, const OGRSpatialReference *poSRS,
int bUpdateIn, CSLConstList papszOpenOptions,
struct MiraMonVectMapInfo *MMMap)
: m_poDS(poDS), poFeatureDefn(nullptr), iNextFID(0),
: m_poDS(poDS), m_poSRS(nullptr), m_poFeatureDefn(nullptr), m_iNextFID(0),
phMiraMonLayer(nullptr), hMiraMonLayerPNT(), hMiraMonLayerARC(),
hMiraMonLayerPOL(), hMiraMonLayerReadOrNonGeom(), hMMFeature(),
bUpdate(CPL_TO_BOOL(bUpdateIn)), nMMMemoryRatio(1.0),
Expand All @@ -50,9 +50,9 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
/* -------------------------------------------------------------------- */
/* Create the feature definition */
/* -------------------------------------------------------------------- */
poFeatureDefn = new OGRFeatureDefn(CPLGetBasename(pszFilename));
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->Reference();
m_poFeatureDefn = new OGRFeatureDefn(CPLGetBasename(pszFilename));
SetDescription(m_poFeatureDefn->GetName());
m_poFeatureDefn->Reference();

if (bUpdate)
{
Expand Down Expand Up @@ -182,7 +182,7 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,

// This helps the map to be created
//GetLayerDefn()->SetName(hMiraMonLayerPNT.pszSrcLayerName);
poFeatureDefn->SetName(hMiraMonLayerPNT.pszSrcLayerName);
m_poFeatureDefn->SetName(hMiraMonLayerPNT.pszSrcLayerName);
}

// Saving the HRS in the layer structure
Expand Down Expand Up @@ -237,33 +237,33 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
if (phMiraMonLayer->bIsPoint)
{
if (phMiraMonLayer->TopHeader.bIs3d)
poFeatureDefn->SetGeomType(wkbPoint25D);
m_poFeatureDefn->SetGeomType(wkbPoint25D);
else
poFeatureDefn->SetGeomType(wkbPoint);
m_poFeatureDefn->SetGeomType(wkbPoint);
}
else if (phMiraMonLayer->bIsArc && !phMiraMonLayer->bIsPolygon)
{
if (phMiraMonLayer->TopHeader.bIs3d)
poFeatureDefn->SetGeomType(wkbLineString25D);
m_poFeatureDefn->SetGeomType(wkbLineString25D);
else
poFeatureDefn->SetGeomType(wkbLineString);
m_poFeatureDefn->SetGeomType(wkbLineString);
}
else if (phMiraMonLayer->bIsPolygon)
{
// 3D
if (phMiraMonLayer->TopHeader.bIs3d)
{
if (phMiraMonLayer->TopHeader.bIsMultipolygon)
poFeatureDefn->SetGeomType(wkbMultiPolygon25D);
m_poFeatureDefn->SetGeomType(wkbMultiPolygon25D);
else
poFeatureDefn->SetGeomType(wkbPolygon25D);
m_poFeatureDefn->SetGeomType(wkbPolygon25D);
}
else
{
if (phMiraMonLayer->TopHeader.bIsMultipolygon)
poFeatureDefn->SetGeomType(wkbMultiPolygon);
m_poFeatureDefn->SetGeomType(wkbMultiPolygon);
else
poFeatureDefn->SetGeomType(wkbPolygon);
m_poFeatureDefn->SetGeomType(wkbPolygon);
}
}
else
Expand Down Expand Up @@ -334,7 +334,8 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
m_poSRS = nullptr;
}
else
poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(m_poSRS);
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(
m_poSRS);
}

// If there is associated information
Expand Down Expand Up @@ -485,7 +486,7 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
oField.SetPrecision(phMiraMonLayer->pMMBDXP->pField[nIField]
.DecimalsIfFloat);

poFeatureDefn->AddFieldDefn(&oField);
m_poFeatureDefn->AddFieldDefn(&oField);
}
}
}
Expand All @@ -501,11 +502,11 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
OGRMiraMonLayer::~OGRMiraMonLayer()

{
if (m_nFeaturesRead > 0 && poFeatureDefn != nullptr)
if (m_nFeaturesRead > 0 && m_poFeatureDefn != nullptr)
{
CPLDebugOnly("MiraMon", "%d features read on layer '%s'.",
static_cast<int>(m_nFeaturesRead),
poFeatureDefn->GetName());
m_poFeatureDefn->GetName());
}

if (hMiraMonLayerPOL.bIsPolygon)
Expand Down Expand Up @@ -667,8 +668,8 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
/* Clean up. */
/* -------------------------------------------------------------------- */

if (poFeatureDefn)
poFeatureDefn->Release();
if (m_poFeatureDefn)
m_poFeatureDefn->Release();

if (m_poSRS)
m_poSRS->Release();
Expand All @@ -687,10 +688,10 @@ OGRMiraMonLayer::~OGRMiraMonLayer()
void OGRMiraMonLayer::ResetReading()

{
if (iNextFID == 0)
if (m_iNextFID == 0)
return;

iNextFID = 0;
m_iNextFID = 0;

//VSIFSeekL(m_fp, 0, SEEK_SET);
if (!phMiraMonLayer)
Expand Down Expand Up @@ -744,15 +745,15 @@ OGRFeature *OGRMiraMonLayer::GetNextRawFeature()
if (!phMiraMonLayer)
return nullptr;

if (iNextFID >= (GUInt64)phMiraMonLayer->TopHeader.nElemCount)
if (m_iNextFID >= (GUInt64)phMiraMonLayer->TopHeader.nElemCount)
return nullptr;

OGRFeature *poFeature = GetFeature(iNextFID);
OGRFeature *poFeature = GetFeature(m_iNextFID);

if (!poFeature)
return nullptr;

iNextFID++;
m_iNextFID++;
return poFeature;
}

Expand Down Expand Up @@ -994,7 +995,7 @@ OGRFeature *OGRMiraMonLayer::GetFeature(GIntBig nFeatureId)
/* -------------------------------------------------------------------- */
/* Create feature. */
/* -------------------------------------------------------------------- */
auto poFeature = std::make_unique<OGRFeature>(poFeatureDefn);
auto poFeature = std::make_unique<OGRFeature>(m_poFeatureDefn);
if (poGeom)
{
poGeom->assignSpatialReference(m_poSRS);
Expand Down Expand Up @@ -1852,7 +1853,7 @@ OGRErr OGRMiraMonLayer::MMWriteGeometry()
OGRErr OGRMiraMonLayer::TranslateFieldsToMM()

{
if (poFeatureDefn->GetFieldCount() == 0)
if (m_poFeatureDefn->GetFieldCount() == 0)
return OGRERR_NONE;

CPLDebugOnly("MiraMon", "Translating fields to MiraMon...");
Expand All @@ -1867,7 +1868,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()

phMiraMonLayer->pLayerDB->pFields =
static_cast<struct MiraMonDataBaseField *>(
CPLCalloc(poFeatureDefn->GetFieldCount(),
CPLCalloc(m_poFeatureDefn->GetFieldCount(),
sizeof(*(phMiraMonLayer->pLayerDB->pFields))));
if (!phMiraMonLayer->pLayerDB->pFields)
return OGRERR_NOT_ENOUGH_MEMORY;
Expand All @@ -1876,13 +1877,13 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
if (phMiraMonLayer->pLayerDB->pFields)
{
memset(phMiraMonLayer->pLayerDB->pFields, 0,
poFeatureDefn->GetFieldCount() *
m_poFeatureDefn->GetFieldCount() *
sizeof(*phMiraMonLayer->pLayerDB->pFields));
for (MM_EXT_DBF_N_FIELDS iField = 0;
iField < (MM_EXT_DBF_N_FIELDS)poFeatureDefn->GetFieldCount();
iField < (MM_EXT_DBF_N_FIELDS)m_poFeatureDefn->GetFieldCount();
iField++)
{
switch (poFeatureDefn->GetFieldDefn(iField)->GetType())
switch (m_poFeatureDefn->GetFieldDefn(iField)->GetType())
{
case OFTInteger:
case OFTIntegerList:
Expand All @@ -1908,7 +1909,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
MM_Numeric;
phMiraMonLayer->pLayerDB->pFields[iField]
.nNumberOfDecimals =
poFeatureDefn->GetFieldDefn(iField)->GetPrecision();
m_poFeatureDefn->GetFieldDefn(iField)->GetPrecision();
break;

case OFTBinary:
Expand All @@ -1934,14 +1935,14 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
MM_Character;
break;
}
if (poFeatureDefn->GetFieldDefn(iField)->GetType() == OFTDate)
if (m_poFeatureDefn->GetFieldDefn(iField)->GetType() == OFTDate)
phMiraMonLayer->pLayerDB->pFields[iField].nFieldSize = 8;
else
{
if (poFeatureDefn->GetFieldDefn(iField)->GetPrecision() == 0)
if (m_poFeatureDefn->GetFieldDefn(iField)->GetPrecision() == 0)
{
phMiraMonLayer->pLayerDB->pFields[iField].nFieldSize =
poFeatureDefn->GetFieldDefn(iField)->GetWidth();
m_poFeatureDefn->GetFieldDefn(iField)->GetWidth();
if (phMiraMonLayer->pLayerDB->pFields[iField].nFieldSize ==
0)
phMiraMonLayer->pLayerDB->pFields[iField].nFieldSize =
Expand All @@ -1951,19 +1952,19 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
{
// One more space for the "."
phMiraMonLayer->pLayerDB->pFields[iField].nFieldSize =
(unsigned int)(poFeatureDefn->GetFieldDefn(iField)
(unsigned int)(m_poFeatureDefn->GetFieldDefn(iField)
->GetWidth() +
1);
}
}

if (poFeatureDefn->GetFieldDefn(iField)->GetNameRef())
if (m_poFeatureDefn->GetFieldDefn(iField)->GetNameRef())
{
// Interlis 1 encoding is ISO 8859-1 (Latin1) -> Recode from UTF-8
if (phMiraMonLayer->nCharSet != MM_JOC_CARAC_UTF8_DBF)
{
char *pszString = CPLRecode(
poFeatureDefn->GetFieldDefn(iField)->GetNameRef(),
m_poFeatureDefn->GetFieldDefn(iField)->GetNameRef(),
CPL_ENC_UTF8, CPL_ENC_ISO8859_1);
MM_strnzcpy(
phMiraMonLayer->pLayerDB->pFields[iField].pszFieldName,
Expand All @@ -1974,17 +1975,17 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
{
MM_strnzcpy(
phMiraMonLayer->pLayerDB->pFields[iField].pszFieldName,
poFeatureDefn->GetFieldDefn(iField)->GetNameRef(),
m_poFeatureDefn->GetFieldDefn(iField)->GetNameRef(),
MM_MAX_LON_FIELD_NAME_DBF);
}
}

if (poFeatureDefn->GetFieldDefn(iField)->GetAlternativeNameRef())
if (m_poFeatureDefn->GetFieldDefn(iField)->GetAlternativeNameRef())
{
if (phMiraMonLayer->nCharSet != MM_JOC_CARAC_UTF8_DBF)
{
char *pszString =
CPLRecode(poFeatureDefn->GetFieldDefn(iField)
CPLRecode(m_poFeatureDefn->GetFieldDefn(iField)
->GetAlternativeNameRef(),
CPL_ENC_UTF8, CPL_ENC_ISO8859_1);
MM_strnzcpy(phMiraMonLayer->pLayerDB->pFields[iField]
Expand All @@ -1996,7 +1997,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
{
MM_strnzcpy(phMiraMonLayer->pLayerDB->pFields[iField]
.pszFieldDescription,
poFeatureDefn->GetFieldDefn(iField)
m_poFeatureDefn->GetFieldDefn(iField)
->GetAlternativeNameRef(),
MM_MAX_BYTES_FIELD_DESC);
}
Expand All @@ -2018,21 +2019,21 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)

{
if (poFeatureDefn->GetFieldCount() == 0)
if (m_poFeatureDefn->GetFieldCount() == 0)
{
// MiraMon have private DataBase records
hMMFeature.nNumMRecords = 1;
return OGRERR_NONE;
}

MM_EXT_DBF_N_MULTIPLE_RECORDS nIRecord;
int nNumFields = poFeatureDefn->GetFieldCount();
int nNumFields = m_poFeatureDefn->GetFieldCount();
MM_EXT_DBF_N_MULTIPLE_RECORDS nNumRecords;
hMMFeature.nNumMRecords = 0;

for (int iField = 0; iField < nNumFields; iField++)
{
OGRFieldType eFType = poFeatureDefn->GetFieldDefn(iField)->GetType();
OGRFieldType eFType = m_poFeatureDefn->GetFieldDefn(iField)->GetType();
const char *pszRawValue = poFeature->GetFieldAsString(iField);

if (eFType == OFTStringList)
Expand All @@ -2052,7 +2053,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
for (nIRecord = 0; nIRecord < hMMFeature.nNumMRecords; nIRecord++)
{
hMMFeature.pRecords[nIRecord].nNumField =
poFeatureDefn->GetFieldCount();
m_poFeatureDefn->GetFieldCount();

if (MMResizeMiraMonFieldValue(
&(hMMFeature.pRecords[nIRecord].pField),
Expand Down Expand Up @@ -2394,7 +2395,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
/****************************************************************************/
OGRFeatureDefn *OGRMiraMonLayer::GetLayerDefn()
{
return poFeatureDefn;
return m_poFeatureDefn;
}

/****************************************************************************/
Expand Down Expand Up @@ -2483,7 +2484,7 @@ OGRErr OGRMiraMonLayer::CreateField(const OGRFieldDefn *poField, int bApproxOK)
case OFTString:
case OFTStringList:
case OFTDate:
poFeatureDefn->AddFieldDefn(poField);
m_poFeatureDefn->AddFieldDefn(poField);
return OGRERR_NONE;
default:
if (!bApproxOK)
Expand All @@ -2498,7 +2499,7 @@ OGRErr OGRMiraMonLayer::CreateField(const OGRFieldDefn *poField, int bApproxOK)
{
OGRFieldDefn oModDef(poField);
oModDef.SetType(OFTString);
poFeatureDefn->AddFieldDefn(poField);
m_poFeatureDefn->AddFieldDefn(poField);
return OGRERR_NONE;
}
}
Expand Down

0 comments on commit 9679657

Please sign in to comment.