Skip to content

Commit

Permalink
Respond to MR comments
Browse files Browse the repository at this point in the history
Move the new is_pod method to simdb::utils::is_pod, so that it won't be
confused with std::is_pod in the event of `using namespace std'. Also move the
struct definition to a new file, `simdb/utils/CompatUtils.hpp', so that it is
centralized in one place.
  • Loading branch information
acrucker authored and klingaard committed Jan 17, 2024
1 parent 8291100 commit 4626e0d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
37 changes: 16 additions & 21 deletions sparta/simdb/include/simdb/schema/ColumnMetaStructs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "simdb/schema/ColumnTypedefs.hpp"
#include "simdb/schema/DatabaseTypedefs.hpp"
#include "simdb/Errors.hpp"
#include "simdb/utils/CompatUtils.hpp"

#include <string>
#include <type_traits>
Expand All @@ -23,20 +24,14 @@ namespace simdb {
template <typename ColumnT, typename Enable = void>
struct column_info;

template<typename T>
struct is_pod {
static constexpr bool value = std::is_trivial<T>::value
&& std::is_standard_layout<T>::value;
};

//! int8_t
template <>
struct column_info<int8_t> {
static ColumnDataType data_type() {
return ColumnDataType::int8_t;
}
using value_type = int8_t;
static constexpr bool is_fixed_size = is_pod<int8_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<int8_t>::value;
};

//! uint8_t
Expand All @@ -46,7 +41,7 @@ struct column_info<uint8_t> {
return ColumnDataType::uint8_t;
}
using value_type = uint8_t;
static constexpr bool is_fixed_size = is_pod<uint8_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<uint8_t>::value;
};

//! int16_t
Expand All @@ -56,7 +51,7 @@ struct column_info<int16_t> {
return ColumnDataType::int16_t;
}
using value_type = int16_t;
static constexpr bool is_fixed_size = is_pod<int16_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<int16_t>::value;
};

//! uint16_t
Expand All @@ -66,7 +61,7 @@ struct column_info<uint16_t> {
return ColumnDataType::uint16_t;
}
using value_type = uint16_t;
static constexpr bool is_fixed_size = is_pod<uint16_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<uint16_t>::value;
};

//! int32_t
Expand All @@ -76,7 +71,7 @@ struct column_info<int32_t> {
return ColumnDataType::int32_t;
}
using value_type = int32_t;
static constexpr bool is_fixed_size = is_pod<int32_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<int32_t>::value;
};

//! uint32_t
Expand All @@ -86,7 +81,7 @@ struct column_info<uint32_t> {
return ColumnDataType::uint32_t;
}
using value_type = uint32_t;
static constexpr bool is_fixed_size = is_pod<uint32_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<uint32_t>::value;
};

//! int64_t
Expand All @@ -96,7 +91,7 @@ struct column_info<int64_t> {
return ColumnDataType::int64_t;
}
using value_type = int64_t;
static constexpr bool is_fixed_size = is_pod<int64_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<int64_t>::value;
};

//! uint64_t
Expand All @@ -106,7 +101,7 @@ struct column_info<uint64_t> {
return ColumnDataType::uint64_t;
}
using value_type = uint64_t;
static constexpr bool is_fixed_size = is_pod<uint64_t>::value;
static constexpr bool is_fixed_size = utils::is_pod<uint64_t>::value;
};

//! float
Expand All @@ -116,7 +111,7 @@ struct column_info<float> {
return ColumnDataType::float_t;
}
using value_type = float;
static constexpr bool is_fixed_size = is_pod<float>::value;
static constexpr bool is_fixed_size = utils::is_pod<float>::value;
};

//! double
Expand All @@ -126,7 +121,7 @@ struct column_info<double> {
return ColumnDataType::double_t;
}
using value_type = double;
static constexpr bool is_fixed_size = is_pod<double>::value;
static constexpr bool is_fixed_size = utils::is_pod<double>::value;
};

