-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling of c++ integer types
- Loading branch information
Showing
5 changed files
with
205 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* juce_python - Python bindings for the JUCE framework. | ||
* | ||
* This file is part of the popsicle project. | ||
* | ||
* Copyright (c) 2024 - kunitoki <[email protected]> | ||
* | ||
* popsicle is an open source library subject to commercial or open-source licensing. | ||
* | ||
* By using popsicle, you agree to the terms of the popsicle License Agreement, which can | ||
* be found at https://raw.githubusercontent.com/kunitoki/popsicle/master/LICENSE | ||
* | ||
* Or: You may also use this code under the terms of the GPL v3 (see www.gnu.org/licenses). | ||
* | ||
* POPSICLE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED | ||
* OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
|
||
namespace popsicle { | ||
|
||
// ================================================================================================= | ||
|
||
template <class T> | ||
class GenericInteger | ||
{ | ||
public: | ||
using underlying_type = T; | ||
|
||
constexpr GenericInteger() = default; | ||
|
||
constexpr GenericInteger (T value) noexcept | ||
: value (value) | ||
{ | ||
} | ||
|
||
constexpr GenericInteger (const GenericInteger& other) = default; | ||
constexpr GenericInteger (GenericInteger&& other) = default; | ||
constexpr GenericInteger& operator= (const GenericInteger& other) = default; | ||
constexpr GenericInteger& operator= (GenericInteger&& other) = default; | ||
|
||
constexpr operator T() const noexcept | ||
{ | ||
return value; | ||
} | ||
|
||
constexpr T get() const noexcept | ||
{ | ||
return value; | ||
} | ||
|
||
private: | ||
T value{}; | ||
}; | ||
|
||
// ================================================================================================= | ||
|
||
template <class T> | ||
struct underlying_type | ||
{ | ||
using type = T; | ||
}; | ||
|
||
template <class T> | ||
struct underlying_type<GenericInteger<T>> | ||
{ | ||
using type = typename GenericInteger<T>::underlying_type; | ||
}; | ||
|
||
|
||
template <class T> | ||
using underlying_type_t = typename underlying_type<T>::type; | ||
|
||
} // namespace popsicle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
|
||
import popsicle as juce | ||
from popsicle import int64 | ||
|
||
#================================================================================================== | ||
|
||
this_file = juce.File(os.path.abspath(__file__)) | ||
data_folder = this_file.getSiblingFile("data") | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_read_only_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.MemoryMappedFile.readOnly) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() > 0 | ||
assert mmf.getRange().getStart() >= 0 | ||
assert mmf.getRange().getEnd() > mmf.getRange().getStart() | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_read_write_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.MemoryMappedFile.readWrite) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() > 0 | ||
assert mmf.getRange().getStart() >= 0 | ||
assert mmf.getRange().getEnd() > mmf.getRange().getStart() | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_exclusive_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.MemoryMappedFile.readOnly, exclusive=True) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() > 0 | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_non_existent_file(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("nonexistent.txt"), juce.MemoryMappedFile.readOnly) | ||
assert mmf.getData() is None | ||
assert mmf.getSize() == 0 | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_section_read_only_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.Range[int64](0, 10), juce.MemoryMappedFile.readOnly) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() == 10 | ||
assert mmf.getRange().getLength() == 10 | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_section_read_write_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.Range[int64](0, 10), juce.MemoryMappedFile.readWrite) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() == 10 | ||
assert mmf.getRange().getLength() == 10 | ||
|
||
#================================================================================================== | ||
|
||
def test_memory_mapped_file_section_exclusive_mode(): | ||
mmf = juce.MemoryMappedFile(data_folder.getChildFile("somefile.txt"), juce.Range[int64](0, 10), juce.MemoryMappedFile.readOnly, exclusive=True) | ||
assert mmf.getData() is not None | ||
assert mmf.getSize() == 10 |