rewrite
This commit is contained in:
parent
23fa8b98b0
commit
0eed272765
35 changed files with 1634 additions and 1507 deletions
82
interfaces/Crafter.Build-FixedVector.cppm
Normal file
82
interfaces/Crafter.Build-FixedVector.cppm
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
export module Crafter.Build:FixedVector;
|
||||
import std;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Crafter {
|
||||
export template <typename T>
|
||||
class FixedVector {
|
||||
public:
|
||||
using value_type = T;
|
||||
using iterator = T*;
|
||||
using const_iterator = const T*;
|
||||
T* values;
|
||||
std::uint_fast32_t size_;
|
||||
FixedVector() {}
|
||||
FixedVector(std::uint_fast32_t size): values(reinterpet_cast<T*>(operator new[](size * sizeof(T)))), size_(size) {}
|
||||
|
||||
void Set(std::uint_fast32_t size) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_DEBUG
|
||||
if(this->size_ != 0) {
|
||||
throw std::runtime_error("FixedVector already set!");
|
||||
}
|
||||
#endif
|
||||
values = reinterpet_cast<T*>(operator new[](size * sizeof(T)));
|
||||
this->size_ = size;
|
||||
}
|
||||
|
||||
~FixedVector() {
|
||||
delete[] values;
|
||||
}
|
||||
|
||||
FixedVector(const FixedVector&) = delete;
|
||||
FixedVector& operator=(const FixedVector&) = delete;
|
||||
|
||||
FixedVector(FixedVector&& other) noexcept : values(other.values), size_(other.size_) {
|
||||
other.values = nullptr;
|
||||
other.size_ = 0;
|
||||
}
|
||||
|
||||
FixedVector& operator=(FixedVector&& other) noexcept {
|
||||
if (this != &other) {
|
||||
delete[] values;
|
||||
values = other.values;
|
||||
size_ = other.size_;
|
||||
other.values = nullptr;
|
||||
other.size_ = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& operator[](std::uint_fast32_t index) { return values[index]; }
|
||||
const T& operator[](std::uint_fast32_t index) const { return values[index]; }
|
||||
|
||||
std::uint_fast32_t size() const { return size_; }
|
||||
|
||||
iterator begin() { return values; }
|
||||
const_iterator begin() const { return values; }
|
||||
const_iterator cbegin() const { return values; }
|
||||
|
||||
iterator end() { return values + size_; }
|
||||
const_iterator end() const { return values + size_; }
|
||||
const_iterator cend() const { return values + size_; }
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue