Skip to content

Commit

Permalink
Use static constepxr char[] constants
Browse files Browse the repository at this point in the history
  • Loading branch information
sjperkins committed Sep 4, 2023
1 parent 9cf2344 commit 28938bb
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 40 deletions.
62 changes: 43 additions & 19 deletions cpp/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ using ::casacore::MSWeather;
namespace arcae {
namespace {

// Table and subtable names
static constexpr char kAntenna[] = "ANTENNA";
static constexpr char kMain[] = "MAIN";
static constexpr char kDataDescription[] = "DATA_DESCRIPTION";
static constexpr char kDoppler[] = "DOPPLER";
static constexpr char kFeed[] = "FEED";
static constexpr char kField[] = "FIELD";
static constexpr char kFlagCmd[] = "FLAG_CMD";
static constexpr char kFreqOffset[] = "FREQ_OFFSET";
static constexpr char kHistory[] = "HISTORY";
static constexpr char kObservation[] = "OBSERVATION";
static constexpr char kPointing[] = "POINTING";
static constexpr char kPolarization[] = "POLARIZATION";
static constexpr char kProcessor[] = "PROCESSOR";
static constexpr char kSource[] = "SOURCE";
static constexpr char kSpectralWindow[] = "SPECTRAL_WINDOW";
static constexpr char kState[] = "STATE";
static constexpr char kSyscal[] = "SYSCAL";
static constexpr char kWeather[] = "WEATHER";

// Category related columns
static constexpr char kFlagCategory[] = "FLAG_CATEGORY";
static constexpr char kCategory[] = "CATEGORY";

TableDesc MainMSDesc(bool complete)
{
// Get required descriptor
Expand All @@ -87,7 +111,7 @@ TableDesc MainMSDesc(bool complete)
// This is an OK solution since the C++ layer always adds this keyword
// if it is missing from the MS
// (see addCat())
td.rwColumnDesc("FLAG_CATEGORY").rwKeywordSet().removeField("CATEGORY");
td.rwColumnDesc(kFlagCategory).rwKeywordSet().removeField(kCategory);
return td;
}

Expand Down Expand Up @@ -167,41 +191,41 @@ Result<TableDesc> MSTableDescriptor(const String & table, bool complete)
// Upper case things to be sure
table_.upcase();

if(table.empty() || table_ == "MAIN") {
if(table.empty() || table_ == kMain) {
return MainMSDesc(complete);
} else if(table_ == "ANTENNA") {
} else if(table_ == kAntenna) {
return MSSubtableDesc<MSAntenna>(complete);
} else if(table_ == "DATA_DESCRIPTION") {
} else if(table_ == kDataDescription) {
return MSSubtableDesc<MSDataDescription>(complete);
} else if(table_ == "DOPPLER") {
} else if(table_ == kDoppler) {
return MSSubtableDesc<MSDoppler>(complete);
} else if(table_ == "FEED") {
} else if(table_ == kFeed) {
return MSSubtableDesc<MSFeed>(complete);
} else if(table_ == "FIELD") {
} else if(table_ == kField) {
return MSSubtableDesc<MSField>(complete);
} else if(table_ == "FLAG_CMD") {
} else if(table_ == kFlagCmd) {
return MSSubtableDesc<MSFlagCmd>(complete);
} else if(table_ == "FREQ_OFFSET") {
} else if(table_ == kFreqOffset) {
return MSSubtableDesc<MSFreqOffset>(complete);
} else if(table_ == "HISTORY") {
} else if(table_ == kHistory) {
return MSSubtableDesc<MSHistory>(complete);
} else if(table_ == "OBSERVATION") {
} else if(table_ == kObservation) {
return MSSubtableDesc<MSObservation>(complete);
} else if(table_ == "POINTING") {
} else if(table_ == kPointing) {
return MSSubtableDesc<MSPointing>(complete);
} else if(table_ == "POLARIZATION") {
} else if(table_ == kPolarization) {
return MSSubtableDesc<MSPolarization>(complete);
} else if(table_ == "PROCESSOR") {
} else if(table_ == kProcessor) {
return MSSubtableDesc<MSProcessor>(complete);
} else if(table_ == "SOURCE") {
} else if(table_ == kSource) {
return MSSubtableDesc<MSSource>(complete);
} else if(table_ == "SPECTRAL_WINDOW") {
} else if(table_ == kSpectralWindow) {
return MSSubtableDesc<MSSpectralWindow>(complete);
} else if(table_ == "STATE") {
} else if(table_ == kState) {
return MSSubtableDesc<MSState>(complete);
} else if(table_ == "SYSCAL") {
} else if(table_ == kSyscal) {
return MSSubtableDesc<MSSysCal>(complete);
} else if(table_ == "WEATHER") {
} else if(table_ == kWeather) {
return MSSubtableDesc<MSWeather>(complete);
}

Expand Down
67 changes: 46 additions & 21 deletions cpp/table_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <casacore/tables/Tables/TableLock.h>
#include <casacore/ms/MeasurementSets/MeasurementSet.h>

using namespace std::literals;

using ::arrow::Result;
using ::arrow::Status;

Expand Down Expand Up @@ -54,6 +56,29 @@ using ::casacore::MSWeather;


namespace arcae {
namespace {

/// Table and subtable names
static constexpr char kAntenna[] = "ANTENNA";
static constexpr char kMain[] = "MAIN";
static constexpr char kDataDescription[] = "DATA_DESCRIPTION";
static constexpr char kDoppler[] = "DOPPLER";
static constexpr char kFeed[] = "FEED";
static constexpr char kField[] = "FIELD";
static constexpr char kFlagCmd[] = "FLAG_CMD";
static constexpr char kFreqOffset[] = "FREQ_OFFSET";
static constexpr char kHistory[] = "HISTORY";
static constexpr char kObservation[] = "OBSERVATION";
static constexpr char kPointing[] = "POINTING";
static constexpr char kPolarization[] = "POLARIZATION";
static constexpr char kProcessor[] = "PROCESSOR";
static constexpr char kSource[] = "SOURCE";
static constexpr char kSpectralWindow[] = "SPECTRAL_WINDOW";
static constexpr char kState[] = "STATE";
static constexpr char kSyscal[] = "SYSCAL";
static constexpr char kWeather[] = "WEATHER";

} // namespace

Result<std::shared_ptr<SafeTableProxy>> open_table(const std::string & filename) {
return SafeTableProxy::Make([&filename]() -> Result<std::shared_ptr<TableProxy>> {
Expand All @@ -80,14 +105,14 @@ Result<std::shared_ptr<SafeTableProxy>> default_ms(
const std::string & json_dminfo)
{
// Upper case subtable name
std::string usubtable(subtable.size(), '0');
auto usubtable = std::string(subtable.size(), '0');
std::transform(std::begin(subtable), std::end(subtable), std::begin(usubtable),
[](unsigned char c) { return std::toupper(c); });

std::string modname = name.empty() ? "measurementset.ms" : name;
auto modname = name.empty() ? "measurementset.ms"s : name;

// Subtables are relative to the MS name
if(usubtable != "MAIN") {
if(usubtable != kMain) {
modname.append(1, '/');
modname.append(usubtable);
}
Expand All @@ -97,45 +122,45 @@ Result<std::shared_ptr<SafeTableProxy>> default_ms(
json_table_desc, json_dminfo));

return SafeTableProxy::Make([&]() -> Result<std::shared_ptr<TableProxy>> {
if(usubtable.empty() || usubtable == "MAIN") {
if(usubtable.empty() || usubtable == kMain) {
auto ms = MeasurementSet(setup_new_table);
// Create the MS default subtables
ms.createDefaultSubtables(Table::New);
// Create a table proxy
return std::make_shared<TableProxy>(ms);
} else if(usubtable == "ANTENNA") {
} else if(usubtable == kAntenna) {
return std::make_shared<TableProxy>(MSAntenna(setup_new_table));
} else if(usubtable == "DATA_DESCRIPTION") {
} else if(usubtable == kDataDescription) {
return std::make_shared<TableProxy>(MSDataDescription(setup_new_table));
} else if(usubtable == "DOPPLER") {
} else if(usubtable == kDoppler) {
return std::make_shared<TableProxy>(MSDoppler(setup_new_table));
} else if(usubtable == "FEED") {
} else if(usubtable == kFeed) {
return std::make_shared<TableProxy>(MSFeed(setup_new_table));
} else if(usubtable == "FIELD") {
} else if(usubtable == kField) {
return std::make_shared<TableProxy>(MSField(setup_new_table));
} else if(usubtable == "FLAG_CMD") {
} else if(usubtable == kFlagCmd) {
return std::make_shared<TableProxy>(MSFlagCmd(setup_new_table));
} else if(usubtable == "FREQ_OFFSET") {
} else if(usubtable == kFreqOffset) {
return std::make_shared<TableProxy>(MSFreqOffset(setup_new_table));
} else if(usubtable == "HISTORY") {
} else if(usubtable == kHistory) {
return std::make_shared<TableProxy>(MSHistory(setup_new_table));
} else if(usubtable == "OBSERVATION") {
} else if(usubtable == kObservation) {
return std::make_shared<TableProxy>(MSObservation(setup_new_table));
} else if(usubtable == "POINTING") {
} else if(usubtable == kPointing) {
return std::make_shared<TableProxy>(MSPointing(setup_new_table));
} else if(usubtable == "POLARIZATION") {
} else if(usubtable == kPolarization) {
return std::make_shared<TableProxy>(MSPolarization(setup_new_table));
} else if(usubtable == "PROCESSOR") {
} else if(usubtable == kProcessor) {
return std::make_shared<TableProxy>(MSProcessor(setup_new_table));
} else if(usubtable == "SOURCE") {
} else if(usubtable == kSource) {
return std::make_shared<TableProxy>(MSSource(setup_new_table));
} else if(usubtable == "SPECTRAL_WINDOW") {
} else if(usubtable == kSpectralWindow) {
return std::make_shared<TableProxy>(MSSpectralWindow(setup_new_table));
} else if(usubtable == "STATE") {
} else if(usubtable == kState) {
return std::make_shared<TableProxy>(MSState(setup_new_table));
} else if(usubtable == "SYSCAL") {
} else if(usubtable == kSyscal) {
return std::make_shared<TableProxy>(MSSysCal(setup_new_table));
} else if(usubtable == "WEATHER") {
} else if(usubtable == kWeather) {
return std::make_shared<TableProxy>(MSWeather(setup_new_table));
}

Expand Down

0 comments on commit 28938bb

Please sign in to comment.