Skip to content

Commit

Permalink
Use swl-variant, remove some variants entirely.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 27, 2024
1 parent 675e5c4 commit a59cc16
Show file tree
Hide file tree
Showing 53 changed files with 945 additions and 651 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ message(STATUS "VCPKG_OVERLAY_TRIPLETS ${VCPKG_OVERLAY_TRIPLETS}")
# with the installation
# Note that fmt is a public dependency of the vcpkg version of spdlog
# STB and uriparser aren't technically part of the public interface, but they're used by the downstream Cesium for Unreal project
set(PACKAGES_PUBLIC asyncplusplus expected-lite fmt glm rapidjson spdlog stb uriparser)
set(PACKAGES_PUBLIC asyncplusplus expected-lite fmt glm rapidjson spdlog stb swl-variant uriparser)
# These packages are used in the code and produce binaries, but are not part of the public interface. Therefore we need
# to distribute the binaries for linking, but not the headers, as downstream consumers don't need them
# OpenSSL and abseil are both dependencies of s2geometry
Expand All @@ -63,6 +63,9 @@ if(NOT VCPKG_MANIFEST_MODE)
list(APPEND PACKAGES_ALL ${PACKAGES_PRIVATE})
list(APPEND PACKAGES_ALL ${PACKAGES_TEST})

set(ENV{VCPKG_OVERLAY_PORTS} "${CMAKE_CURRENT_LIST_DIR}/vcpkg/ports")
set(ENV{VCPKG_OVERLAY_TRIPLETS} "${CMAKE_CURRENT_LIST_DIR}/vcpkg/triplets")

