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
7 changes: 5 additions & 2 deletions bindings/python/src/model/mixin/core/vertex_identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ namespace geode
},
pybind11::arg( "unique_vertex_id" ),
"Return the list of ComponentMeshVertex identified with the "
"unique vertex; raise an IndexError if unique_vertex_id is not "
"in [0, nb_unique_vertices)" )
"unique vertex, in insertion order (after loading a native "
"file of the current format: Corners, Lines, Surfaces then "
"Blocks in the model order, then increasing vertex "
"indices); raise an IndexError if "
"unique_vertex_id is not in [0, nb_unique_vertices)" )
.def(
"is_unique_vertex_isolated",
[]( const VertexIdentifier& identifier,
Expand Down
7 changes: 6 additions & 1 deletion cmake/ConfigureMinizip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ExternalProject_Add(minizip
GIT_TAG 4.1.0
GIT_SHALLOW ON
GIT_PROGRESS ON
DEPENDS zlib
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_ARGS
Expand All @@ -39,7 +40,11 @@ ExternalProject_Add(minizip
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
CMAKE_CACHE_ARGS
-DMZ_COMPAT:BOOL=OFF
-DMZ_ZLIB:BOOL=OFF
-DMZ_ZLIB:BOOL=ON
-DMZ_FETCH_LIBS:BOOL=OFF
-DMZ_FORCE_FETCH_LIBS:BOOL=OFF
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG:BOOL=ON
-DZLIB_ROOT:PATH=${ZLIB_INSTALL_PREFIX}
-DMZ_BZIP2:BOOL=OFF
-DMZ_LZMA:BOOL=OFF
-DMZ_PKCRYPT:BOOL=OFF
Expand Down
6 changes: 5 additions & 1 deletion cmake/OpenGeode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ find_package(absl REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${ABSEIL_INSTALL_PREFIX}
find_package(Async++ REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${ASYNCPLUSPLUS_INSTALL_PREFIX})
find_package(Bitsery REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${BITSERY_INSTALL_PREFIX})
find_package(earcut_hpp REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${EARCUT_INSTALL_PREFIX})
find_package(ZLIB REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${ZLIB_INSTALL_PREFIX})
# minizip-ng calls find_dependency(ZLIB): reuse the zlib-ng config found above
set(GEODE_PREFER_CONFIG ${CMAKE_FIND_PACKAGE_PREFER_CONFIG})
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
find_package(minizip-ng REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${MINIZIP_INSTALL_PREFIX})
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${GEODE_PREFER_CONFIG})
find_package(nanoflann REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${NANOFLANN_INSTALL_PREFIX})
find_package(spdlog REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${SPDLOG_INSTALL_PREFIX})
find_package(nlohmann_json REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${JSON_INSTALL_PREFIX})
find_package(zlib REQUIRED CONFIG NO_DEFAULT_PATH PATHS ${ZLIB_INSTALL_PREFIX})
find_package(Threads REQUIRED)

# Install OpenGeode third-parties
Expand Down
5 changes: 5 additions & 0 deletions cmake/OpenGeodeConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ find_dependency(Async++)
get_target_property(library_type OpenGeode::basic TYPE)
if(library_type STREQUAL "STATIC_LIBRARY")
find_dependency(earcut_hpp)
find_dependency(ZLIB CONFIG)
# minizip-ng calls find_dependency(ZLIB): use the installed zlib-ng config
set(GEODE_PREFER_CONFIG ${CMAKE_FIND_PACKAGE_PREFER_CONFIG})
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
find_dependency(minizip-ng)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${GEODE_PREFER_CONFIG})
find_dependency(nanoflann)
find_dependency(spdlog)
find_dependency(nlohmann_json)
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ include(${PROJECT_SOURCE_DIR}/cmake/ConfigureAbseil.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureAsync++.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureBitsery.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureEarcut.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureZlib.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureMinizip.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureNanoflann.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureSpdlog.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureSQLite.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigurePROJ.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureGDAL.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureJson.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigureZlib.cmake)

if(OPENGEODE_WITH_PYTHON OR INCLUDE_PYBIND11)
include(${PROJECT_SOURCE_DIR}/cmake/ConfigurePybind11.cmake)
Expand Down
70 changes: 64 additions & 6 deletions include/geode/basic/bitsery_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,54 @@

#pragma once

#include <cstddef>
#include <memory>
#include <optional>
#include <string_view>

#include <absl/container/fixed_array.h>
#include <absl/container/inlined_vector.h>
#include <absl/types/span.h>

#include <bitsery/adapter/buffer.h>
#include <bitsery/adapter/stream.h>
#include <bitsery/bitsery.h>
#include <bitsery/ext/inheritance.h>
#include <bitsery/ext/pointer.h>

#include <geode/basic/attribute.hpp>
#include <geode/basic/attribute_manager.hpp>
#include <geode/basic/byte_span.hpp>
#include <geode/basic/common.hpp>
#include <geode/basic/growable.hpp>
#include <geode/basic/range.hpp>

namespace bitsery
{
namespace traits
{
template <>
struct ContainerTraits< geode::ByteSpan >
{
using TValue = char;
static constexpr bool isResizable = false;
static constexpr bool isContiguous = true;
static size_t size( const geode::ByteSpan &container )
{
return container.size();
}
};

template <>
struct BufferAdapterTraits< geode::ByteSpan >
{
using TIterator = const char *;
using TConstIterator = const char *;
using TValue = char;
};
} // namespace traits
} // namespace bitsery

namespace geode
{
using PContext =
Expand All @@ -45,13 +80,13 @@ namespace geode
bitsery::ext::InheritanceContext >;
using Serializer =
bitsery::Serializer< bitsery::OutputBufferedStreamAdapter, TContext >;
/*!
* Deserializer reading a ByteSpan:
* Deserializer archive{ context, bytes.data(), bytes.size() }.
*/
using Deserializer =
bitsery::Deserializer< bitsery::InputStreamAdapter, TContext >;

enum struct BITSERY
{
constructor
};
bitsery::Deserializer< bitsery::InputBufferAdapter< ByteSpan >,
TContext >;

/*!
* Register all the information needed by Bitsery to serialize the objects
Expand Down Expand Up @@ -83,6 +118,29 @@ namespace geode

static void register_deserialize_pcontext( PContext &context );
};

namespace detail
{
/*!
* Deserialize an object from bytes, with the deserialize contexts of
* every registered library.
* @return true if the bytes were read without error, entirely, and
* every pointer was linked.
*/
template < typename Object >
[[nodiscard]] bool deserialize_bytes( ByteSpan bytes, Object &object )
{
TContext context{};
BitseryExtensions::register_deserialize_pcontext(
std::get< 0 >( context ) );
Deserializer archive{ context, bytes.data(), bytes.size() };
archive.object( object );
const auto &adapter = archive.adapter();
return adapter.error() == bitsery::ReaderError::NoError
&& adapter.isCompletedSuccessfully()
&& std::get< 1 >( context ).isValid();
}
} // namespace detail
} // namespace geode

namespace bitsery
Expand Down
35 changes: 35 additions & 0 deletions include/geode/basic/byte_span.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <absl/types/span.h>

namespace geode
{
/*!
* Read-only bytes to deserialize, owned elsewhere (file content, slice of
* an archive in memory...).
*/
using ByteSpan = absl::Span< const char >;
} // namespace geode
151 changes: 151 additions & 0 deletions include/geode/basic/detail/file_content.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once

#include <cstddef>
#include <memory>
#include <optional>
#include <string_view>

#include <geode/basic/byte_span.hpp>
#include <geode/basic/common.hpp>

namespace geode::detail
{
/*!
* Owned bytes, uninitialized at construction.
*/
class ByteBuffer
{
public:
explicit ByteBuffer( size_t size )
: data_{ new char[size] }, size_{ size }
{
}

[[nodiscard]] char* data()
{
return data_.get();
}

[[nodiscard]] size_t size() const
{
return size_;
}

[[nodiscard]] ByteSpan span() const
{
return { data_.get(), size_ };
}

private:
std::unique_ptr< char[] > data_;
size_t size_;
};

/*!
* A whole file mapped read-only in memory: its pages are read from the
* file when first accessed, and belong to the system file cache.
* The file must not be truncated while it is mapped.
*/
class opengeode_basic_api MappedFile
{
public:
/*!
* Map a whole file (UTF-8 path) read-only.
* @return nullptr if the file cannot be mapped (missing, not a regular
* file, or mapping not supported).
*/
[[nodiscard]] static std::shared_ptr< const MappedFile > map(
std::string_view filename );

MappedFile( const MappedFile& ) = delete;
MappedFile& operator=( const MappedFile& ) = delete;
MappedFile( MappedFile&& ) = delete;
MappedFile& operator=( MappedFile&& ) = delete;
~MappedFile();

/*!
* Bytes of the file (empty for an empty file).
*/
[[nodiscard]] ByteSpan span() const;

/*!
* Remove the pages lying entirely within the given bytes of span()
* from the memory of the process (they stay in the file cache).
* The bytes stay readable: their pages are mapped again if accessed.
*/
void release( ByteSpan bytes ) const;

private:
MappedFile( const char* data, size_t size );

private:
const char* data_;
size_t size_;
};

/*!
* Bytes of a file: either a slice of a mapped file (kept mapped while
* this object lives, and released from memory when it is destroyed), or
* an owned buffer.
*/
class opengeode_basic_api FileContent
{
public:
explicit FileContent( ByteBuffer buffer );

/*!
* @param[in] bytes Bytes inside mapping->span().
*/
FileContent(
std::shared_ptr< const MappedFile > mapping, ByteSpan bytes );

FileContent( const FileContent& ) = delete;
FileContent& operator=( const FileContent& ) = delete;
FileContent( FileContent&& other ) noexcept;
FileContent& operator=( FileContent&& ) = delete;
~FileContent();

[[nodiscard]] ByteSpan span() const
{
return bytes_;
}

private:
std::shared_ptr< const MappedFile > mapping_;
std::optional< ByteBuffer > buffer_;
ByteSpan bytes_;
};

/*!
* Content of a whole file (UTF-8 path): mapped when possible, otherwise
* read into memory.
* @return std::nullopt if the file cannot be opened or is not a regular
* file.
* @exception OpenGeodeException (data) if the file cannot be read.
*/
[[nodiscard]] std::optional< FileContent >
opengeode_basic_api map_file_content( std::string_view filename );
} // namespace geode::detail
Loading
Loading