Merge branch 'master' of https://github.com/DigitalPulseSoftware/NazaraEngine
Former-commit-id: 6a6191171a34d24a22c020a8d4c01e7869c3279d
This commit is contained in:
@@ -27,11 +27,11 @@ namespace Nz
|
||||
template<typename T> std::size_t CountOf(const T& c);
|
||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||
|
||||
template<typename T>
|
||||
struct PointedType
|
||||
{
|
||||
using type = void; //< FIXME: I can't make SFINAE work
|
||||
};
|
||||
template<typename T>
|
||||
struct PointedType
|
||||
{
|
||||
using type = void; //< FIXME: I can't make SFINAE work
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct TypeTag {};
|
||||
|
||||
@@ -30,6 +30,16 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Applies the tuple to the function
|
||||
* \return The result of the function
|
||||
*
|
||||
* \param fn Function
|
||||
* \param t Tuple of arguments for the function
|
||||
*
|
||||
* \see Apply
|
||||
*/
|
||||
|
||||
template<typename F, typename Tuple>
|
||||
auto Apply(F&& fn, Tuple&& t)
|
||||
{
|
||||
@@ -38,6 +48,17 @@ namespace Nz
|
||||
return Detail::ApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Applies the tuple to the member function on an object
|
||||
* \return The result of the member function called
|
||||
*
|
||||
* \param object Object of a class
|
||||
* \param fn Member function
|
||||
* \param t Tuple of arguments for the member function
|
||||
*
|
||||
* \see Apply
|
||||
*/
|
||||
|
||||
template<typename O, typename F, typename Tuple>
|
||||
auto Apply(O& object, F&& fn, Tuple&& t)
|
||||
{
|
||||
@@ -46,15 +67,39 @@ namespace Nz
|
||||
return Detail::ApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the hash of a hashable object
|
||||
* \return A bytearray which represents the hash
|
||||
*
|
||||
* \param hash Enumeration of type HashType
|
||||
* \param v Object to hash, must be convertible to "Nz::String"
|
||||
*
|
||||
* \see ComputeHash
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteArray ComputeHash(HashType hash, const T& v)
|
||||
{
|
||||
return ComputeHash(AbstractHash::Get(hash).get(), v);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the hash of a hashable object
|
||||
* \return A bytearray which represents the hash
|
||||
*
|
||||
* \param hash Pointer to abstract hash
|
||||
* \param v Object to hash, must be convertible to "Nz::String"
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to Abstracthash is invalid
|
||||
*
|
||||
* \see ComputeHash
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteArray ComputeHash(AbstractHash* hash, const T& v)
|
||||
{
|
||||
NazaraAssert(hash != nullptr, "Invalid abstracthash pointer");
|
||||
|
||||
hash->Begin();
|
||||
|
||||
HashAppend(hash, v);
|
||||
@@ -62,19 +107,44 @@ namespace Nz
|
||||
return hash->End();
|
||||
}
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
/*!
|
||||
* \brief Returns the number of elements in a C-array
|
||||
* \return The number of elements
|
||||
*
|
||||
* \param name C-array
|
||||
*
|
||||
* \see CountOf
|
||||
*/
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
constexpr std::size_t CountOf(T(&name)[N]) noexcept
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
/*!
|
||||
* \brief Returns the number of elements in a container
|
||||
* \return The number of elements
|
||||
*
|
||||
* \param c Container with the member function "size()"
|
||||
*
|
||||
* \see CountOf
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
std::size_t CountOf(const T& c)
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
// Algorithme venant de CityHash par Google
|
||||
/*!
|
||||
* \brief Combines two hash in one
|
||||
*
|
||||
* \param seed First value that will be modified (expected to be 64bits)
|
||||
* \param v Second value to hash
|
||||
*/
|
||||
|
||||
// Algorithm from CityHash by Google
|
||||
// http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co
|
||||
template<typename T>
|
||||
void HashCombine(std::size_t& seed, const T& v)
|
||||
@@ -91,10 +161,20 @@ namespace Nz
|
||||
seed = static_cast<std::size_t>(b * kMul);
|
||||
}
|
||||
|
||||
template<typename T> struct PointedType<T*> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* volatile> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const volatile> {typedef T type;};
|
||||
template<typename T> struct PointedType<T*> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* volatile> {typedef T type;};
|
||||
template<typename T> struct PointedType<T* const volatile> {typedef T type;};
|
||||
|
||||
/*!
|
||||
* \brief Serializes a boolean
|
||||
* \return true if serialization succedeed
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Boolean to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
|
||||
inline bool Serialize(SerializationContext& context, bool value)
|
||||
{
|
||||
@@ -113,6 +193,16 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Serializes an arithmetic type
|
||||
* \return true if serialization succedeed
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Arithmetic type to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value)
|
||||
{
|
||||
@@ -131,6 +221,16 @@ namespace Nz
|
||||
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unserializes a boolean
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to boolean to unserialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
|
||||
inline bool Unserialize(SerializationContext& context, bool* value)
|
||||
{
|
||||
if (context.currentBitPos == 8)
|
||||
@@ -149,6 +249,18 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unserializes an arithmetic type
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to arithmetic type to serialize
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to value is invalid
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value)
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,59 +8,141 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with a reserved size
|
||||
*
|
||||
* \param n Space reserved
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(size_type n) :
|
||||
m_array()
|
||||
{
|
||||
m_array.reserve(n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with a raw memory and a size
|
||||
*
|
||||
* \param ptr Pointer to raw memory
|
||||
* \param n Size that can be accessed
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(const void* buffer, size_type n) :
|
||||
m_array(static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object with n times the same value
|
||||
*
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline ByteArray::ByteArray(size_type n, const value_type value) :
|
||||
m_array(n, value)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteArray object from two iterators
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
ByteArray::ByteArray(InputIterator first, InputIterator last) :
|
||||
m_array(first, last)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends the content of raw memory
|
||||
*
|
||||
* \param ptr Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Append(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(end(), static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends another array of bytes
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Append(const ByteArray& other)
|
||||
{
|
||||
return Insert(end(), other.begin(), other.end());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns this with n times the same value
|
||||
*
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline void ByteArray::Assign(size_type n, value_type value)
|
||||
{
|
||||
m_array.assign(n, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns this with the content between two iterators
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
void ByteArray::Assign(InputIterator first, InputIterator last)
|
||||
{
|
||||
m_array.assign(first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets last element
|
||||
* \return A reference to last element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::Back()
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets last element
|
||||
* \return A constant reference to last element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::Back() const
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears the content of the string
|
||||
*
|
||||
* \param keepBuffer Should the buffer be kept
|
||||
*/
|
||||
|
||||
inline void ByteArray::Clear(bool keepBuffer)
|
||||
{
|
||||
m_array.clear();
|
||||
@@ -68,142 +150,326 @@ namespace Nz
|
||||
m_array.shrink_to_fit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases an element from the byte array
|
||||
*
|
||||
* \param pos Iterator to the element
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Erase(const_iterator pos)
|
||||
{
|
||||
return m_array.erase(pos);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the elements between the two pointers from the byte array
|
||||
*
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Erase(const_iterator first, const_iterator last)
|
||||
{
|
||||
return m_array.erase(first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets first element
|
||||
* \return A reference to first element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::Front()
|
||||
{
|
||||
return m_array.front();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets first element
|
||||
* \return A constant reference to first element
|
||||
*
|
||||
* \remark If ByteArray is empty, behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::Front() const
|
||||
{
|
||||
return m_array.front();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal allocator of the byte array
|
||||
* \return Allocator
|
||||
*/
|
||||
|
||||
inline ByteArray::allocator_type ByteArray::GetAllocator() const
|
||||
{
|
||||
return m_array.get_allocator();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Raw buffer
|
||||
*/
|
||||
|
||||
inline ByteArray::pointer ByteArray::GetBuffer()
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the capacity of the byte array
|
||||
* \return Capacity of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetCapacity() const noexcept
|
||||
{
|
||||
return m_array.capacity();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the raw buffer
|
||||
* \return Raw buffer
|
||||
*/
|
||||
|
||||
inline ByteArray::const_pointer ByteArray::GetConstBuffer() const
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the maximal size supported by the byte array
|
||||
* \return Biggest size handled
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetMaxSize() const noexcept
|
||||
{
|
||||
return m_array.max_size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte array
|
||||
* \return Size of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::GetSize() const noexcept
|
||||
{
|
||||
return m_array.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a sub byte array of the byte array
|
||||
* \return Sub byte array
|
||||
*
|
||||
* \param startPos First iterator
|
||||
* \param endPos Second iterator
|
||||
*/
|
||||
|
||||
inline ByteArray ByteArray::GetSubArray(const_iterator startPos, const_iterator endPos) const
|
||||
{
|
||||
return ByteArray(startPos, endPos);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content of raw memory at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param buffer Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, const void* buffer, size_type n)
|
||||
{
|
||||
return m_array.insert(pos, static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content of another byte array at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param other Other byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, const ByteArray& other)
|
||||
{
|
||||
return m_array.insert(pos, other.begin(), other.end());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts n times the same value at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param n Number of repetitions
|
||||
* \param value Value to repeat
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Insert(const_iterator pos, size_type n, value_type byte)
|
||||
{
|
||||
return m_array.insert(pos, n, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Inserts the content from two iterators at the iterator position
|
||||
*
|
||||
* \param pos Iterator to the position
|
||||
* \param first First iterator
|
||||
* \param last Second iterator
|
||||
*/
|
||||
|
||||
template <class InputIterator>
|
||||
ByteArray::iterator ByteArray::Insert(const_iterator pos, InputIterator first, InputIterator last)
|
||||
{
|
||||
return m_array.insert(pos, first, last);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the byte array is empty
|
||||
* \return true if byte array is empty
|
||||
*/
|
||||
|
||||
inline bool ByteArray::IsEmpty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the last element
|
||||
*
|
||||
* \remark If byte array is empty, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void ByteArray::PopBack()
|
||||
{
|
||||
Erase(end() - 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Erases the first element
|
||||
*
|
||||
* \remark If byte array is empty, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void ByteArray::PopFront()
|
||||
{
|
||||
Erase(begin());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Prepends the content of raw memory
|
||||
*
|
||||
* \param ptr Constant pointer to raw memory
|
||||
* \param n Size that can be read
|
||||
*
|
||||
* \remark If preallocated space of ptr is less than the size, the behaviour is undefined
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Prepend(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(begin(), buffer, n);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Prepends another array of bytes
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*
|
||||
* \see Insert
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::Prepend(const ByteArray& other)
|
||||
{
|
||||
return Insert(begin(), other);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pushes the byte at the end
|
||||
*
|
||||
* \param byte Byte to add
|
||||
*/
|
||||
|
||||
inline void ByteArray::PushBack(const value_type byte)
|
||||
{
|
||||
m_array.push_back(byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Pushes the byte at the beginning
|
||||
*
|
||||
* \param byte Byte to add
|
||||
*/
|
||||
|
||||
inline void ByteArray::PushFront(const value_type byte)
|
||||
{
|
||||
m_array.insert(begin(), 1, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reserves enough memory for the buffer size
|
||||
*
|
||||
* \param bufferSize Size of the buffer to allocate
|
||||
*
|
||||
* \remark If bufferSize is smaller than the old one, nothing is done
|
||||
*/
|
||||
|
||||
inline void ByteArray::Reserve(size_type bufferSize)
|
||||
{
|
||||
m_array.reserve(bufferSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resizes the string
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param newSize Target size
|
||||
*/
|
||||
|
||||
inline void ByteArray::Resize(size_type newSize)
|
||||
{
|
||||
m_array.resize(newSize);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resizes the string
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param newSize Target size
|
||||
* \param byte Byte to add if newSize is greather than actual size
|
||||
*/
|
||||
|
||||
inline void ByteArray::Resize(size_type newSize, const value_type byte)
|
||||
{
|
||||
m_array.resize(newSize, byte);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Releases the excedent memory
|
||||
*/
|
||||
|
||||
inline void ByteArray::ShrinkToFit()
|
||||
{
|
||||
m_array.shrink_to_fit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Swaps the content with the other byte array
|
||||
*
|
||||
* \param other Other byte array to swap with
|
||||
*/
|
||||
|
||||
inline void ByteArray::Swap(ByteArray& other)
|
||||
{
|
||||
m_array.swap(other.m_array);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gives a string representation in base 16
|
||||
* \return String in base 16
|
||||
*/
|
||||
|
||||
inline String ByteArray::ToHex() const
|
||||
{
|
||||
std::size_t length = m_array.size() * 2;
|
||||
@@ -215,76 +481,153 @@ namespace Nz
|
||||
return hexOutput;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gives a string representation
|
||||
* \return String where each byte is converted to char
|
||||
*/
|
||||
|
||||
inline String ByteArray::ToString() const
|
||||
{
|
||||
return String(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::begin() noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::begin() const noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::cbegin() const noexcept
|
||||
{
|
||||
return m_array.cbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::cend() const noexcept
|
||||
{
|
||||
return m_array.cend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::crbegin() const noexcept
|
||||
{
|
||||
return m_array.crbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a constant reversed iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::crend() const noexcept
|
||||
{
|
||||
return m_array.crend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the byte array is empty
|
||||
* \return true if byte array is empty
|
||||
*/
|
||||
|
||||
inline bool ByteArray::empty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::iterator ByteArray::end() noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns an iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_iterator ByteArray::end() const noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::reverse_iterator ByteArray::rbegin() noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the beggining of the string
|
||||
* \return Beggining of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reverse_iterator ByteArray::rbegin() const noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a reversed iterator pointing to the end of the string
|
||||
* \return End of the string
|
||||
*/
|
||||
|
||||
inline ByteArray::reverse_iterator ByteArray::rend() noexcept
|
||||
{
|
||||
return m_array.rend();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte array
|
||||
* \return Size of the byte array
|
||||
*/
|
||||
|
||||
inline ByteArray::size_type ByteArray::size() const noexcept
|
||||
{
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith byte
|
||||
* \return A reference to the byte at the ith position
|
||||
*
|
||||
* \remark Produces a NazaraAssert if pos is greather than the size
|
||||
*/
|
||||
|
||||
inline ByteArray::reference ByteArray::operator[](size_type pos)
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
@@ -292,6 +635,13 @@ namespace Nz
|
||||
return m_array[pos];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith byte
|
||||
* \return A constant reference to the byte at the ith position
|
||||
*
|
||||
* \remark Produces a NazaraAssert if pos is greather than the size
|
||||
*/
|
||||
|
||||
inline ByteArray::const_reference ByteArray::operator[](size_type pos) const
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
@@ -299,6 +649,13 @@ namespace Nz
|
||||
return m_array[pos];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Concatenates the byte array to another
|
||||
* \return ByteArray which is the result of the concatenation
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*/
|
||||
|
||||
inline ByteArray ByteArray::operator+(const ByteArray& other) const
|
||||
{
|
||||
ByteArray tmp(*this);
|
||||
@@ -307,6 +664,13 @@ namespace Nz
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Concatenates the byte array to this byte array
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param other ByteArray to add
|
||||
*/
|
||||
|
||||
inline ByteArray& ByteArray::operator+=(const ByteArray& other)
|
||||
{
|
||||
Append(other);
|
||||
@@ -314,31 +678,79 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is equal to the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator==(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array == rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is equal to the second byte array
|
||||
* \return false if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator!=(const ByteArray& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is less than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator<(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array < rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is less or equal than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator<=(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array <= rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is greather than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator>(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array > rhs.m_array;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the first byte array is greather or equal than the second byte array
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param first ByteArray to compare in left hand side
|
||||
* \param second ByteArray to compare in right hand side
|
||||
*/
|
||||
|
||||
inline bool ByteArray::operator>=(const ByteArray& rhs) const
|
||||
{
|
||||
return m_array >= rhs.m_array;
|
||||
@@ -353,6 +765,13 @@ namespace Nz
|
||||
|
||||
namespace std
|
||||
{
|
||||
/*!
|
||||
* \brief Swaps two byte arrays, specialisation of std
|
||||
*
|
||||
* \param lhs First byte array
|
||||
* \param rhs Second byte array
|
||||
*/
|
||||
|
||||
inline void swap(Nz::ByteArray& lhs, Nz::ByteArray& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
|
||||
@@ -7,11 +7,25 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a ByteStream object with a stream
|
||||
*
|
||||
* \remark Produces a NazaraAssert if stream is invalid
|
||||
*/
|
||||
|
||||
inline ByteStream::ByteStream(Stream* stream)
|
||||
{
|
||||
NazaraAssert(stream, "Invalid stream");
|
||||
|
||||
m_context.stream = stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ByteStream object by move semantic
|
||||
*
|
||||
* \param stream ByteStream to move into this
|
||||
*/
|
||||
|
||||
inline ByteStream::ByteStream(ByteStream&& stream) :
|
||||
m_ownedStream(std::move(stream.m_ownedStream)),
|
||||
m_context(stream.m_context)
|
||||
@@ -19,17 +33,35 @@ namespace Nz
|
||||
stream.m_context.stream = nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and calls FlushBits
|
||||
*
|
||||
* \remark Produces a NazaraWarning if flush did not work
|
||||
*
|
||||
* \see FlushBits
|
||||
*/
|
||||
|
||||
inline ByteStream::~ByteStream()
|
||||
{
|
||||
if (!FlushBits())
|
||||
NazaraWarning("Failed to flush bits at serializer destruction");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the stream endianness
|
||||
* \return Type of the endianness
|
||||
*/
|
||||
|
||||
inline Endianness ByteStream::GetDataEndianness() const
|
||||
{
|
||||
return m_context.endianness;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the size of the byte stream
|
||||
* \return Size of the stream
|
||||
*/
|
||||
|
||||
inline Nz::UInt64 ByteStream::GetSize() const
|
||||
{
|
||||
if (m_context.stream)
|
||||
@@ -38,11 +70,21 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal stream
|
||||
* \return Internal stream
|
||||
*/
|
||||
|
||||
inline Stream* ByteStream::GetStream() const
|
||||
{
|
||||
return m_context.stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Flushes the stream
|
||||
* \return true if flushing is successful
|
||||
*/
|
||||
|
||||
inline bool ByteStream::FlushBits()
|
||||
{
|
||||
if (!m_context.stream)
|
||||
@@ -59,6 +101,14 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reads data
|
||||
* \return Number of data read
|
||||
*
|
||||
* \param buffer Preallocated buffer to contain information read
|
||||
* \param size Size of the read and thus of the buffer
|
||||
*/
|
||||
|
||||
inline std::size_t ByteStream::Read(void* ptr, std::size_t size)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
@@ -68,13 +118,29 @@ namespace Nz
|
||||
return m_context.stream->Read(ptr, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the stream endianness
|
||||
*
|
||||
* \param Type of the endianness
|
||||
*/
|
||||
|
||||
inline void ByteStream::SetDataEndianness(Endianness endiannes)
|
||||
{
|
||||
m_context.endianness = endiannes;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets this with a stream
|
||||
*
|
||||
* \param stream Stream existing
|
||||
*
|
||||
* \remark Produces a NazaraAssert if stream is invalid
|
||||
*/
|
||||
|
||||
inline void ByteStream::SetStream(Stream* stream)
|
||||
{
|
||||
NazaraAssert(stream, "Invalid stream");
|
||||
|
||||
// We don't want to lose some bits..
|
||||
FlushBits();
|
||||
|
||||
@@ -82,6 +148,16 @@ namespace Nz
|
||||
m_ownedStream.reset();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Writes data
|
||||
* \return Number of data written
|
||||
*
|
||||
* \param buffer Preallocated buffer containing information to write
|
||||
* \param size Size of the writting and thus of the buffer
|
||||
*
|
||||
* \remark Produces a NazaraAssert if buffer is nullptr
|
||||
*/
|
||||
|
||||
inline void ByteStream::Write(const void* data, std::size_t size)
|
||||
{
|
||||
if (!m_context.stream)
|
||||
@@ -91,6 +167,15 @@ namespace Nz
|
||||
m_context.stream->Write(data, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Outputs a data from the stream
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param value Value to unserialize
|
||||
*
|
||||
* \remark Produces a NazaraError if unserialization failed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteStream& ByteStream::operator>>(T& value)
|
||||
{
|
||||
@@ -103,6 +188,15 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds the data to the stream
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param value Value to serialize
|
||||
*
|
||||
* \remark Produces a NazaraError if serialization failed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteStream& ByteStream::operator<<(const T& value)
|
||||
{
|
||||
@@ -115,6 +209,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the other byte stream into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param stream ByteStream to move in this
|
||||
*/
|
||||
|
||||
inline ByteStream& ByteStream::operator=(ByteStream&& stream)
|
||||
{
|
||||
m_context = stream.m_context;
|
||||
|
||||
@@ -7,17 +7,38 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::CallOnExit
|
||||
* \brief Core class that represents a function to call at the end of the scope
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a CallOnExit object with a function
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline CallOnExit::CallOnExit(Func func) :
|
||||
m_func(func)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and calls the function
|
||||
*/
|
||||
|
||||
inline CallOnExit::~CallOnExit()
|
||||
{
|
||||
if (m_func)
|
||||
m_func();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calls the function and sets the new callback
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline void CallOnExit::CallAndReset(Func func)
|
||||
{
|
||||
if (m_func)
|
||||
@@ -26,6 +47,12 @@ namespace Nz
|
||||
Reset(func);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the function
|
||||
*
|
||||
* \param func Function to call on exit
|
||||
*/
|
||||
|
||||
inline void CallOnExit::Reset(Func func)
|
||||
{
|
||||
m_func = func;
|
||||
|
||||
@@ -11,10 +11,28 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::Color
|
||||
* \brief Core class that represents a color
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object by default
|
||||
*/
|
||||
|
||||
inline Color::Color()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with values
|
||||
*
|
||||
* \param red Red value
|
||||
* \param green Green value
|
||||
* \param blue Blue value
|
||||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 red, UInt8 green, UInt8 blue, UInt8 alpha) :
|
||||
r(red),
|
||||
g(green),
|
||||
@@ -23,6 +41,12 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with a light level
|
||||
*
|
||||
* \param lightness Value for r, g and b
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 lightness) :
|
||||
r(lightness),
|
||||
g(lightness),
|
||||
@@ -31,6 +55,13 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Color object with values
|
||||
*
|
||||
* \param vec[3] vec[0] = red value, vec[1] = green value, vec[2] = blue value
|
||||
* \param alpha Alpha value
|
||||
*/
|
||||
|
||||
inline Color::Color(UInt8 vec[3], UInt8 alpha) :
|
||||
r(vec[0]),
|
||||
g(vec[1]),
|
||||
@@ -39,6 +70,11 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts this to string
|
||||
* \return String representation of the object "Color(r, g, b[, a])"
|
||||
*/
|
||||
|
||||
inline String Color::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
@@ -52,6 +88,13 @@ namespace Nz
|
||||
return ss;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds two colors together
|
||||
* \return Color which is the sum
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator+(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
@@ -64,6 +107,13 @@ namespace Nz
|
||||
return c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Multiplies two colors together
|
||||
* \return Color which is the product
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator*(const Color& color) const
|
||||
{
|
||||
///TODO: Improve this shit
|
||||
@@ -76,48 +126,104 @@ namespace Nz
|
||||
return c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds the color to this
|
||||
* \return Color which is the sum
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator+=(const Color& color)
|
||||
{
|
||||
return operator=(operator+(color));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Multiplies the color to this
|
||||
* \return Color which is the product
|
||||
*
|
||||
* \param color Other color
|
||||
*/
|
||||
|
||||
inline Color Color::operator*=(const Color& color)
|
||||
{
|
||||
return operator=(operator*(color));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the two colors are equal
|
||||
* \return true if it is the case
|
||||
*
|
||||
* \param color Color to compare
|
||||
*/
|
||||
|
||||
inline bool Color::operator==(const Color& color) const
|
||||
{
|
||||
return r == color.r && g == color.g && b == color.b && a == color.a;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the two colors are equal
|
||||
* \return false if it is the case
|
||||
*
|
||||
* \param color Color to compare
|
||||
*/
|
||||
|
||||
inline bool Color::operator!=(const Color& color) const
|
||||
{
|
||||
return !operator==(color);
|
||||
}
|
||||
|
||||
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
|
||||
// Algorithm coming from http://www.easyrgb.com/index.php?X=MATH
|
||||
|
||||
/*!
|
||||
* \brief Converts CMY representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMY(float cyan, float magenta, float yellow)
|
||||
{
|
||||
return Color(static_cast<UInt8>((1.f-cyan)*255.f), static_cast<UInt8>((1.f-magenta)*255.f), static_cast<UInt8>((1.f-yellow)*255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts CMYK representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
* \param black Black component
|
||||
*/
|
||||
|
||||
inline Color Color::FromCMYK(float cyan, float magenta, float yellow, float black)
|
||||
{
|
||||
return FromCMY(cyan * (1.f - black) + black,
|
||||
magenta * (1.f - black) + black,
|
||||
yellow * (1.f - black) + black);
|
||||
magenta * (1.f - black) + black,
|
||||
yellow * (1.f - black) + black);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HSL representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param lightness Lightness component
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSL(UInt8 hue, UInt8 saturation, UInt8 lightness)
|
||||
{
|
||||
if (saturation == 0)
|
||||
{
|
||||
// RGB results from 0 to 255
|
||||
return Color(lightness * 255,
|
||||
lightness * 255,
|
||||
lightness * 255);
|
||||
lightness * 255,
|
||||
lightness * 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -135,11 +241,20 @@ namespace Nz
|
||||
float v1 = 2.f * l - v2;
|
||||
|
||||
return Color(static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h + (1.f/3.f))),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h)),
|
||||
static_cast<UInt8>(255.f * Hue2RGB(v1, v2, h - (1.f/3.f))));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HSV representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param value Value component
|
||||
*/
|
||||
|
||||
inline Color Color::FromHSV(float hue, float saturation, float value)
|
||||
{
|
||||
if (NumberEquals(saturation, 0.f))
|
||||
@@ -201,11 +316,28 @@ namespace Nz
|
||||
return Color(static_cast<UInt8>(r*255.f), static_cast<UInt8>(g*255.f), static_cast<UInt8>(b*255.f));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts XYZ representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(const Vector3f& vec)
|
||||
{
|
||||
return FromXYZ(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts XYZ representation to RGB
|
||||
* \return Color resulting
|
||||
*
|
||||
* \param x X component
|
||||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline Color Color::FromXYZ(float x, float y, float z)
|
||||
{
|
||||
x /= 100.f; // X from 0 to 95.047
|
||||
@@ -234,6 +366,15 @@ namespace Nz
|
||||
return Color(static_cast<UInt8>(r * 255.f), static_cast<UInt8>(g * 255.f), static_cast<UInt8>(b * 255.f));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to CMYK
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline void Color::ToCMY(const Color& color, float* cyan, float* magenta, float* yellow)
|
||||
{
|
||||
*cyan = 1.f - color.r/255.f;
|
||||
@@ -241,6 +382,15 @@ namespace Nz
|
||||
*yellow = 1.f - color.b/255.f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to CMYK
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param cyan Cyan component
|
||||
* \param magenta Magenta component
|
||||
* \param yellow Yellow component
|
||||
*/
|
||||
|
||||
inline void Color::ToCMYK(const Color& color, float* cyan, float* magenta, float* yellow, float* black)
|
||||
{
|
||||
float c, m, y;
|
||||
@@ -265,6 +415,15 @@ namespace Nz
|
||||
*black = k;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to HSL
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param lightness Lightness component
|
||||
*/
|
||||
|
||||
inline void Color::ToHSL(const Color& color, UInt8* hue, UInt8* saturation, UInt8* lightness)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
@@ -315,6 +474,15 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to HSV
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param hue Hue component
|
||||
* \param saturation Saturation component
|
||||
* \param value Value component
|
||||
*/
|
||||
|
||||
inline void Color::ToHSV(const Color& color, float* hue, float* saturation, float* value)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
@@ -361,11 +529,27 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to XYZ
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param vec Vector3 representing the space color
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, Vector3f* vec)
|
||||
{
|
||||
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts RGB representation to XYZ
|
||||
*
|
||||
* \param color Color to transform
|
||||
* \param x X component
|
||||
* \param y Y component
|
||||
* \param z Z component
|
||||
*/
|
||||
|
||||
inline void Color::ToXYZ(const Color& color, float* x, float* y, float* z)
|
||||
{
|
||||
float r = color.r/255.f; //R from 0 to 255
|
||||
@@ -397,6 +581,15 @@ namespace Nz
|
||||
*z = r*0.0193f + g*0.1192f + b*0.9505f;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts HUE representation to RGV
|
||||
* \return RGB corresponding
|
||||
*
|
||||
* \param v1 V1 component
|
||||
* \param v2 V2 component
|
||||
* \param vH VH component
|
||||
*/
|
||||
|
||||
inline float Color::Hue2RGB(float v1, float v2, float vH)
|
||||
{
|
||||
if (vH < 0.f)
|
||||
@@ -415,8 +608,16 @@ namespace Nz
|
||||
return v1 + (v2 - v1)*(2.f/3.f - vH)*6;
|
||||
|
||||
return v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Output operator
|
||||
* \return The stream
|
||||
*
|
||||
* \param out The stream
|
||||
* \param color The color to output
|
||||
*/
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const Nz::Color& color)
|
||||
{
|
||||
|
||||
@@ -27,36 +27,36 @@
|
||||
#ifndef NAZARA_CONFIG_CORE_HPP
|
||||
#define NAZARA_CONFIG_CORE_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
/// Each modification of a parameter needs a recompilation of the module
|
||||
|
||||
// Précision des réels lors de la transformation en chaîne de caractère (Max. chiffres après la virgule)
|
||||
// Precision of reals when transformed into string (Max. numbers after the coma)
|
||||
#define NAZARA_CORE_DECIMAL_DIGITS 6
|
||||
|
||||
// Duplique la sortie du log sur le flux de sortie standard (cout)
|
||||
// Duplicate the log output on the standard output flux (cout)
|
||||
#define NAZARA_CORE_DUPLICATE_LOG_TO_COUT 0
|
||||
|
||||
// Teste les assertions
|
||||
// Checks the assertions
|
||||
#define NAZARA_CORE_ENABLE_ASSERTS 0
|
||||
|
||||
// Appelle exit dès qu'une assertion est invalide
|
||||
// Call exit when an assertion is invalid
|
||||
#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1
|
||||
|
||||
// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash)
|
||||
// Size of buffer when reading entirely a file (ex: Hash)
|
||||
#define NAZARA_CORE_FILE_BUFFERSIZE 4096
|
||||
|
||||
// Incorpore la table Unicode Character Data (Nécessaires pour faire fonctionner le flag String::HandleUTF8)
|
||||
// Incorporate the Unicode Character Data table (Necessary to make it work with the flag String::HandleUTF8)
|
||||
#define NAZARA_CORE_INCLUDE_UNICODEDATA 0
|
||||
|
||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_CORE_SAFE 1
|
||||
|
||||
// Protège les classes des accès concurrentiels
|
||||
// Protect the classes against data race
|
||||
#define NAZARA_CORE_THREADSAFE 1
|
||||
|
||||
// Les classes à protéger des accès concurrentiels
|
||||
// Classes to protect against data race
|
||||
#define NAZARA_THREADSAFETY_CLOCK 0 // Clock
|
||||
#define NAZARA_THREADSAFETY_DIRECTORY 1 // Directory
|
||||
#define NAZARA_THREADSAFETY_DYNLIB 1 // DynLib
|
||||
@@ -64,18 +64,19 @@
|
||||
#define NAZARA_THREADSAFETY_LOG 1 // Log
|
||||
#define NAZARA_THREADSAFETY_REFCOUNTED 1 // RefCounted
|
||||
|
||||
// Le nombre de spinlocks à utiliser avec les sections critiques de Windows (0 pour désactiver)
|
||||
// Number of spinlocks to use with the Windows critical sections (0 to disable)
|
||||
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
|
||||
|
||||
// Optimise l'implémentation Windows avec certaines avancées de Windows vista (Casse la compatibilité XP)
|
||||
// Optimize the Windows implementation with technologies of Windows vista (and greather) (Break the compatibility with XP)
|
||||
#define NAZARA_CORE_WINDOWS_VISTA 0
|
||||
|
||||
|
||||
/*
|
||||
// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes)
|
||||
// Sets the time between waking thread timers and activating a timer (in milliseconds)
|
||||
#define NAZARA_CORE_TIMER_WAKEUPTIME 10
|
||||
*/
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
/// Checking the values and types of certain constants
|
||||
#include <Nazara/Core/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#ifndef NAZARA_CONFIG_CHECK_CORE_HPP
|
||||
#define NAZARA_CONFIG_CHECK_CORE_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
// We fore the value of MANAGE_MEMORY in debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY
|
||||
#undef NAZARA_CORE_MANAGE_MEMORY
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 0
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
// We assume that Debug.hpp has already been included, same thing for Config.hpp
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
using DynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
|
||||
using DynLibFunc = int (*)(); // "Generic" type of poiter to function
|
||||
|
||||
class DynLibImpl;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Nz
|
||||
|
||||
mutable String m_lastError;
|
||||
DynLibImpl* m_impl;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_DYNLIB_HPP
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
|
||||
#if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN)
|
||||
// Détection automatique selon les macros du compilateur
|
||||
// Automatic detection following macroes of compiler
|
||||
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
||||
#define NAZARA_BIG_ENDIAN
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64) || defined(_M_I86) || \
|
||||
defined(_M_IX86) || defined(_M_X64)
|
||||
defined(_M_IX86) || defined(_M_X64)
|
||||
#define NAZARA_LITTLE_ENDIAN
|
||||
#else
|
||||
#error Failed to identify endianness, you must define either NAZARA_BIG_ENDIAN or NAZARA_LITTLE_ENDIAN
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Gets the platform endianness
|
||||
* \return Type of the endianness
|
||||
*/
|
||||
|
||||
inline constexpr Endianness GetPlatformEndianness()
|
||||
{
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
@@ -16,11 +21,20 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Swaps the byte for endianness operations
|
||||
*
|
||||
* \param buffer Raw memory
|
||||
* \param size Size to change endianness
|
||||
*
|
||||
* \remark If size is greather than the preallocated buffer, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline void SwapBytes(void* buffer, unsigned int size)
|
||||
{
|
||||
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
|
||||
unsigned int i = 0;
|
||||
unsigned int j = size-1;
|
||||
unsigned int j = size - 1;
|
||||
|
||||
while (i < j)
|
||||
std::swap(bytes[i++], bytes[j--]);
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Nz
|
||||
|
||||
enum CursorPosition
|
||||
{
|
||||
CursorPosition_AtBegin, // Début du fichier
|
||||
CursorPosition_AtCurrent, // Position du pointeur
|
||||
CursorPosition_AtEnd, // Fin du fichier
|
||||
CursorPosition_AtBegin, // beginning of the file
|
||||
CursorPosition_AtCurrent, // Position of the cursor
|
||||
CursorPosition_AtEnd, // End of the file
|
||||
|
||||
CursorPosition_Max = CursorPosition_AtEnd
|
||||
};
|
||||
@@ -45,7 +45,7 @@ namespace Nz
|
||||
ErrorFlag_ThrowException = 0x4,
|
||||
ErrorFlag_ThrowExceptionDisabled = 0x8,
|
||||
|
||||
ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled*2-1
|
||||
ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled * 2 - 1
|
||||
};
|
||||
|
||||
enum ErrorType
|
||||
@@ -75,18 +75,18 @@ namespace Nz
|
||||
|
||||
enum OpenModeFlags
|
||||
{
|
||||
OpenMode_NotOpen = 0x00, // Utilise le mode d'ouverture actuel
|
||||
OpenMode_NotOpen = 0x00, // Use the current mod of opening
|
||||
|
||||
OpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
OpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
OpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture
|
||||
OpenMode_Text = 0x10, // Ouvre en mode texte
|
||||
OpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
|
||||
OpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
|
||||
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
|
||||
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
|
||||
OpenMode_ReadOnly = 0x04, // Open in read only
|
||||
OpenMode_Text = 0x10, // Open in text mod
|
||||
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
|
||||
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
|
||||
|
||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Ouvre en lecture/écriture
|
||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
|
||||
|
||||
OpenMode_Max = OpenMode_WriteOnly*2 - 1
|
||||
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
|
||||
};
|
||||
|
||||
enum ParameterType
|
||||
@@ -177,7 +177,7 @@ namespace Nz
|
||||
StreamOption_Sequential = 0x1,
|
||||
StreamOption_Text = 0x2,
|
||||
|
||||
StreamOption_Max = StreamOption_Text*2 - 1
|
||||
StreamOption_Max = StreamOption_Text * 2 - 1
|
||||
};
|
||||
|
||||
enum Ternary
|
||||
|
||||
@@ -8,11 +8,27 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Computes the hash for the file
|
||||
* \return ByteArray represing the result of the hash of the file
|
||||
*
|
||||
* \param hash Hash to execute
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(HashType hash, const String& filePath)
|
||||
{
|
||||
return ComputeHash(AbstractHash::Get(hash).get(), filePath);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Computes the hash for the file
|
||||
* \return ByteArray represing the result of the hash of the file
|
||||
*
|
||||
* \param hash Hash to execute
|
||||
* \param filePath Path for the file
|
||||
*/
|
||||
|
||||
inline ByteArray File::ComputeHash(AbstractHash* hash, const String& filePath)
|
||||
{
|
||||
return Nz::ComputeHash(hash, File(filePath));
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
|
||||
// Inspiré du code de la SFML par Laurent Gomila
|
||||
// Inspired from the of code of the SFML by Laurent Gomila
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -6,18 +6,40 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::StdLogger
|
||||
* \brief Core class that represents a functor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a FunctorWithoutArgs object with a function
|
||||
*
|
||||
* \param func Function to execute
|
||||
*/
|
||||
|
||||
template<typename F>
|
||||
FunctorWithoutArgs<F>::FunctorWithoutArgs(F func) :
|
||||
m_func(func)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runs the function
|
||||
*/
|
||||
|
||||
template<typename F>
|
||||
void FunctorWithoutArgs<F>::Run()
|
||||
{
|
||||
m_func();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a FunctorWithoutArgs object with a function and its arguments
|
||||
*
|
||||
* \param func Function to execute
|
||||
* \param args Arguments for the function
|
||||
*/
|
||||
|
||||
template<typename F, typename... Args>
|
||||
FunctorWithArgs<F, Args...>::FunctorWithArgs(F func, Args&&... args) :
|
||||
m_func(func),
|
||||
@@ -25,12 +47,22 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runs the function
|
||||
*/
|
||||
|
||||
template<typename F, typename... Args>
|
||||
void FunctorWithArgs<F, Args...>::Run()
|
||||
{
|
||||
Apply(m_func, m_args);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a FunctorWithoutArgs object with a member function and an object
|
||||
*
|
||||
* \param func Member function to execute
|
||||
* \param object Object to execute on
|
||||
*/
|
||||
|
||||
template<typename C>
|
||||
MemberWithoutArgs<C>::MemberWithoutArgs(void (C::*func)(), C* object) :
|
||||
@@ -39,6 +71,10 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runs the function
|
||||
*/
|
||||
|
||||
template<typename C>
|
||||
void MemberWithoutArgs<C>::Run()
|
||||
{
|
||||
|
||||
@@ -47,6 +47,16 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Nz::Initializer<Args...>
|
||||
* \brief Core class that represents a module initializer
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Initializer object with a boolean
|
||||
*
|
||||
* \param initialize Initialize the module
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Initializer<Args...>::Initializer(bool initialize) :
|
||||
@@ -56,12 +66,24 @@ namespace Nz
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and call Uninitialize
|
||||
*
|
||||
* \see Uninitialize
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Initializer<Args...>::~Initializer()
|
||||
{
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Initialize the module
|
||||
*
|
||||
* \see Uninitialize
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
bool Initializer<Args...>::Initialize()
|
||||
{
|
||||
@@ -71,12 +93,23 @@ namespace Nz
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the module is initialized
|
||||
* \return true if initialized
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
bool Initializer<Args...>::IsInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uninitialize the module
|
||||
*
|
||||
* \see Initialize
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Initializer<Args...>::Uninitialize()
|
||||
{
|
||||
@@ -84,6 +117,11 @@ namespace Nz
|
||||
Detail::Initializer<Args...>::Uninit();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the initializer to boolean
|
||||
* \return true if initialized
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Initializer<Args...>::operator bool() const
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Je ne suis pas fier des cinq lignes qui suivent mais difficile de faire autrement pour le moment...
|
||||
// I'm not proud of those five following lines but ti's hard to do with another way now
|
||||
#ifdef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#define NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION_DEFINED
|
||||
#else
|
||||
@@ -16,6 +16,17 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \fn Nz::MemoryHelper
|
||||
* \brief Core functions that helps the handle of memory in the engine
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Calls the operator delete on the pointer
|
||||
*
|
||||
* \remark Uses MemoryManager with NAZARA_CORE_MANAGE_MEMORY defined else operator delete
|
||||
*/
|
||||
|
||||
inline void OperatorDelete(void* ptr)
|
||||
{
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
@@ -25,6 +36,12 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calls the operator new on the pointer
|
||||
*
|
||||
* \remark Uses MemoryManager with NAZARA_CORE_MANAGE_MEMORY defined else operator new
|
||||
*/
|
||||
|
||||
inline void* OperatorNew(std::size_t size)
|
||||
{
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
@@ -34,6 +51,14 @@ namespace Nz
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs the object inplace
|
||||
* \return Pointer to the constructed object
|
||||
*
|
||||
* \param ptr Pointer to raw memory allocated
|
||||
* \param args Arguments for the constructor
|
||||
*/
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* PlacementNew(void* ptr, Args&&... args)
|
||||
{
|
||||
@@ -43,7 +68,7 @@ namespace Nz
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
// Si c'est nous qui avons défini la constante, alors il nous faut l'enlever (Pour éviter que le moteur entier n'en souffre)
|
||||
// If we have defined the constant, then we have to undefine it (to avoid bloating in the engine)
|
||||
#ifndef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION_DEFINED
|
||||
#undef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Nz
|
||||
private:
|
||||
MemoryPool(MemoryPool* pool);
|
||||
|
||||
std::unique_ptr<void*[]> m_freeList;
|
||||
std::unique_ptr<void* []> m_freeList;
|
||||
std::unique_ptr<UInt8[]> m_pool;
|
||||
std::unique_ptr<MemoryPool> m_next;
|
||||
std::atomic_uint m_freeCount;
|
||||
|
||||
@@ -8,6 +8,19 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::MemoryPool
|
||||
* \brief Core class that represents a memory pool
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a MemoryPool object
|
||||
*
|
||||
* \param blockSize Size of blocks that will be allocated
|
||||
* \param size Size of the pool
|
||||
* \param canGrow Determine if the pool can allocate more memory
|
||||
*/
|
||||
|
||||
inline MemoryPool::MemoryPool(unsigned int blockSize, unsigned int size, bool canGrow) :
|
||||
m_freeCount(size),
|
||||
m_previous(nullptr),
|
||||
@@ -16,27 +29,47 @@ namespace Nz
|
||||
m_size(size)
|
||||
{
|
||||
m_pool.reset(new UInt8[blockSize * size]);
|
||||
m_freeList.reset(new void*[size]);
|
||||
m_freeList.reset(new void* [size]);
|
||||
|
||||
// Remplissage de la free list
|
||||
for (unsigned int i = 0; i < size; ++i)
|
||||
m_freeList[i] = &m_pool[m_blockSize * (size-i-1)];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a MemoryPool object by move semantic
|
||||
*
|
||||
* \param pool MemoryPool to move into this
|
||||
*/
|
||||
|
||||
inline MemoryPool::MemoryPool(MemoryPool&& pool) noexcept
|
||||
{
|
||||
operator=(std::move(pool));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a MemoryPool object by chaining memory pool
|
||||
*
|
||||
* \param pool Previous MemoryPool
|
||||
*/
|
||||
|
||||
inline MemoryPool::MemoryPool(MemoryPool* pool) :
|
||||
MemoryPool(pool->m_blockSize, pool->m_size, pool->m_canGrow)
|
||||
{
|
||||
m_previous = pool;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Allocates enough memory for the size and returns a pointer to it
|
||||
* \return A pointer to memory allocated
|
||||
*
|
||||
* \param size Size to allocate
|
||||
*
|
||||
* \remark If the size is greather than the blockSize of pool, new operator is called
|
||||
*/
|
||||
|
||||
inline void* MemoryPool::Allocate(unsigned int size)
|
||||
{
|
||||
///DOC: Si la taille est supérieure à celle d'un bloc du pool, l'opérateur new est utilisé
|
||||
if (size <= m_blockSize)
|
||||
{
|
||||
if (m_freeCount > 0)
|
||||
@@ -53,10 +86,17 @@ namespace Nz
|
||||
return OperatorNew(size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Deletes the memory represented by the poiner
|
||||
*
|
||||
* Calls the destructor of the object before releasing it
|
||||
*
|
||||
* \remark If ptr is null, nothing is done
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline void MemoryPool::Delete(T* ptr)
|
||||
{
|
||||
///DOC: Va appeler le destructeur de l'objet avant de le libérer
|
||||
if (ptr)
|
||||
{
|
||||
ptr->~T();
|
||||
@@ -64,12 +104,20 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Frees the memory represented by the poiner
|
||||
*
|
||||
* If the pool gets empty after the call and we are the child of another pool, we commit suicide. If the pointer does not own to a block of the pool, operator delete is called
|
||||
*
|
||||
* \remark Throws a std::runtime_error if pointer does not point to an element of the pool with NAZARA_CORE_SAFE defined
|
||||
* \remark If ptr is null, nothing is done
|
||||
*/
|
||||
|
||||
inline void MemoryPool::Free(void* ptr)
|
||||
{
|
||||
///DOC: Si appelé avec un pointeur ne faisant pas partie du pool, l'opérateur delete est utilisé
|
||||
if (ptr)
|
||||
{
|
||||
// Le pointeur nous appartient-il ?
|
||||
// Does the pointer belong to us ?
|
||||
UInt8* freePtr = static_cast<UInt8*>(ptr);
|
||||
UInt8* poolPtr = m_pool.get();
|
||||
if (freePtr >= poolPtr && freePtr < poolPtr + m_blockSize*m_size)
|
||||
@@ -81,7 +129,7 @@ namespace Nz
|
||||
|
||||
m_freeList[m_freeCount++] = ptr;
|
||||
|
||||
// Si nous sommes vide et l'extension d'un autre pool, nous nous suicidons
|
||||
// If we are empty and the extension of another pool, we commit suicide
|
||||
if (m_freeCount == m_size && m_previous && !m_next)
|
||||
{
|
||||
m_previous->m_next.release();
|
||||
@@ -98,31 +146,61 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the block size
|
||||
* \return Size of the blocks
|
||||
*/
|
||||
|
||||
inline unsigned int MemoryPool::GetBlockSize() const
|
||||
{
|
||||
return m_blockSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the number of free blocks
|
||||
* \return Number of free blocks in the pool
|
||||
*/
|
||||
|
||||
inline unsigned int MemoryPool::GetFreeBlocks() const
|
||||
{
|
||||
return m_freeCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the pool size
|
||||
* \return Size of the pool
|
||||
*/
|
||||
|
||||
inline unsigned int MemoryPool::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a new value of type T with arguments
|
||||
* \return Pointer to the allocated object
|
||||
*
|
||||
* \param args Arguments for the new object
|
||||
*
|
||||
* \remark Constructs inplace in the pool
|
||||
*/
|
||||
|
||||
template<typename T, typename... Args>
|
||||
inline T* MemoryPool::New(Args&&... args)
|
||||
{
|
||||
///DOC: Permet de construire un objet directement dans le pook
|
||||
T* object = static_cast<T*>(Allocate(sizeof(T)));
|
||||
PlacementNew<T>(object, std::forward<Args>(args)...);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns the content of another pool by move semantic
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param pool Other pool to move into this
|
||||
*/
|
||||
|
||||
inline MemoryPool& MemoryPool::operator=(MemoryPool&& pool) noexcept
|
||||
{
|
||||
m_blockSize = pool.m_blockSize;
|
||||
@@ -134,7 +212,7 @@ namespace Nz
|
||||
m_next = std::move(pool.m_next);
|
||||
m_size = pool.m_size;
|
||||
|
||||
// Si nous avons été créés par un autre pool, nous devons le faire pointer vers nous de nouveau
|
||||
// If we have been created by another pool, we must make it point to us again
|
||||
if (m_previous)
|
||||
{
|
||||
m_previous->m_next.release();
|
||||
|
||||
@@ -7,18 +7,36 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a MemoryStream object by default
|
||||
*/
|
||||
|
||||
inline MemoryStream::MemoryStream() :
|
||||
Stream(StreamOption_None, OpenMode_ReadWrite),
|
||||
m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a MemoryStream object with a byte array
|
||||
*
|
||||
* \param byteArray Bytes to stream
|
||||
* \param openMode Reading/writing mode for the stream
|
||||
*/
|
||||
|
||||
inline MemoryStream::MemoryStream(ByteArray* byteArray, UInt32 openMode) :
|
||||
MemoryStream()
|
||||
{
|
||||
SetBuffer(byteArray, openMode);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal buffer
|
||||
* \return Buffer of bytes
|
||||
*
|
||||
* \remark Produces a NazaraAssert if buffer is invalid
|
||||
*/
|
||||
|
||||
inline ByteArray& MemoryStream::GetBuffer()
|
||||
{
|
||||
NazaraAssert(m_buffer, "Invalid buffer");
|
||||
@@ -26,6 +44,13 @@ namespace Nz
|
||||
return *m_buffer;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the internal buffer
|
||||
* \return Buffer of bytes
|
||||
*
|
||||
* \remark Produces a NazaraAssert if buffer is invalid
|
||||
*/
|
||||
|
||||
inline const ByteArray& MemoryStream::GetBuffer() const
|
||||
{
|
||||
NazaraAssert(m_buffer, "Invalid buffer");
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ObjectRef
|
||||
* \brief Core class that represents a reference to an object
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Gets the ObjectRef object by name
|
||||
* \return Optional reference
|
||||
*
|
||||
* \param name Name of the object
|
||||
*
|
||||
* \remark Produces a NazaraError if object not found
|
||||
*/
|
||||
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Get(const String& name)
|
||||
{
|
||||
@@ -17,18 +31,37 @@ namespace Nz
|
||||
return ref;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the library has the object with that name
|
||||
* \return true if it the case
|
||||
*/
|
||||
|
||||
template<typename Type>
|
||||
bool ObjectLibrary<Type>::Has(const String& name)
|
||||
{
|
||||
return Type::s_library.find(name) != Type::s_library.end();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the ObjectRef object with that name
|
||||
*
|
||||
* \param name Name of the object
|
||||
* \param object Object to stock
|
||||
*/
|
||||
|
||||
template<typename Type>
|
||||
void ObjectLibrary<Type>::Register(const String& name, ObjectRef<Type> object)
|
||||
{
|
||||
Type::s_library.emplace(name, object);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ObjectRef object by name
|
||||
* \return Optional reference
|
||||
*
|
||||
* \param name Name of the object
|
||||
*/
|
||||
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Query(const String& name)
|
||||
{
|
||||
@@ -39,6 +72,12 @@ namespace Nz
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unregisters the ObjectRef object with that name
|
||||
*
|
||||
* \param name Name of the object
|
||||
*/
|
||||
|
||||
template<typename Type>
|
||||
void ObjectLibrary<Type>::Unregister(const String& name)
|
||||
{
|
||||
|
||||
@@ -7,12 +7,27 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ObjectRef
|
||||
* \brief Core class that represents a reference to an object
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ObjectRef object by default
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::ObjectRef() :
|
||||
m_object(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ObjectRef object with a pointer to an object
|
||||
*
|
||||
* \param object Pointer to handle like a reference (can be nullptr)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::ObjectRef(T* object) :
|
||||
m_object(object)
|
||||
@@ -21,6 +36,12 @@ namespace Nz
|
||||
m_object->AddReference();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ObjectRef object by assignation
|
||||
*
|
||||
* \param ref ObjectRef to assign into this
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::ObjectRef(const ObjectRef& ref) :
|
||||
m_object(ref.m_object)
|
||||
@@ -29,6 +50,12 @@ namespace Nz
|
||||
m_object->AddReference();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ObjectRef<U> object from another type of ObjectRef
|
||||
*
|
||||
* \param ref ObjectRef of type U to convert to type T
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
ObjectRef<T>::ObjectRef(const ObjectRef<U>& ref) :
|
||||
@@ -36,13 +63,23 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a ObjectRef object by move semantic
|
||||
*
|
||||
* \param ref ObjectRef to move into this
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::ObjectRef(ObjectRef&& ref) noexcept :
|
||||
m_object(ref.m_object)
|
||||
{
|
||||
ref.m_object = nullptr; // On vole la référence
|
||||
ref.m_object = nullptr; // We steal the reference
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object (remove a reference to the object when shared)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::~ObjectRef()
|
||||
{
|
||||
@@ -50,27 +87,50 @@ namespace Nz
|
||||
m_object->RemoveReference();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the underlying pointer
|
||||
* \return Underlying pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T* ObjectRef<T>::Get() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the reference is valid
|
||||
* \return true if reference is not nullptr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool ObjectRef<T>::IsValid() const
|
||||
{
|
||||
return m_object != nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Releases the handle of the pointer
|
||||
* \return Underlying pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T* ObjectRef<T>::Release()
|
||||
{
|
||||
if (m_object)
|
||||
m_object->RemoveReference();
|
||||
|
||||
T* object = m_object;
|
||||
m_object = nullptr;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the content of the ObjectRef with another pointer
|
||||
* \return true if old handle is destroyed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool ObjectRef<T>::Reset(T* object)
|
||||
{
|
||||
@@ -88,6 +148,13 @@ namespace Nz
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Swaps the content of the two ObjectRef
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param ref ObjectRef to swap
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>& ObjectRef<T>::Swap(ObjectRef& ref)
|
||||
{
|
||||
@@ -96,24 +163,48 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the ObjectRef to bool
|
||||
* \return true if reference is not nullptr
|
||||
*
|
||||
* \see IsValid
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::operator bool() const
|
||||
{
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dereferences the ObjectRef
|
||||
* \return Underlying pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>::operator T*() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dereferences the ObjectRef
|
||||
* \return Underlying pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T* ObjectRef<T>::operator->() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns the object into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param object Pointer to handle like a reference (can be nullptr)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>& ObjectRef<T>::operator=(T* object)
|
||||
{
|
||||
@@ -122,6 +213,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the reference of the ObjectRef with the handle from another
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param ref The other ObjectRef
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>& ObjectRef<T>::operator=(const ObjectRef& ref)
|
||||
{
|
||||
@@ -130,6 +228,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the reference of the ObjectRef from another type of ObjectRef
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param ref ObjectRef of type U to convert
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
ObjectRef<T>& ObjectRef<T>::operator=(const ObjectRef<U>& ref)
|
||||
@@ -141,6 +246,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the ObjectRef into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param ref ObjectRef to move in this
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ObjectRef<T>& ObjectRef<T>::operator=(ObjectRef&& ref) noexcept
|
||||
{
|
||||
@@ -154,6 +266,13 @@ namespace Nz
|
||||
|
||||
namespace std
|
||||
{
|
||||
/*!
|
||||
* \brief Gives a hash representation of the object, specialisation of std
|
||||
* \return Hash of the ObjectRef
|
||||
*
|
||||
* \param object Object to hash
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
struct hash<Nz::ObjectRef<T>>
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef NAZARA_OFFSETOF_HPP
|
||||
#define NAZARA_OFFSETOF_HPP
|
||||
|
||||
// Par "Jesse Good" de SO:
|
||||
// By "Jesse Good" from SO:
|
||||
// http://stackoverflow.com/questions/12811330/c-compile-time-offsetof-inside-a-template?answertab=votes#tab-top
|
||||
|
||||
namespace Nz
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
///TODO: Révision
|
||||
///TODO: Revision
|
||||
namespace Nz
|
||||
{
|
||||
class DynLib;
|
||||
|
||||
@@ -6,6 +6,20 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::PrimitiveList
|
||||
* \brief Core class that represents a geometric primitive
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Makes a box centered
|
||||
*
|
||||
* \param lengths (Width, Height, Depht)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -15,11 +29,31 @@ namespace Nz
|
||||
box.subdivision = subdivision;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a box centered
|
||||
*
|
||||
* \param lengths (Width, Height, Depht)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param position Position of the box
|
||||
* \param rotation Rotation of the box
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeBox(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakeBox(lengths, subdivision, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a cone, centered in (0, 0, 0) and circle in (0, -length, 0)
|
||||
*
|
||||
* \param length Height of the cone
|
||||
* \param radius Width of the radius
|
||||
* \param subdivision Number of sides for the circle
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeCone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -30,11 +64,31 @@ namespace Nz
|
||||
cone.subdivision = subdivision;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a cone, centered in (0, 0, 0) and circle in (0, -length, 0)
|
||||
*
|
||||
* \param length Height of the cone
|
||||
* \param radius Width of the radius
|
||||
* \param subdivision Number of sides for the circle
|
||||
* \param position Position of the cone
|
||||
* \param rotation Rotation of the cone
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeCone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakeCone(length, radius, subdivision, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a cubic sphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the cubic sphere
|
||||
* \param subdivision Number of subdivision for the box
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeCubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -45,11 +99,30 @@ namespace Nz
|
||||
sphere.cubic.subdivision = subdivision;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a cubic sphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the cubic sphere
|
||||
* \param subdivision Number of subdivision for the box
|
||||
* \param position Position of the cubic sphere
|
||||
* \param rotation Rotation of the cubic sphere
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakeCubicSphere(size, subdivision, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a icosphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the icosphere
|
||||
* \param recursionLevel Number of recursion for the icosphere
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -60,11 +133,30 @@ namespace Nz
|
||||
sphere.ico.recursionLevel = recursionLevel;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a icosphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param recursionLevel Number of recursion for the icosphere
|
||||
* \param position Position of the icosphere
|
||||
* \param rotation Rotation of the icosphere
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakeIcoSphere(size, recursionLevel, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a plane, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -74,16 +166,45 @@ namespace Nz
|
||||
plane.subdivision = subdivision;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a plane, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param planeInfo Information for the plane
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo, const Rectf& uvCoords)
|
||||
{
|
||||
MakePlane(size, subdivision, Matrix4f::Transform(planeInfo.distance * planeInfo.normal, Quaternionf::RotationBetween(Vector3f::Up(), planeInfo.normal)), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a plane, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param position Position of the plane
|
||||
* \param rotation Rotation of the plane
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakePlane(size, subdivision, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a UV sphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param sliceCount Number of slices
|
||||
* \param stackCount Number of stacks
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
@@ -95,11 +216,32 @@ namespace Nz
|
||||
sphere.uv.stackCount = stackCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes a UV sphere, centered in (0, 0, 0)
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param sliceCount Number of slices
|
||||
* \param stackCount Number of stacks
|
||||
* \param position Position of the box
|
||||
* \param rotation Rotation of the box
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline void Primitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
MakeUVSphere(size, sliceCount, stackCount, Matrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a box centered
|
||||
* \return Primitive which is a box
|
||||
*
|
||||
* \param lengths (Width, Height, Depht)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Box(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -108,6 +250,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a box centered
|
||||
* \return Primitive which is a box
|
||||
*
|
||||
* \param lengths (Width, Height, Depht)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param position Position of the box
|
||||
* \param rotation Rotation of the box
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Box(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -116,6 +269,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a cone, centered in (0, 0, 0) and circle in (0, -length, 0)
|
||||
* \return Primitive which is a cone
|
||||
*
|
||||
* \param length Height of the cone
|
||||
* \param radius Width of the radius
|
||||
* \param subdivision Number of sides for the circle
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Cone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -124,6 +288,18 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a cone, centered in (0, 0, 0) and circle in (0, -length, 0)
|
||||
* \return Primitive which is a cone
|
||||
*
|
||||
* \param length Height of the cone
|
||||
* \param radius Width of the radius
|
||||
* \param subdivision Number of sides for the circle
|
||||
* \param position Position of the cone
|
||||
* \param rotation Rotation of the cone
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Cone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -132,6 +308,16 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a cubic sphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a cubic sphere
|
||||
*
|
||||
* \param size Radius of the cubic sphere
|
||||
* \param subdivision Number of subdivision for the box
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::CubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -140,6 +326,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a cubic sphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a cubic sphere
|
||||
*
|
||||
* \param size Radius of the cubic sphere
|
||||
* \param subdivision Number of subdivision for the box
|
||||
* \param position Position of the cubic sphere
|
||||
* \param rotation Rotation of the cubic sphere
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::CubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -148,6 +345,16 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a icosphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a icosphere
|
||||
*
|
||||
* \param size Radius of the icosphere
|
||||
* \param recursionLevel Number of recursion for the icosphere
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::IcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -156,6 +363,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a icosphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a icosphere
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param recursionLevel Number of recursion for the icosphere
|
||||
* \param position Position of the icosphere
|
||||
* \param rotation Rotation of the icosphere
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::IcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -164,6 +382,16 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a plane, centered in (0, 0, 0)
|
||||
* \return Primitive which is a plane
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -172,6 +400,16 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a plane, centered in (0, 0, 0)
|
||||
* \return Primitive which is a plane
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param planeInfo Information for the plane
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Planef& plane, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -180,6 +418,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a plane, centered in (0, 0, 0)
|
||||
* \return Primitive which is a plane
|
||||
*
|
||||
* \param size (Width, Depth)
|
||||
* \param subdivision Number of subdivision for the axis
|
||||
* \param position Position of the plane
|
||||
* \param rotation Rotation of the plane
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -188,6 +437,17 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a UV sphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a uv sphere
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param sliceCount Number of slices
|
||||
* \param stackCount Number of stacks
|
||||
* \param transformMatrix Matrix to apply
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
@@ -196,6 +456,18 @@ namespace Nz
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Creates a UV sphere, centered in (0, 0, 0)
|
||||
* \return Primitive which is a uv sphere
|
||||
*
|
||||
* \param size Radius of the sphere
|
||||
* \param sliceCount Number of slices
|
||||
* \param stackCount Number of stacks
|
||||
* \param position Position of the box
|
||||
* \param rotation Rotation of the box
|
||||
* \param uvCoords Coordinates for texture
|
||||
*/
|
||||
|
||||
inline Primitive Primitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords)
|
||||
{
|
||||
Primitive primitive;
|
||||
|
||||
@@ -11,6 +11,18 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ResourceLoader<Type, Parameters>
|
||||
* \brief Core class that represents a loader of resources
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the extension of the file is supported
|
||||
* \return true if supported
|
||||
*
|
||||
* \param extension Extension of the file
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const String& extension)
|
||||
{
|
||||
@@ -25,10 +37,32 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads a resource from a filepath and parameters
|
||||
* \return true if successfully loaded
|
||||
*
|
||||
* \param resource Resource to load
|
||||
* \param filePath Path to the resource
|
||||
* \param parameters Parameters for the load
|
||||
*
|
||||
* \remark Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if filePath has no extension
|
||||
* \remark Produces a NazaraError if file count not be opened
|
||||
* \remark Produces a NazaraWarning if loader failed
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const String& filePath, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!resource)
|
||||
{
|
||||
NazaraError("Pointer invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid parameters");
|
||||
@@ -122,13 +156,29 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads a resource from a raw memory, a size and parameters
|
||||
* \return true if successfully loaded
|
||||
*
|
||||
* \param resource Resource to load
|
||||
* \param data Raw memory of the resource
|
||||
* \param size Size available for the read
|
||||
* \param parameters Parameters for the load
|
||||
*
|
||||
* \remark Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if size is 0 with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraWarning if loader failed
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!parameters.IsValid())
|
||||
if (!resource)
|
||||
{
|
||||
NazaraError("Invalid parameters");
|
||||
NazaraError("Pointer invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,6 +187,12 @@ namespace Nz
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid parameters");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
MemoryView stream(data, size);
|
||||
@@ -198,13 +254,28 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads a resource from a stream and parameters
|
||||
* \return true if successfully loaded
|
||||
*
|
||||
* \param resource Resource to load
|
||||
* \param stream Stream of the resource
|
||||
* \param parameters Parameters for the load
|
||||
*
|
||||
* \remark Produces a NazaraError if resource is nullptr with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if stream has no data with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraError if parameters are invalid with NAZARA_CORE_SAFE defined
|
||||
* \remark Produces a NazaraWarning if loader failed
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (!parameters.IsValid())
|
||||
if (!resource)
|
||||
{
|
||||
NazaraError("Invalid parameters");
|
||||
NazaraError("Pointer invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -213,6 +284,12 @@ namespace Nz
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid parameters");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
UInt64 streamPos = stream.GetCursorPos();
|
||||
@@ -224,17 +301,17 @@ namespace Nz
|
||||
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Le loader supporte-t-il les données ?
|
||||
// Does the loader support these data ?
|
||||
Ternary recognized = checkFunc(stream, parameters);
|
||||
if (recognized == Ternary_False)
|
||||
continue;
|
||||
else if (recognized == Ternary_True)
|
||||
found = true;
|
||||
|
||||
// On repositionne le stream à son ancienne position
|
||||
// We move the stream to its old position
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Chargement de la ressource
|
||||
// Load of the resource
|
||||
if (streamLoader(resource, stream, parameters))
|
||||
return true;
|
||||
|
||||
@@ -250,6 +327,16 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the loader
|
||||
*
|
||||
* \param extensionGetter A function to test whether the extension (as a string) is supported by this loader
|
||||
* \param checkFunc A function to check the stream with the parser
|
||||
* \param streamLoader A function to load the data from a stream in the resource
|
||||
* \param fileLoader Optional function to load the data from a file in the resource
|
||||
* \param memoryLoader Optional function to load the data from a raw memory in the resource
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceLoader<Type, Parameters>::RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader, MemoryLoader memoryLoader)
|
||||
{
|
||||
@@ -272,6 +359,16 @@ namespace Nz
|
||||
Type::s_loaders.push_front(std::make_tuple(extensionGetter, checkFunc, streamLoader, fileLoader, memoryLoader));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unregisters the loader
|
||||
*
|
||||
* \param extensionGetter A function to test whether the extension (as a string) is supported by this loader
|
||||
* \param checkFunc A function to check the stream with the parser
|
||||
* \param streamLoader A function to load the data from a stream in the resource
|
||||
* \param fileLoader Optional function to load the data from a file in the resource
|
||||
* \param memoryLoader Optional function to load the data from a raw memory in the resource
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceLoader<Type, Parameters>::UnregisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader, MemoryLoader memoryLoader)
|
||||
{
|
||||
|
||||
@@ -9,12 +9,28 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::ResourceManager<Type, Parameters>
|
||||
* \brief Core class that represents a resource manager
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Clears the content of the manager
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Clear()
|
||||
{
|
||||
Type::s_managerMap.clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets a reference to the object loaded from file
|
||||
* \return Reference to the object
|
||||
*
|
||||
* \param filePath Path to the asset that will be loaded
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
ObjectRef<Type> ResourceManager<Type, Parameters>::Get(const String& filePath)
|
||||
{
|
||||
@@ -43,12 +59,21 @@ namespace Nz
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the defaults parameters for the load
|
||||
* \return Default parameters for loading from file
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
const Parameters& ResourceManager<Type, Parameters>::GetDefaultParameters()
|
||||
{
|
||||
return Type::s_managerParameters;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Purges the resource manager from every asset whose it is the only owner
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Purge()
|
||||
{
|
||||
@@ -56,16 +81,23 @@ namespace Nz
|
||||
while (it != Type::s_managerMap.end())
|
||||
{
|
||||
const ObjectRef<Type>& ref = it->second;
|
||||
if (ref.GetReferenceCount() == 1) // Sommes-nous les seuls à détenir la ressource ?
|
||||
if (ref.GetReferenceCount() == 1) // Are we the only ones to own the resource ?
|
||||
{
|
||||
NazaraDebug("Purging resource from file " + ref->GetFilePath());
|
||||
Type::s_managerMap.erase(it++); // Alors on la supprime
|
||||
Type::s_managerMap.erase(it++); // Then we erase it
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Registers the resource under the filePath
|
||||
*
|
||||
* \param filePath Path for the resource
|
||||
* \param resource Object to associate with
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Register(const String& filePath, ObjectRef<Type> resource)
|
||||
{
|
||||
@@ -74,12 +106,24 @@ namespace Nz
|
||||
Type::s_managerMap[absolutePath] = resource;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the defaults parameters for the load
|
||||
*
|
||||
* \param params Default parameters for loading from file
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::SetDefaultParameters(const Parameters& params)
|
||||
{
|
||||
Type::s_managerParameters = params;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unregisters the resource under the filePath
|
||||
*
|
||||
* \param filePath Path for the resource
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Unregister(const String& filePath)
|
||||
{
|
||||
@@ -88,12 +132,21 @@ namespace Nz
|
||||
Type::s_managerMap.erase(absolutePath);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Initializes the resource manager
|
||||
* \return true
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceManager<Type, Parameters>::Initialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uninitialize the resource manager
|
||||
*/
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void ResourceManager<Type, Parameters>::Uninitialize()
|
||||
{
|
||||
|
||||
@@ -8,18 +8,37 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::Signal<Args...>
|
||||
* \brief Core class that represents a signal, a list of objects waiting for its message
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal<Args...> object by default
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::Signal() :
|
||||
m_slotIterator(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal<Args...> object by move semantic
|
||||
*
|
||||
* \param signal Signal to move in this
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::Signal(Signal&& signal)
|
||||
{
|
||||
operator=(std::move(signal));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Clears the list of actions attached to the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::Clear()
|
||||
{
|
||||
@@ -27,12 +46,26 @@ namespace Nz
|
||||
m_slotIterator = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a function to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param func Non-member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(const Callback& func)
|
||||
{
|
||||
return Connect(Callback(func));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a function to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param func Non-member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(Callback&& func)
|
||||
{
|
||||
@@ -54,6 +87,14 @@ namespace Nz
|
||||
return Connection(m_slots.back());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a member function and its object to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param object Object to send the message
|
||||
* \param method Member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename O>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(O& object, void (O::*method) (Args...))
|
||||
@@ -64,6 +105,14 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a member function and its object to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param object Object to send the message
|
||||
* \param method Member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename O>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(O* object, void (O::*method)(Args...))
|
||||
@@ -74,6 +123,14 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a member function and its object to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param object Object to send the message
|
||||
* \param method Member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename O>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(const O& object, void (O::*method) (Args...) const)
|
||||
@@ -84,6 +141,14 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects a member function and its object to the signal
|
||||
* \return Connection attached to the signal
|
||||
*
|
||||
* \param object Object to send the message
|
||||
* \param method Member function
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename O>
|
||||
typename Signal<Args...>::Connection Signal<Args...>::Connect(const O* object, void (O::*method)(Args...) const)
|
||||
@@ -94,6 +159,12 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Applies the list of arguments to every callback functions
|
||||
*
|
||||
* \param args Arguments to send with the message
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::operator()(Args... args) const
|
||||
{
|
||||
@@ -101,6 +172,13 @@ namespace Nz
|
||||
m_slots[m_slotIterator]->callback(args...);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the signal into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param signal Signal to move in this
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>& Signal<Args...>::operator=(Signal&& signal)
|
||||
{
|
||||
@@ -114,17 +192,28 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disconnects a listener from this signal
|
||||
*
|
||||
* \param slot Pointer to the ith listener of the signal
|
||||
*
|
||||
* \remark Produces a NazaraAssert if slot is invalid (nullptr)
|
||||
* \remark Produces a NazaraAssert if index of slot is invalid
|
||||
* \remark Produces a NazaraAssert if slot is not attached to this signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::Disconnect(const SlotPtr& slot)
|
||||
{
|
||||
NazaraAssert(slot, "Invalid slot pointer");
|
||||
NazaraAssert(slot->index < m_slots.size(), "Invalid slot index");
|
||||
NazaraAssert(slot->signal == this, "Slot is not attached to this signal");
|
||||
|
||||
// "Swap this slot with the last one and pop" idiom
|
||||
// This will preserve slot indexes
|
||||
|
||||
// Can we safely "remove" this slot?
|
||||
if (m_slotIterator >= m_slots.size()-1 || slot->index > m_slotIterator)
|
||||
if (m_slotIterator >= (m_slots.size() - 1) || slot->index > m_slotIterator)
|
||||
{
|
||||
// Yes we can
|
||||
SlotPtr& newSlot = m_slots[slot->index];
|
||||
@@ -150,6 +239,16 @@ namespace Nz
|
||||
m_slots.pop_back();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Nz::Signal<Args...>::Connection
|
||||
* \brief Core class that represents a connection attached to a signal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal<Args...>::Connection object with a slot
|
||||
*
|
||||
* \param slot Slot of the listener
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::Connection::Connection(const SlotPtr& slot) :
|
||||
@@ -157,6 +256,13 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects to a signal with arguments
|
||||
*
|
||||
* \param signal New signal to listen
|
||||
* \param args Arguments for the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename... ConnectArgs>
|
||||
void Signal<Args...>::Connection::Connect(BaseClass& signal, ConnectArgs&&... args)
|
||||
@@ -164,6 +270,10 @@ namespace Nz
|
||||
operator=(signal.Connect(std::forward<ConnectArgs>(args)...));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disconnects the connection from the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::Connection::Disconnect()
|
||||
{
|
||||
@@ -171,12 +281,27 @@ namespace Nz
|
||||
ptr->signal->Disconnect(ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the connection is still active with the signal
|
||||
* \return true if signal is still active
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
bool Signal<Args...>::Connection::IsConnected() const
|
||||
{
|
||||
return !m_ptr.expired();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Nz::Signal<Args...>::ConnectionGuard
|
||||
* \brief Core class that represents a RAII for a connection attached to a signal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal<Args...>::ConnectionGuard object with a connection
|
||||
*
|
||||
* \param connection Connection for the scope
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::ConnectionGuard::ConnectionGuard(const Connection& connection) :
|
||||
@@ -184,18 +309,35 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal<Args...>::ConnectionGuard object with a connection by move semantic
|
||||
*
|
||||
* \param connection Connection for the scope
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::ConnectionGuard::ConnectionGuard(Connection&& connection) :
|
||||
m_connection(std::move(connection))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and disconnects the connection
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
Signal<Args...>::ConnectionGuard::~ConnectionGuard()
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Connects to a signal with arguments
|
||||
*
|
||||
* \param signal New signal to listen
|
||||
* \param args Arguments for the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
template<typename... ConnectArgs>
|
||||
void Signal<Args...>::ConnectionGuard::Connect(BaseClass& signal, ConnectArgs&&... args)
|
||||
@@ -204,24 +346,45 @@ namespace Nz
|
||||
m_connection.Connect(signal, std::forward<ConnectArgs>(args)...);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Disconnects the connection from the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::ConnectionGuard::Disconnect()
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the connection attached to the signal
|
||||
* \return Connection of the signal
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::Connection& Signal<Args...>::ConnectionGuard::GetConnection()
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the connection is still active with the signal
|
||||
* \return true if signal is still active
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
bool Signal<Args...>::ConnectionGuard::IsConnected() const
|
||||
{
|
||||
return m_connection.IsConnected();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns the connection into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param connection Connection to assign into this
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(const Connection& connection)
|
||||
{
|
||||
@@ -231,6 +394,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the Connection into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param connection Connection to move in this
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(Connection&& connection)
|
||||
{
|
||||
@@ -240,6 +410,13 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the ConnectionGuard into this
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param connection ConnectionGuard to move in this
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(ConnectionGuard&& connection)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef NAZARA_SPARSEPTR_HPP
|
||||
#define NAZARA_SPARSEPTR_HPP
|
||||
|
||||
///FIXME: Est-ce que SparsePtr est vraiment le meilleur nom pour cette classe ?
|
||||
///FIXME: Is SparsePtr a really good name for this class ?
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
@@ -7,24 +7,52 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::SparsePtr<T>
|
||||
* \brief Core class that represents a pointer and the step between two elements
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SparsePtr<T> object by default
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>::SparsePtr()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SparsePtr<T> object with a pointer
|
||||
*
|
||||
* \param ptr Pointer to data
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>::SparsePtr(T* ptr)
|
||||
{
|
||||
Reset(ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SparsePtr<T> object with a pointer and a step
|
||||
*
|
||||
* \param ptr Pointer to data
|
||||
* \param stride Step between two elements
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>::SparsePtr(VoidPtr ptr, int stride)
|
||||
{
|
||||
Reset(ptr, stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SparsePtr<T> object from another type of SparsePtr
|
||||
*
|
||||
* \param ptr Pointer to data of type U to convert to type T
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
SparsePtr<T>::SparsePtr(const SparsePtr<U>& ptr)
|
||||
@@ -32,18 +60,32 @@ namespace Nz
|
||||
Reset(ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the original pointer
|
||||
* \return Pointer to the first data
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
typename SparsePtr<T>::VoidPtr SparsePtr<T>::GetPtr() const
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the stride
|
||||
* \return Step between two elements
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
int SparsePtr<T>::GetStride() const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the SparsePtr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::Reset()
|
||||
{
|
||||
@@ -51,6 +93,14 @@ namespace Nz
|
||||
SetStride(0);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the SparsePtr with a pointer
|
||||
*
|
||||
* \param ptr Pointer to data
|
||||
*
|
||||
* \remark stride is set to sizeof(T)
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::Reset(T* ptr)
|
||||
{
|
||||
@@ -58,6 +108,13 @@ namespace Nz
|
||||
SetStride(sizeof(T));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the SparsePtr with a pointer and its stride
|
||||
*
|
||||
* \param ptr Pointer to data
|
||||
* \param stride Step between two elements
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::Reset(VoidPtr ptr, int stride)
|
||||
{
|
||||
@@ -65,6 +122,12 @@ namespace Nz
|
||||
SetStride(stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the SparsePtr with another SparsePtr
|
||||
*
|
||||
* \param ptr Another sparsePtr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::Reset(const SparsePtr& ptr)
|
||||
{
|
||||
@@ -72,6 +135,12 @@ namespace Nz
|
||||
SetStride(ptr.GetStride());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the SparsePtr with another type of SparsePtr
|
||||
*
|
||||
* \param ptr Another sparsePtr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void SparsePtr<T>::Reset(const SparsePtr<U>& ptr)
|
||||
@@ -82,94 +151,187 @@ namespace Nz
|
||||
SetStride(ptr.GetStride());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the pointer
|
||||
*
|
||||
* \param ptr Pointer to data
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::SetPtr(VoidPtr ptr)
|
||||
{
|
||||
m_ptr = reinterpret_cast<BytePtr>(ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the stride
|
||||
*
|
||||
* \param stride Step between two elements
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void SparsePtr<T>::SetStride(int stride)
|
||||
{
|
||||
m_stride = stride;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the pointer to bool
|
||||
* \return true if pointer is not nullptr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>::operator bool() const
|
||||
{
|
||||
return m_ptr != nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the pointer to a pointer to the value
|
||||
* \return The value of the pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>::operator T*() const
|
||||
{
|
||||
return reinterpret_cast<T*>(m_ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dereferences the pointer
|
||||
* \return The dereferencing of the pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T& SparsePtr<T>::operator*() const
|
||||
{
|
||||
return *reinterpret_cast<T*>(m_ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Dereferences the pointer
|
||||
* \return The dereferencing of the pointer
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T* SparsePtr<T>::operator->() const
|
||||
{
|
||||
return reinterpret_cast<T*>(m_ptr);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith element of the stride pointer
|
||||
* \return A reference to the ith value
|
||||
*
|
||||
* \param index Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
T& SparsePtr<T>::operator[](int index) const
|
||||
{
|
||||
return *reinterpret_cast<T*>(m_ptr + index*m_stride);
|
||||
return *reinterpret_cast<T*>(m_ptr + index * m_stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A SparsePtr with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator+(int count) const
|
||||
{
|
||||
return SparsePtr(m_ptr + count*m_stride, m_stride);
|
||||
return SparsePtr(m_ptr + count * m_stride, m_stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A SparsePtr with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator+(unsigned int count) const
|
||||
{
|
||||
return SparsePtr(m_ptr + count*m_stride, m_stride);
|
||||
return SparsePtr(m_ptr + count * m_stride, m_stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A SparsePtr with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator-(int count) const
|
||||
{
|
||||
return SparsePtr(m_ptr - count*m_stride, m_stride);
|
||||
return SparsePtr(m_ptr - count * m_stride, m_stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A SparsePtr with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator-(unsigned int count) const
|
||||
{
|
||||
return SparsePtr(m_ptr - count*m_stride, m_stride);
|
||||
return SparsePtr(m_ptr - count * m_stride, m_stride);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the difference between the two SparsePtr
|
||||
* \return The difference of elements: ptr - this->ptr
|
||||
*
|
||||
* \param ptr Other ptr
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
std::ptrdiff_t SparsePtr<T>::operator-(const SparsePtr& ptr) const
|
||||
{
|
||||
return (m_ptr - ptr.m_ptr)/m_stride;
|
||||
return (m_ptr - ptr.m_ptr) / m_stride;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A reference to this pointer with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>& SparsePtr<T>::operator+=(int count)
|
||||
{
|
||||
m_ptr += count*m_stride;
|
||||
m_ptr += count * m_stride;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with an offset
|
||||
* \return A reference to this pointer with the new stride
|
||||
*
|
||||
* \param count Number of stride to do
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>& SparsePtr<T>::operator-=(int count)
|
||||
{
|
||||
m_ptr -= count*m_stride;
|
||||
m_ptr -= count * m_stride;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with the next element
|
||||
* \return A reference to this pointer updated
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>& SparsePtr<T>::operator++()
|
||||
{
|
||||
@@ -178,19 +340,29 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with the next element
|
||||
* \return A SparsePtr not updated
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator++(int)
|
||||
{
|
||||
// On fait une copie de l'objet
|
||||
// We copy the object
|
||||
SparsePtr tmp(*this);
|
||||
|
||||
// On modifie l'objet
|
||||
// We modify it
|
||||
operator++();
|
||||
|
||||
// On retourne la copie
|
||||
// We return the copy
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with the previous element
|
||||
* \return A reference to this pointer updated
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T>& SparsePtr<T>::operator--()
|
||||
{
|
||||
@@ -198,49 +370,96 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the SparsePtr with the previous element
|
||||
* \return A SparsePtr not updated
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
SparsePtr<T> SparsePtr<T>::operator--(int)
|
||||
{
|
||||
// On fait une copie de l'objet
|
||||
// We copy the object
|
||||
SparsePtr tmp(*this);
|
||||
|
||||
// On modifie l'objet
|
||||
// We modify it
|
||||
operator--();
|
||||
|
||||
// On retourne la copie
|
||||
// We return the copy
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return true if the two SparsePtr are pointing to the same memory
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator==(const SparsePtr& ptr) const
|
||||
{
|
||||
return m_ptr == ptr.m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return false if the two SparsePtr are pointing to the same memory
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator!=(const SparsePtr& ptr) const
|
||||
{
|
||||
return m_ptr != ptr.m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return true if the first SparsePtr is pointing to memory inferior to the second one
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator<(const SparsePtr& ptr) const
|
||||
{
|
||||
return m_ptr < ptr.m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return true if the first SparsePtr is pointing to memory superior to the second one
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator>(const SparsePtr& ptr) const
|
||||
{
|
||||
return m_ptr > ptr.m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return true if the first SparsePtr is pointing to memory inferior or equal to the second one
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator<=(const SparsePtr& ptr) const
|
||||
{
|
||||
return m_ptr <= ptr.m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Compares the SparsePtr to another one
|
||||
* \return true if the first SparsePtr is pointing to memory superior or equal to the second one
|
||||
*
|
||||
* \param ptr Other SparsePtr to compare with
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool SparsePtr<T>::operator>=(const SparsePtr& ptr) const
|
||||
{
|
||||
|
||||
@@ -7,12 +7,25 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a Stream object with options
|
||||
*
|
||||
* \param streamOptions Options for the stream
|
||||
* \param openMode Reading/writing mode for the stream
|
||||
*/
|
||||
|
||||
inline Stream::Stream(UInt32 streamOptions, UInt32 openMode) :
|
||||
m_openMode(openMode),
|
||||
m_streamOptions(streamOptions)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Enables the text mode
|
||||
*
|
||||
* \param textMode Enables the mode or disables
|
||||
*/
|
||||
|
||||
inline void Stream::EnableTextMode(bool textMode)
|
||||
{
|
||||
if (textMode)
|
||||
@@ -21,6 +34,12 @@ namespace Nz
|
||||
m_streamOptions &= ~StreamOption_Text;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Flushes the stream
|
||||
*
|
||||
* \remark Produces a NazaraAssert if file is not writable
|
||||
*/
|
||||
|
||||
inline void Stream::Flush()
|
||||
{
|
||||
NazaraAssert(IsWritable(), "Stream is not writable");
|
||||
@@ -28,36 +47,77 @@ namespace Nz
|
||||
FlushStream();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the open mode of the stream
|
||||
* \return Reading/writing mode for the stream
|
||||
*/
|
||||
|
||||
inline UInt32 Stream::GetOpenMode() const
|
||||
{
|
||||
return m_openMode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the options of the stream
|
||||
* \return Options of the stream
|
||||
*/
|
||||
|
||||
inline UInt32 Stream::GetStreamOptions() const
|
||||
{
|
||||
return m_streamOptions;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the stream is readable
|
||||
* \return true if it is the case
|
||||
*/
|
||||
|
||||
inline bool Stream::IsReadable() const
|
||||
{
|
||||
return (m_openMode & OpenMode_ReadOnly) != 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the stream is sequential
|
||||
* \return true if it is the case
|
||||
*/
|
||||
|
||||
inline bool Stream::IsSequential() const
|
||||
{
|
||||
return (m_streamOptions & StreamOption_Sequential) != 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the stream has text mode enabled
|
||||
* \return true if it is the case
|
||||
*/
|
||||
|
||||
inline bool Stream::IsTextModeEnabled() const
|
||||
{
|
||||
return (m_streamOptions & StreamOption_Text) != 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether the stream can be written
|
||||
* \return true if it is the case
|
||||
*/
|
||||
|
||||
inline bool Stream::IsWritable() const
|
||||
{
|
||||
return (m_openMode & OpenMode_WriteOnly) != 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reads the stream and puts the result in a buffer
|
||||
* \return Size of the read
|
||||
*
|
||||
* \param buffer Buffer to stock data
|
||||
* \param size Size meant to be read
|
||||
*
|
||||
* \remark Produces a NazaraAssert if stream is not readable
|
||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline std::size_t Stream::Read(void* buffer, std::size_t size)
|
||||
{
|
||||
NazaraAssert(IsReadable(), "Stream is not readable");
|
||||
@@ -65,6 +125,17 @@ namespace Nz
|
||||
return ReadBlock(buffer, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Writes in the stream the content of a buffer
|
||||
* \return Size of the writing
|
||||
*
|
||||
* \param buffer Buffer to get data from
|
||||
* \param size Size meant to be written
|
||||
*
|
||||
* \remark Produces a NazaraAssert if stream is not writable
|
||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
||||
*/
|
||||
|
||||
inline std::size_t Stream::Write(const void* buffer, std::size_t size)
|
||||
{
|
||||
NazaraAssert(IsWritable(), "Stream is not writable");
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace Nz
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
|
||||
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne
|
||||
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne
|
||||
None = 0x00, // Default mode
|
||||
CaseInsensitive = 0x01, // Case insensitive
|
||||
HandleUtf8 = 0x02, // Considers bytes as a list of UTF-8 characters
|
||||
TrimOnlyLeft = 0x04, // Trim(med), only cut the left part of the string
|
||||
TrimOnlyRight = 0x08 // Trim(med), only cut the right part of the string
|
||||
};
|
||||
|
||||
String();
|
||||
@@ -71,7 +71,7 @@ namespace Nz
|
||||
std::size_t FindAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindLast(char character, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLast(const char *string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLast(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLast(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastAny(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
|
||||
@@ -7,22 +7,42 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Constructs a String object with a shared string by move semantic
|
||||
*
|
||||
* \param sharedString Shared string to move into this
|
||||
*/
|
||||
|
||||
inline String::String(std::shared_ptr<SharedString>&& sharedString) :
|
||||
m_sharedString(std::move(sharedString))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Releases the content to the string
|
||||
*/
|
||||
|
||||
inline void String::ReleaseString()
|
||||
{
|
||||
m_sharedString = std::move(GetEmptyString());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object by default
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString() : // Special case: empty string
|
||||
capacity(0),
|
||||
size(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object with a size
|
||||
*
|
||||
* \param strSize Number of characters in the string
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString(std::size_t strSize) :
|
||||
capacity(strSize),
|
||||
size(strSize),
|
||||
@@ -31,6 +51,13 @@ namespace Nz
|
||||
string[strSize] = '\0';
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object with a size and a capacity
|
||||
*
|
||||
* \param strSize Number of characters in the string
|
||||
* \param strCapacity Capacity in characters in the string
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString(std::size_t strSize, std::size_t strCapacity) :
|
||||
capacity(strCapacity),
|
||||
size(strSize),
|
||||
@@ -39,6 +66,14 @@ namespace Nz
|
||||
string[strSize] = '\0';
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends the string to the hash
|
||||
* \return true if hash is successful
|
||||
*
|
||||
* \param hash Hash to append data of the file
|
||||
* \param string String to hash
|
||||
*/
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const String& string)
|
||||
{
|
||||
hash->Append(reinterpret_cast<const UInt8*>(string.GetConstBuffer()), string.GetSize());
|
||||
@@ -48,6 +83,13 @@ namespace Nz
|
||||
|
||||
namespace std
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param str String to hash
|
||||
*/
|
||||
|
||||
template<>
|
||||
struct hash<Nz::String>
|
||||
{
|
||||
|
||||
@@ -6,18 +6,43 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::TaskScheduler
|
||||
* \brief Core class that represents a thread pool
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Adds a task to the pending list
|
||||
*
|
||||
* \param function Task that the pool will execute
|
||||
*/
|
||||
|
||||
template<typename F>
|
||||
void TaskScheduler::AddTask(F function)
|
||||
{
|
||||
AddTaskFunctor(new FunctorWithoutArgs<F>(function));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a task to the pending list
|
||||
*
|
||||
* \param function Task that the pool will execute
|
||||
* \param args Arguments of the function
|
||||
*/
|
||||
|
||||
template<typename F, typename... Args>
|
||||
void TaskScheduler::AddTask(F function, Args&&... args)
|
||||
{
|
||||
AddTaskFunctor(new FunctorWithArgs<F, Args...>(function, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a task to the pending list
|
||||
*
|
||||
* \param function Task that the pool will execute
|
||||
* \param object Object on which the method will be called
|
||||
*/
|
||||
|
||||
template<typename C>
|
||||
void TaskScheduler::AddTask(void (C::*function)(), C* object)
|
||||
{
|
||||
|
||||
@@ -7,18 +7,43 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \class Nz::Thread
|
||||
* \brief Core class that represents a thread
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread<T> object with a function
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
*/
|
||||
|
||||
template<typename F>
|
||||
Thread::Thread(F function)
|
||||
{
|
||||
CreateImpl(new FunctorWithoutArgs<F>(function));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread<T> object with a function and its parameters
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
* \param args Arguments of the function
|
||||
*/
|
||||
|
||||
template<typename F, typename... Args>
|
||||
Thread::Thread(F function, Args&&... args)
|
||||
{
|
||||
CreateImpl(new FunctorWithArgs<F, Args...>(function, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Thread<T> object with a member function and its object
|
||||
*
|
||||
* \param function Task the thread will execute in parallel
|
||||
* \param object Object on which the method will be called
|
||||
*/
|
||||
|
||||
template<typename C>
|
||||
Thread::Thread(void (C::*function)(), C* object)
|
||||
{
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Pas de header guard
|
||||
// No header guard
|
||||
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
|
||||
// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation
|
||||
// These macroes can change for any file which uses it in the same unit of compilation
|
||||
#undef NazaraLock
|
||||
#undef NazaraMutex
|
||||
#undef NazaraMutexAttrib
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Pas de header guard
|
||||
// No header guard
|
||||
|
||||
// Ces macros peuvent changer pour n'importe quel fichier qui l'utilise dans une même unité de compilation
|
||||
// These macroes can change for any file which uses it in the same unit of compilation
|
||||
#undef NazaraLock
|
||||
#undef NazaraMutex
|
||||
#undef NazaraMutexAttrib
|
||||
|
||||
@@ -18,16 +18,16 @@ namespace Nz
|
||||
Unicode() = delete;
|
||||
~Unicode() = delete;
|
||||
/*
|
||||
Catégorie Unicode:
|
||||
-Les valeurs de 0x01 à 0x80 indiquent la catégorie.
|
||||
-Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie.
|
||||
Unicode category:
|
||||
-Values between 0x01 and 0x80 specify the category
|
||||
-Values between 0x100 and 0x10000 specify the subcategory
|
||||
*/
|
||||
enum Category : UInt16
|
||||
{
|
||||
// Catégorie non-reconnue par Nazara
|
||||
// Category not handled by Nazara
|
||||
Category_NoCategory = 0,
|
||||
|
||||
// Lettres
|
||||
// Letters
|
||||
Category_Letter = 0x01, // L
|
||||
Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll
|
||||
Category_Letter_Modifier = Category_Letter | 0x0200, // Lm
|
||||
@@ -35,19 +35,19 @@ namespace Nz
|
||||
Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt
|
||||
Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu
|
||||
|
||||
// Marques
|
||||
// Marks
|
||||
Category_Mark = 0x02, // M
|
||||
Category_Mark_Enclosing = Category_Mark | 0x100, // Me
|
||||
Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn
|
||||
Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc
|
||||
|
||||
// Nombres
|
||||
// Numbers
|
||||
Category_Number = 0x04, // N
|
||||
Category_Number_DecimalDigit = Category_Number | 0x100, // Nd
|
||||
Category_Number_Letter = Category_Number | 0x200, // Nl
|
||||
Category_Number_Other = Category_Number | 0x400, // No
|
||||
|
||||
// Autres
|
||||
// Others
|
||||
Category_Other = 0x08, // C
|
||||
Category_Other_Control = Category_Other | 0x0100, // Cc
|
||||
Category_Other_Format = Category_Other | 0x0200, // Cf
|
||||
@@ -65,13 +65,13 @@ namespace Nz
|
||||
Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps
|
||||
Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po
|
||||
|
||||
// Espacements
|
||||
// Spaces
|
||||
Category_Separator = 0x20, // Z
|
||||
Category_Separator_Line = Category_Separator | 0x0100, // Zl
|
||||
Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp
|
||||
Category_Separator_Space = Category_Separator | 0x0400, // Zs
|
||||
|
||||
// Symboles
|
||||
// Symbols
|
||||
Category_Symbol = 0x40, // S
|
||||
Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc
|
||||
Category_Symbol_Math = Category_Symbol | 0x0200, // Sm
|
||||
|
||||
Reference in New Issue
Block a user