ezvcpkg_fetch(
COMMIT 2024.11.16
PACKAGES ${PACKAGES_ALL}
Expand Down Expand Up @@ -251,6 +254,7 @@ find_package(libjpeg-turbo CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(s2 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(swl-variant CONFIG REQUIRED)
find_package(tinyxml2 CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(uriparser CONFIG REQUIRED char wchar_t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Cesium3DTiles/Subtree.h>
#include <CesiumAsync/Future.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumUtility/Variant.h>

#include <optional>

Expand Down Expand Up @@ -121,8 +122,8 @@ class SubtreeAvailability {
* @brief A mechanism for accessing availability information. It may be a
* constant value, or it may be read from a bitstream.
*/
using AvailabilityView =
std::variant<SubtreeConstantAvailability, SubtreeBufferViewAvailability>;
using AvailabilityView = CesiumUtility::
Variant<SubtreeConstantAvailability, SubtreeBufferViewAvailability>;

/**
* @brief Constructs a new instance.
Expand Down
72 changes: 36 additions & 36 deletions Cesium3DTilesContent/src/BatchTableToGltfStructuralMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <CesiumGltf/PropertyTypeTraits.h>
#include <CesiumUtility/Assert.h>
#include <CesiumUtility/Log.h>
#include <CesiumUtility/Variant.h>

#include <glm/glm.hpp>
#include <rapidjson/writer.h>
Expand Down Expand Up @@ -43,7 +44,7 @@ struct MaskedType {
bool isFloat64;
bool isBool;

MaskedType() : MaskedType(true){};
MaskedType() : MaskedType(true) {};

MaskedType(bool defaultValue)
: isInt8(defaultValue),
Expand Down Expand Up @@ -99,12 +100,12 @@ struct MaskedArrayType {
uint32_t minArrayCount;
uint32_t maxArrayCount;

MaskedArrayType() : MaskedArrayType(true){};
MaskedArrayType() : MaskedArrayType(true) {};

MaskedArrayType(bool defaultValue)
: elementType(defaultValue),
minArrayCount(std::numeric_limits<uint32_t>::max()),
maxArrayCount(std::numeric_limits<uint32_t>::min()){};
maxArrayCount(std::numeric_limits<uint32_t>::min()) {};

MaskedArrayType(
MaskedType inElementType,
Expand Down Expand Up @@ -142,7 +143,7 @@ struct CompatibleTypes {
* MaskedType or MaskedArrayType, they are considered incompatible with the
* other type.
*/
std::variant<std::monostate, MaskedType, MaskedArrayType> _type;
CesiumUtility::Variant<std::monostate, MaskedType, MaskedArrayType> _type;

/**
* Whether the property has encountered a null value. A
Expand Down Expand Up @@ -173,34 +174,34 @@ struct CompatibleTypes {
bool _canUseNullStringSentinel = true;

public:
CompatibleTypes() : _type(){};
CompatibleTypes(const MaskedType& maskedType) : _type(maskedType){};
CompatibleTypes() : _type() {};
CompatibleTypes(const MaskedType& maskedType) : _type(maskedType) {};
CompatibleTypes(const MaskedArrayType& maskedArrayType)
: _type(maskedArrayType){};
: _type(maskedArrayType) {};

/**
* Whether this is exclusively compatible with array types. This indicates an
* exclusively array property, as opposed to a newly initialized one that is
* "compatible" with everything.
*/
bool isExclusivelyArray() const noexcept {
return std::holds_alternative<MaskedArrayType>(_type);
return holds_alternative<MaskedArrayType>(_type);
}

/**
* Whether this property is with at least one unsigned integer type. Does not
* count arrays.
*/
bool isCompatibleWithUnsignedInteger() const noexcept {
if (std::holds_alternative<MaskedArrayType>(_type)) {
if (holds_alternative<MaskedArrayType>(_type)) {
return false;
}

if (std::holds_alternative<std::monostate>(_type)) {
if (holds_alternative<std::monostate>(_type)) {
return true;
}

MaskedType type = std::get<MaskedType>(_type);
MaskedType type = get<MaskedType>(_type);
return type.isUint8 || type.isUint16 || type.isUint32 || type.isUint64;
}

Expand All @@ -209,15 +210,15 @@ struct CompatibleTypes {
* Does not count arrays.
*/
bool isCompatibleWithSignedInteger() const noexcept {
if (std::holds_alternative<MaskedArrayType>(_type)) {
if (holds_alternative<MaskedArrayType>(_type)) {
return false;
}

if (std::holds_alternative<std::monostate>(_type)) {
if (holds_alternative<std::monostate>(_type)) {
return true;
}

MaskedType type = std::get<MaskedType>(_type);
MaskedType type = get<MaskedType>(_type);
return type.isInt8 || type.isInt16 || type.isInt32 || type.isInt64;
}

Expand All @@ -226,20 +227,20 @@ struct CompatibleTypes {
* happens when a CompatibleTypes is initialized and never modified.
*/
bool isFullyCompatible() const noexcept {
return std::holds_alternative<std::monostate>(_type);
return holds_alternative<std::monostate>(_type);
}

/**
* Whether this property is incompatible with every primitive type.
* Fully-incompatible properties will be treated as string properties.
*/
bool isIncompatible() const noexcept {
if (std::holds_alternative<MaskedType>(_type)) {
return std::get<MaskedType>(_type).isIncompatible();
if (holds_alternative<MaskedType>(_type)) {
return get<MaskedType>(_type).isIncompatible();
}

if (std::holds_alternative<MaskedArrayType>(_type)) {
return std::get<MaskedArrayType>(_type).isIncompatible();
if (holds_alternative<MaskedArrayType>(_type)) {
return get<MaskedArrayType>(_type).isIncompatible();
}

// std::monostate means compatibility with all types.
Expand All @@ -256,13 +257,13 @@ struct CompatibleTypes {
* Merges a MaskedType into this BatchTableProperty.
*/
void operator&=(const MaskedType& inMaskedType) noexcept {
if (std::holds_alternative<MaskedType>(_type)) {
MaskedType& maskedType = std::get<MaskedType>(_type);
if (holds_alternative<MaskedType>(_type)) {
MaskedType& maskedType = get<MaskedType>(_type);
maskedType &= inMaskedType;
return;
}

if (std::holds_alternative<MaskedArrayType>(_type)) {
if (holds_alternative<MaskedArrayType>(_type)) {
makeIncompatible();
return;
}
Expand All @@ -274,13 +275,13 @@ struct CompatibleTypes {
* Merges a MaskedArrayType into this CompatibleTypes.
*/
void operator&=(const MaskedArrayType& inArrayType) noexcept {
if (std::holds_alternative<MaskedArrayType>(_type)) {
MaskedArrayType& arrayType = std::get<MaskedArrayType>(_type);
if (holds_alternative<MaskedArrayType>(_type)) {
MaskedArrayType& arrayType = get<MaskedArrayType>(_type);
arrayType &= inArrayType;
return;
}

if (std::holds_alternative<MaskedType>(_type)) {
if (holds_alternative<MaskedType>(_type)) {
makeIncompatible();
return;
}
Expand All @@ -292,17 +293,16 @@ struct CompatibleTypes {
* Merges another CompatibleTypes into this one.
*/
void operator&=(const CompatibleTypes& inTypes) noexcept {
if (std::holds_alternative<std::monostate>(inTypes._type)) {
if (holds_alternative<std::monostate>(inTypes._type)) {
// The other CompatibleTypes is compatible with everything, so it does not
// change this one.
} else

if (std::holds_alternative<MaskedArrayType>(inTypes._type)) {
const MaskedArrayType& arrayType =
std::get<MaskedArrayType>(inTypes._type);
if (holds_alternative<MaskedArrayType>(inTypes._type)) {
const MaskedArrayType& arrayType = get<MaskedArrayType>(inTypes._type);
operator&=(arrayType);
} else {
const MaskedType& maskedType = std::get<MaskedType>(inTypes._type);
const MaskedType& maskedType = get<MaskedType>(inTypes._type);
operator&=(maskedType);
}

Expand All @@ -318,11 +318,11 @@ struct CompatibleTypes {
* MaskedType.
*/
MaskedType toMaskedType() const noexcept {
if (std::holds_alternative<MaskedType>(_type)) {
return std::get<MaskedType>(_type);
if (holds_alternative<MaskedType>(_type)) {
return get<MaskedType>(_type);
}

bool isArray = std::holds_alternative<MaskedArrayType>(_type);
bool isArray = holds_alternative<MaskedArrayType>(_type);
return MaskedType(!isArray);
}

Expand All @@ -332,11 +332,11 @@ struct CompatibleTypes {
* MaskedArrayType.
*/
MaskedArrayType toMaskedArrayType() const noexcept {
if (std::holds_alternative<MaskedArrayType>(_type)) {
return std::get<MaskedArrayType>(_type);
if (holds_alternative<MaskedArrayType>(_type)) {
return get<MaskedArrayType>(_type);
}

bool isNonArray = std::holds_alternative<MaskedType>(_type);
bool isNonArray = holds_alternative<MaskedType>(_type);
return MaskedArrayType(!isNonArray);
}

Expand Down
2 changes: 1 addition & 1 deletion Cesium3DTilesContent/src/I3dmToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ std::vector<glm::dmat4> getMeshGpuInstancingTransforms(
}
if (rotations) {
auto quatAccessorView = getQuaternionAccessorView(model, rotations);
std::visit(
visit(
[&](auto&& arg) {
for (unsigned i = 0; i < count; ++i) {
auto quat = toGlmQuat<glm::dquat>(arg[i]);
Expand Down
14 changes: 7 additions & 7 deletions Cesium3DTilesContent/src/SubtreeAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void SubtreeAvailability::setContentAvailable(
bool SubtreeAvailability::isSubtreeAvailable(
uint64_t relativeSubtreeMortonId) const noexcept {
const SubtreeConstantAvailability* constantAvailability =
std::get_if<SubtreeConstantAvailability>(&this->_subtreeAvailability);
get_if<SubtreeConstantAvailability>(&this->_subtreeAvailability);
if (constantAvailability) {
return constantAvailability->constant;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ void convertConstantAvailabilityToBitstream(
SubtreeAvailability::AvailabilityView& availabilityView) {
const SubtreeAvailability::SubtreeConstantAvailability*
pConstantAvailability =
std::get_if<SubtreeAvailability::SubtreeConstantAvailability>(
get_if<SubtreeAvailability::SubtreeConstantAvailability>(
&availabilityView);
if (!pConstantAvailability)
return;
Expand Down Expand Up @@ -427,7 +427,7 @@ void SubtreeAvailability::setSubtreeAvailable(
uint64_t relativeSubtreeMortonId,
bool isAvailable) noexcept {
const SubtreeConstantAvailability* pConstantAvailability =
std::get_if<SubtreeConstantAvailability>(&this->_subtreeAvailability);
get_if<SubtreeConstantAvailability>(&this->_subtreeAvailability);
if (pConstantAvailability) {
if (pConstantAvailability->constant == isAvailable) {
// New state matches the constant, so there is nothing to do.
Expand Down Expand Up @@ -483,7 +483,7 @@ bool SubtreeAvailability::isAvailable(
}

const SubtreeConstantAvailability* constantAvailability =
std::get_if<SubtreeConstantAvailability>(&availabilityView);
get_if<SubtreeConstantAvailability>(&availabilityView);
if (constantAvailability) {
return constantAvailability->constant;
}
Expand All @@ -503,7 +503,7 @@ void SubtreeAvailability::setAvailable(
AvailabilityView& availabilityView,
bool isAvailable) noexcept {
const SubtreeConstantAvailability* pConstantAvailability =
std::get_if<SubtreeConstantAvailability>(&availabilityView);
get_if<SubtreeConstantAvailability>(&availabilityView);
if (pConstantAvailability) {
if (pConstantAvailability->constant == isAvailable) {
// New state matches the constant, so there is nothing to do.
Expand Down Expand Up @@ -549,7 +549,7 @@ bool SubtreeAvailability::isAvailableUsingBufferView(
numOfTilesFromRootToParentLevel + relativeTileMortonId;

const SubtreeBufferViewAvailability* bufferViewAvailability =
std::get_if<SubtreeBufferViewAvailability>(&availabilityView);
get_if<SubtreeBufferViewAvailability>(&availabilityView);

const uint64_t byteIndex = availabilityBitIndex / 8;
if (byteIndex >= bufferViewAvailability->view.size()) {
Expand All @@ -572,7 +572,7 @@ void SubtreeAvailability::setAvailableUsingBufferView(
numOfTilesFromRootToParentLevel + relativeTileMortonId;

const SubtreeBufferViewAvailability* pBufferViewAvailability =
std::get_if<SubtreeBufferViewAvailability>(&availabilityView);
get_if<SubtreeBufferViewAvailability>(&availabilityView);

const uint64_t byteIndex = availabilityBitIndex / 8;
if (byteIndex >= pBufferViewAvailability->view.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGeospatial/S2CellBoundingVolume.h>
#include <CesiumUtility/Variant.h>

#include <optional>
#include <variant>

namespace Cesium3DTilesSelection {

Expand All @@ -26,7 +26,7 @@ namespace Cesium3DTilesSelection {
* @see CesiumGeospatial::BoundingRegionWithLooseFittingHeights
* @see CesiumGeospatial::S2CellBoundingVolume
*/
typedef std::variant<
typedef CesiumUtility::Variant<
CesiumGeometry::BoundingSphere,
CesiumGeometry::OrientedBoundingBox,
CesiumGeospatial::BoundingRegion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <CesiumGltf/Model.h>
#include <CesiumRasterOverlays/RasterOverlayDetails.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumUtility/Variant.h>

#include <memory>
#include <variant>
#include <vector>

namespace Cesium3DTilesSelection {
Expand Down Expand Up @@ -207,7 +207,7 @@ class CESIUM3DTILESSELECTION_API TileRenderContent {
* that is currently being owned by the tile
*/
class CESIUM3DTILESSELECTION_API TileContent {
using TileContentKindImpl = std::variant<
using TileContentKindImpl = CesiumUtility::Variant<
TileUnknownContent,
TileEmptyContent,
std::unique_ptr<TileExternalContent>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <CesiumGeometry/OctreeTileID.h>
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumUtility/Variant.h>

#include <string>
#include <variant>

namespace Cesium3DTilesSelection {

Expand All @@ -32,7 +32,7 @@ namespace Cesium3DTilesSelection {
* have any content, but content for it can be created by subdividing
* the parent tile's content.
*/
typedef std::variant<
typedef CesiumUtility::Variant<
std::string,
CesiumGeometry::QuadtreeTileID,
CesiumGeometry::OctreeTileID,
Expand Down
Loading

0 comments on commit a59cc16

Please sign in to comment.