Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CCDFDataModel/CCDFAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "CCDFTypes.h"
#include "CCDFAttribute.h"

void CDF::Attribute::setName(const char *value) { name.copy(value); }
void CDF::Attribute::setName(const char *value) { name = CT::fromCStr(value); }

CDF::Attribute::Attribute() {
data = NULL;
Expand All @@ -37,21 +37,21 @@ CDF::Attribute::Attribute(Attribute *att) {
data = NULL;
length = 0;

name.copy(&att->name);
name = att->name;
setData(att);
}

CDF::Attribute::Attribute(const char *attrName, const char *attrString) {
data = NULL;
length = 0;
name.copy(attrName);
name = CT::fromCStr(attrName);
setData(CDF_CHAR, attrString, strlen(attrString));
}

CDF::Attribute::Attribute(const char *attrName, CDFType type, const void *dataToSet, size_t dataLength) {
data = NULL;
length = 0;
name.copy(attrName);
name = CT::fromCStr(attrName);
setData(type, dataToSet, dataLength);
}

Expand Down
4 changes: 2 additions & 2 deletions CCDFDataModel/CCDFDimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace CDF {
Dimension(const char *_name, size_t _length) {
isIterative = false;
length = _length;
name.copy(_name);
name = CT::fromCStr(_name);
id = -1;
}
CT::string name;
Expand All @@ -47,7 +47,7 @@ namespace CDF {
int id;
size_t getSize() { return length; }
void setSize(size_t _length) { length = _length; }
void setName(const char *value) { name.copy(value); }
void setName(const char *value) { name = CT::fromCStr(value); }
CT::string getName() { return name; }
// Returns a new copy of this dimension
Dimension *clone() {
Expand Down
4 changes: 2 additions & 2 deletions CCDFDataModel/CCDFGeoJSONIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ int CDFGeoJSONReader::open(const char *fileName) {
CT::string fileBaseName;
const char *last = rindex(fileName, '/');
if ((last != NULL) && (*last)) {
fileBaseName.copy(last + 1);
fileBaseName = CT::fromCStr(last + 1);
} else {
fileBaseName.copy(fileName);
fileBaseName = CT::fromCStr(fileName);
}

if (!((strlen(fileName) > 4) || (strcmp("json", fileName + strlen(fileName - 4)) == 0))) {
Expand Down
2 changes: 1 addition & 1 deletion CCDFDataModel/CCDFNetCDFIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ int CDFNetCDFReader::readVariables(int groupId, CT::string *groupName, int mode)
status = readDimensions(groupId, groupName);
if (status != 0) return 1;
if (status != 0) {
CDBError("readDimensions failed for group [%s]", groupName);
CDBError("readDimensions failed for group [%s]", groupName->c_str());
return 1;
}
#ifdef MEASURETIME
Expand Down
16 changes: 8 additions & 8 deletions CCDFDataModel/CCDFObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int CDFObject::open(const char *fileName) {
return 1;
}
clear();
currentFile.copy(fileName);
currentFile = CT::fromCStr(fileName);
traceTimingsSpanStart(TraceTimingType::FSOPEN);
int status = r->open(fileName);
traceTimingsSpanEnd(TraceTimingType::FSOPEN);
Expand Down Expand Up @@ -147,7 +147,7 @@ void ncmlHandleAttribute(xmlNode *cur_node, CT::string NCMLVarName, CDFObject *c
// Rename an attribute
if (pszOrgName != NULL) {
try {
cdfObject->getVariable(NCMLVarName.c_str())->getAttribute(pszOrgName)->name.copy(pszAttributeName);
cdfObject->getVariable(NCMLVarName.c_str())->getAttribute(pszOrgName)->name = CT::fromCStr(pszAttributeName);
} catch (...) {
}
} else {
Expand All @@ -158,7 +158,7 @@ void ncmlHandleAttribute(xmlNode *cur_node, CT::string NCMLVarName, CDFObject *c
var = cdfObject->getVariable(NCMLVarName.c_str());
} catch (...) {
var = new CDF::Variable();
var->name.copy(NCMLVarName.c_str());
var->name = NCMLVarName.c_str();
cdfObject->addVariable(var);
}
CDFType attrType = cdfObject->ncmlTypeToCDFType(pszAttributeType);
Expand All @@ -173,7 +173,7 @@ void ncmlHandleAttribute(xmlNode *cur_node, CT::string NCMLVarName, CDFObject *c
attributeValuesAsDouble[attrN] = atof(attributeValues[attrN].c_str());
}
CDF::Attribute *attr = new CDF::Attribute();
attr->name.copy(pszAttributeName);
attr->name = CT::fromCStr(pszAttributeName);
var->addAttribute(attr);
attr->type = attrType;
CDF::allocateData(attrType, &attr->data, attrLen);
Expand Down Expand Up @@ -220,14 +220,14 @@ CT::string ncmlHandleVariable(xmlNode *cur_node, CDFObject *cdfObject) {
CDBError("Can not find variable '%s' to rename", pszOrgName);
throw(__LINE__);
}
var->name.copy(pszName);
var->name = CT::fromCStr(pszName);
}
if (pszName != NULL) {
auto var = cdfObject->getVariableNE(pszName);
if (var == NULL) {
var = new CDF::Variable();
var->currentType = CDF_CHAR;
var->name.copy(pszName);
var->name = CT::fromCStr(pszName);
cdfObject->addVariable(var);
}
/* Set type */
Expand Down Expand Up @@ -282,7 +282,7 @@ void ncmlHandleDimension(xmlNode *cur_node, CDFObject *cdfObject) {
if (pszOrgName != NULL && pszName != NULL) {
try {
CDF::Dimension *dim = cdfObject->getDimension(pszOrgName);
dim->name.copy(pszName);
dim->name = CT::fromCStr(pszName);
} catch (...) {
}
}
Expand All @@ -293,7 +293,7 @@ void ncmlHandleDimension(xmlNode *cur_node, CDFObject *cdfObject) {
} catch (...) {
if (pszOrgName == NULL) {
dim = new CDF::Dimension();
dim->name.copy(pszName);
dim->name = CT::fromCStr(pszName);
cdfObject->addDimension(dim);
if (pszLength != NULL) {
dim->setSize(atoi(pszLength));
Expand Down
2 changes: 1 addition & 1 deletion CCDFDataModel/CCDFObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CDFObject : public CDF::Variable {
public:
DEF_ERRORFUNCTION();
CDFObject() {
name.copy("NC_GLOBAL");
name = "NC_GLOBAL";
reader = NULL;
}
~CDFObject();
Expand Down
4 changes: 2 additions & 2 deletions CCDFDataModel/CCDFPNGIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ int CDFPNGReader::open(const char *fileName) {
CT::string fileBaseName;
const char *last = rindex(fileName, '/');
if ((last != NULL) && (*last)) {
fileBaseName.copy(last + 1);
fileBaseName = CT::fromCStr(last + 1);
} else {
fileBaseName.copy(fileName);
fileBaseName = CT::fromCStr(fileName);
}

/* Now always add a CRS variable */
Expand Down
6 changes: 3 additions & 3 deletions CCDFDataModel/CCDFVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,9 @@ bool CDF::Variable::isString(bool isString) {
}

void CDF::Variable::setName(const char *value) {
name.copy(value);
name = CT::fromCStr(value);
// TODO Implement this correctly in readvariabledata....
if (orgName.length() == 0) orgName.copy(value);
if (orgName.length() == 0) orgName = CT::fromCStr(value);
}

void CDF::Variable::setSize(size_t size) { currentSize = size; }
Expand Down Expand Up @@ -938,7 +938,7 @@ int CDF::Variable::setAttribute(const char *attrName, CDFType attrType, const vo
attr = getAttribute(attrName);
} catch (...) {
attr = new Attribute();
attr->name.copy(attrName);
attr->name = CT::fromCStr(attrName);
addAttribute(attr);
}
attr->type = attrType;
Expand Down
2 changes: 1 addition & 1 deletion CCDFDataModel/CCDFVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace CDF {
attr = getAttribute(attrName);
} catch (...) {
attr = new Attribute();
attr->name.copy(attrName);
attr->name = CT::fromCStr(attrName);
addAttribute(attr);
}
attr->type = attrType;
Expand Down
8 changes: 4 additions & 4 deletions CCDFDataModel/CProj4ToCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ int CProj4ToCF::convertProjToCF(CDF::Variable *projectionVariable, const char *p

std::vector<CKeyValuePair> projKVPList;
CT::string proj4CTString;
proj4CTString.copy(proj4String);
proj4CTString = CT::fromCStr(proj4String);
auto projElements = proj4CTString.splitToStack(" ");

if (projElements.size() < 2) {
Expand All @@ -404,9 +404,9 @@ int CProj4ToCF::convertProjToCF(CDF::Variable *projectionVariable, const char *p
auto element = projElement.splitToStack("=");
if (element.size() > 0) {
CT::string name, value;
name.copy(element[0]);
name = element[0];
if (element.size() > 1) {
value.copy(element[1]);
value = element[1];
}
if (name.startsWith("+")) {
name.substringSelf(1, -1);
Expand Down Expand Up @@ -497,7 +497,7 @@ int CProj4ToCF::convertProjToCF(CDF::Variable *projectionVariable, const char *p

CT::string CProj4ToCF::convertCFToProj(CDF::Variable *projectionVariable) {
CT::string proj4String;
proj4String.copy("Unsupported projection");
proj4String = "Unsupported projection";
try {
CT::string grid_mapping_name;
projectionVariable->getAttribute("grid_mapping_name")->getDataAsString(&grid_mapping_name);
Expand Down
12 changes: 6 additions & 6 deletions CCDFDataModel/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "utils.h"

CDFReader *findReaderByFileName(CT::string fileName) {
if (fileName.endsWith(".nc")) {
CDFReader *findReaderByFileName(const std::string &fileName) {
if (CT::endsWith(fileName, ".nc")) {
return new CDFNetCDFReader();
}
if (fileName.endsWith(".h5")) {
if (CT::endsWith(fileName, ".h5")) {
return new CDFHDF5Reader();
}
if (fileName.endsWith(".geojson")) {
if (CT::endsWith(fileName, ".geojson")) {
return new CDFGeoJSONReader();
}
if (fileName.endsWith(".csv")) {
if (CT::endsWith(fileName, ".csv")) {
return new CDFCSVReader();
}
if (fileName.endsWith(".png")) {
if (CT::endsWith(fileName, ".png")) {
return new CDFPNGReader();
}
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion CCDFDataModel/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <CTypes.h>
#include "CDebugger.h"
#include "CCDFDataModel.h"
Expand All @@ -14,6 +15,6 @@
#ifndef ADAGUCUTILS_H
#define ADAGUCUTILS_H

CDFReader *findReaderByFileName(CT::string fileName);
CDFReader *findReaderByFileName(const std::string &fileName);

#endif
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enable_testing()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
27 changes: 27 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
- Styles can be included into each other via the `IncludeStyle` option: See example at [adaguc.tests.ahn_utrechtse_heuvelrug_500m.xml](./data/config/datasets/adaguc.tests.ahn_utrechtse_heuvelrug_500m.xml)
- The WCS server now handles swapped x/y dimension axes properly.
- Data postprocessor convert_uv_components (isVectorLike) is not added by default anymore.
- C++ standard bumped from C++17 to C++20.
- Foundation laid for the `CT::string` -> `std::string` migration:
- New free helpers in `namespace CT::` operating on `std::string`: `CT::split`, `CT::join`, `CT::startsWith`, `CT::endsWith`, `CT::indexOf`, `CT::lastIndexOf`, `CT::replace`, `CT::replaceSelf`, `CT::trim`, `CT::toLowerCase`, `CT::toUpperCase`, `CT::printf`, `CT::printfconcat`, `CT::isNumeric`, `CT::isInt`, `CT::isFloat`, `CT::toFloat`, `CT::toDouble`, `CT::toInt`, `CT::toLong`, `CT::substring`, `CT::testRegEx`, `CT::basename`, `CT::equalsIgnoreCase`, `CT::encodeXml`, `CT::getHex`, `CT::getHex24`, `CT::randomString`.
- New `CT::fromCStr(const char*)` helper provides null-safe conversion to `std::string` (matching the historical behaviour of `CT::string((const char*)NULL)`).
- `CT::string` now interoperates with `std::string`: a constructor `CT::string(const std::string&)` accepts a `std::string`, and `static_cast<std::string>(ct)` (or `std::string(ct)`) explicitly converts a `CT::string` to `std::string`. The implicit `operator const char *()` is preserved for backward compatibility.
- `CDBDebug`, `CDBError`, `CDBWarning`, `_printDebugLine`, `_printErrorLine`, `_printWarningLine`, `CT::printf`, `CT::printfconcat` and the `print`/`printconcat` methods on `CT::string` are annotated with `__attribute__((format(printf,...)))`. The compiler now flags `%s` against an `std::string` (which would push the object onto the varargs stack as undefined behaviour) at build time.
- 34 new/extended unit tests in `hclasses/testhclasses.cpp` cover the new helpers, including the historical edge cases (empty-field splits, multi-character delimiters, whitespace-tolerant `isFloat`, NaN handling, null-safe construction).
- Migration guide for future contributors at `doc/developing/string-migration.md`.
- Real bug fixes uncovered while building the foundation:
- `adagucserverEC/CXMLSerializerInterface.cpp:102` - `CT::string xmlData` was being passed through `CDBError("...%s", ...)` varargs without `.c_str()`. The `format(printf,...)` attribute now catches this class of bug at compile time.
- `CCDFDataModel/CCDFNetCDFIO.cpp:552` - same pattern with `CT::string *groupName`.
- `adagucserverEC/COpenDAPHandler.cpp:423` - `httpHeaderContentType = getenv("CONTENT_TYPE")` was silently safe via `CT::string`'s null-pointer-tolerant constructor; the migration to `std::string` would have crashed, so the call site now uses `CT::fromCStr` explicitly.
- Migrated to `std::string` in this release:
- `GeoParameters::crs` (`adagucserverEC/Types/GeoParameters.h`)
- `ProjectionMapKey::sourceCRS`, `ProjectionMapKey::destCRS` (`adagucserverEC/Types/ProjectionStore.h`)
- `PointDV::id` (`adagucserverEC/Types/CPointTypes.h`)
- `CRectangleText::text`, `CRectangleText::fontFile` (`adagucserverEC/CRectangleText.h`)
- `CServerParams::responceCrs`, `CServerParams::Version`, `CServerParams::Exceptions`, `CServerParams::mapTitle`, `CServerParams::mapSubTitle`, `CServerParams::BGColor`, `CServerParams::JSONP`, `CServerParams::queryStrURLParam`, `CServerParams::datasetLocation` (`adagucserverEC/CServerParams.h` and `CRequest.h`)
- `CNetCDFDataWriter::tempFileName` (`adagucserverEC/CNetCDFDataWriter.h`)
- `COpenDAPHandler::httpHeaderContentType` (`adagucserverEC/COpenDAPHandler.h`)
- Migrated function signatures:
- `isLonLatProjection`, `isMercatorProjection` -> `const std::string &` (`adagucserverEC/utils/projectionUtils.h`)
- `findReaderByFileName` -> `const std::string &` (`CCDFDataModel/utils.h`)
- `checkIfFileMatchesLayer` -> `const std::string &` (`adagucserverEC/utils/serverutils.h`)
- `findLayerConfigForRequestedLayer` -> `const std::string &` (`adagucserverEC/utils/CRequestUtils.h`)
- `CSLD::parameterIsSld`, `CSLD::processSLDUrl` -> `const std::string &` (`adagucserverEC/CSLD.h`)
- Replaced legacy `name.copy(rawCharPtr)` patterns in `CCDFDataModel` (`CCDFAttribute`, `CCDFDimension`, `CCDFVariable`, `CCDFObject`, `CCDFGeoJSONIO`, `CCDFPNGIO`, `CProj4ToCF`) with the null-safe `name = CT::fromCStr(rawCharPtr)` pattern, eliminating the historical reliance on `CT::string`'s permissive null-pointer constructor in those readers/writers.

**Version 5.0.1 - 2025-11-05**

Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/CAutoResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int CAutoResource::configureDataset(CServerParams *srvParam, bool) {
// Set server title based on dataset
CT::string serverTitle = "";
if (serverTitle.empty() && srvParam->datasetLocation.empty() == false) {
serverTitle = srvParam->datasetLocation.basename();
serverTitle = CT::basename(srvParam->datasetLocation).c_str();
}
setServerTitle(srvParam, serverTitle);

Expand Down
26 changes: 13 additions & 13 deletions adagucserverEC/CCreateScaleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ int CCreateScaleBar::createScaleBar(CDrawImage *scaleBarImage, GeoParameters &ge
scaleBarImage->line(offsetX + p.width * 2.0f, scaleBarHeight - 1.0f * scaling, offsetX + p.width * 2.0f, scaleBarHeight - 9.0f * scaling, scaling * 1, 240);

// Draw text
CT::string units = "";
CT::string projection = geoParams.crs.c_str();
if (projection.equals("EPSG:3411")) units = "meter";
if (projection.equals("EPSG:3412")) units = "meter";
if (projection.equals("EPSG:3575")) units = "meter";
if (projection.equals("EPSG:4326")) units = "degrees";
if (projection.equals("EPSG:28992")) units = "meter";
if (projection.equals("EPSG:32661")) units = "meter";
if (projection.equals("EPSG:3857")) units = "meter";
if (projection.equals("EPSG:900913")) units = "meter";
if (projection.equals("EPSG:102100")) units = "meter";

if (units.equals("meter")) {
std::string units = "";
const std::string &projection = geoParams.crs;
if (projection == "EPSG:3411") units = "meter";
if (projection == "EPSG:3412") units = "meter";
if (projection == "EPSG:3575") units = "meter";
if (projection == "EPSG:4326") units = "degrees";
if (projection == "EPSG:28992") units = "meter";
if (projection == "EPSG:32661") units = "meter";
if (projection == "EPSG:3857") units = "meter";
if (projection == "EPSG:900913") units = "meter";
if (projection == "EPSG:102100") units = "meter";

if (units == "meter") {
if (p.mapunits > 1000) {
p.mapunits /= 1000;
units = "km";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int CDPPWFP::execute(CServerConfig::XMLE_DataPostProc *proc, CDataSource *dataSo

CImageWarper warper;

status = warper.initreproj(sourceGeo.crs, destGeo, &dataSource->srvParams->cfg->Projection);
status = warper.initreproj(sourceGeo.crs.c_str(), destGeo, &dataSource->srvParams->cfg->Projection);
if (status != 0) {
CDBError("Unable to initialize projection");
return 1;
Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/CDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ int CDataReader::parseDimensions(CDataSource *dataSource, int mode, int x, int y

if (dataSource->formatConverterActive == false && dataSource->dfCellSizeX > 0) {

if (isLonLatProjection(&dataSource->nativeProj4)) {
if (isLonLatProjection(dataSource->nativeProj4.c_str())) {
// If the lon variable name contains an X, it is probably not longitude.
if (dataSource->varX->name.indexOf("x") == -1 && dataSource->varX->name.indexOf("X") == -1) {
size_t j = 0;
Expand Down
Loading
Loading