//! string
Expand All @@ -139,7 +134,7 @@ struct column_info<ColumnT, typename std::enable_if<
return ColumnDataType::string_t;
}
using value_type = ColumnT;
static constexpr bool is_fixed_size = is_pod<std::string>::value;
static constexpr bool is_fixed_size = utils::is_pod<std::string>::value;
};

//! char
Expand All @@ -149,7 +144,7 @@ struct column_info<char> {
return ColumnDataType::char_t;
}
using value_type = char;
static constexpr bool is_fixed_size = is_pod<char>::value;
static constexpr bool is_fixed_size = utils::is_pod<char>::value;
};

//! Vectors of raw bytes are stored as blobs (void* / opaque)
Expand All @@ -161,7 +156,7 @@ struct column_info<ColumnT, typename std::enable_if<
return ColumnDataType::blob_t;
}
using value_type = typename is_container<ColumnT>::value_type;
static constexpr bool is_fixed_size = is_pod<ColumnT>::value;
static constexpr bool is_fixed_size = utils::is_pod<ColumnT>::value;
};

//! Blob descriptor
Expand All @@ -173,11 +168,11 @@ struct column_info<ColumnT, typename std::enable_if<
return ColumnDataType::blob_t;
}
using value_type = Blob;
static constexpr bool is_fixed_size = is_pod<ColumnT>::value;
static constexpr bool is_fixed_size = utils::is_pod<ColumnT>::value;
};

//! See if the given column data type has a fixed number
//! of bytes, as determined by is_pod<T>
//! of bytes, as determined by utils::is_pod<T>
inline bool getColumnIsFixedSize(const ColumnDataType dtype)
{
using dt = ColumnDataType;
Expand Down
19 changes: 19 additions & 0 deletions sparta/simdb/include/simdb/utils/CompatUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// <CompatUtils> -*- C++ -*-

#pragma once

#include <type_traits>

namespace simdb {
namespace utils {

//! \brief Replacement for std::is_pod, which was deprecated in C++20

template<typename T>
struct is_pod {
static constexpr bool value = std::is_trivial<T>::value
&& std::is_standard_layout<T>::value;
};

} // namespace utils
} // namespace simdb
4 changes: 2 additions & 2 deletions sparta/simdb/src/ObjectRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "simdb/utils/ObjectQuery.hpp"
#include "simdb/TableRef.hpp"
#include "simdb/DbConnProxy.hpp"
#include "simdb/utils/CompatUtils.hpp"

//SQLite-specific headers
#include "simdb/impl/sqlite/TransactionUtils.hpp"
Expand Down Expand Up @@ -96,8 +97,7 @@ PropertyDataT LOCAL_getScalarProperty(const std::string & table_name,
//! without using ObjectQuery.
template <typename PropertyDataT>
typename std::enable_if<
std::is_trivial<PropertyDataT>::value &&
std::is_standard_layout<PropertyDataT>::value,
utils::is_pod<PropertyDataT>::value,
PropertyDataT>::type
LOCAL_getScalarPropertyNoObjectQuery(
const std::string & table_name,
Expand Down
5 changes: 3 additions & 2 deletions sparta/sparta/pairs/SpartaKeyPairs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "sparta/utils/MetaTypeList.hpp"
#include "sparta/utils/MetaStructs.hpp"
#include "sparta/utils/DetectMemberUtils.hpp"
#include "simdb/utils/CompatUtils.hpp"


namespace sparta {

Expand Down Expand Up @@ -1691,8 +1693,7 @@ namespace sparta {
template<typename T>
MetaStruct::enable_if_t<
std::is_integral<MetaStruct::decay_t<T>>::value &&
std::is_trivial<MetaStruct::decay_t<T>>::value &&
std::is_standard_layout<MetaStruct::decay_t<T>>::value &&
simdb::utils::is_pod<MetaStruct::decay_t<T>>::value &&
!MetaStruct::is_bool<MetaStruct::decay_t<T>>::value, void>

updateValueInCache_(
Expand Down

0 comments on commit 4626e0d

Please sign in to comment.