Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfovich committed Sep 10, 2024
1 parent 373a4d3 commit c142075
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/HW3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
paths:
- 'HW3/**'
- '.github/workflows/HW3.yml'
#- '.github/workflows/HW3.yml'

permissions:
actions: write
Expand Down
58 changes: 35 additions & 23 deletions HW3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
cmake_minimum_required(VERSION 3.12)

option(BUILD_TESTS "BuildTests" ON)
option(BUILD_BENCHMARK "BuildBenchmark" OFF)
set(PROJECT_VERSION "0.0.3" CACHE INTERNAL "Version")
project (allocator VERSION ${PROJECT_VERSION})

cmake_minimum_required (VERSION 3.25)
# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/lib")
option(BUILD_TESTS "Build tests" ON)
option(CONFIGURE_DEB_PACKAGE "Configure .deb package" OFF)
option(BUILD_BENCHMARK "Build benchmark" OFF)

set(TARGET_NAME allocator_driver CACHE INTERNAL "Target name")
set(PROJECT_VERSION "0.0.1" CACHE INTERNAL "Version")

add_subdirectory(allocator_driver)
project (${TARGET_NAME} VERSION ${PROJECT_VERSION})
add_executable (${TARGET_NAME} "src/main.cpp")
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 20)
set_target_properties(${TARGET_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "$<0:>${CMAKE_BINARY_DIR}/lib"
)

target_link_libraries(${TARGET_NAME} allocator_lib cc_lib)
add_subdirectory(allocator_lib)
add_subdirectory(cc_lib)

# deb-package.
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME "allocator_driver")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_CONTACT [email protected])
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/deb")
include(CPack)
# .deb package.
if(CONFIGURE_DEB_PACKAGE)
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_NAME ${TARGET_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/deb")
include(CPack)
endif()

# Tests.
enable_testing()
add_subdirectory(tests)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(BuildBenchmark)
# Benchmark.
if(BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
68 changes: 62 additions & 6 deletions HW3/cc_lib/include/cc/forward_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,79 @@
#include <memory>
#include <cinttypes>

#include <list>

namespace cc {

template<typename T, typename Allocator = std::allocator<T>>
class ForwardList
{
public:


public: // types
template<typename T>
class ForwardListIterator
{
public:
using difference_type = std::ptrdiff_t;
using value_type = T;

const T& operator*() const {
return *this;
}

T& operator*() { return node->data; }

ForwardListIterator& operator++();

ForwardListIterator operator++(int)
{
auto tmp = *this;
++*this;
return tmp;
}

bool operator==(const ForwardListIterator&) const {
return false;
}
private:
ForwardList<T, Allocator>::Node* node = nullptr;
ForwardList<T, Allocator>* list = nullptr;
};

using value_type = T;
using allocator_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = std::allocator_traits<Allocator>::const_pointer;
using iterator = ForwardListIterator<T>;
using const_iterator = ForwardListIterator<const T>;

public: // methods
void f(){
ForwardListIterator i;
// i.node;
ForwardList<int>::const_iterator iter;
//++iter;

std::list<int>::const_iterator iii;
++iii;
*iii = 23;
}
private: // types
struct Node
{
T data;
std::unique_ptr<Node> nextNode = nullptr;
template<typename U>
friend class ForwardListIterator;
T data;
Node nextNode = nullptr;
};

private: // data
Allocator allocator;
std::unique_ptr<Node> firstNode = nullptr;
std::size_t size = 0;
Allocator allocator;
Node* firstNode = nullptr;
std::size_t size = 0;
};

} // namespace cc
File renamed without changes.
5 changes: 5 additions & 0 deletions HW3/allocator_driver/main.cpp → HW3/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>
#include <map>

#include <forward_list>

template<typename T>
T factorial(T n){
if(n < 0){
Expand Down Expand Up @@ -44,5 +46,8 @@ int main()
std::cout << key << ": " << value << '\n';
}

cc::ForwardList<int> list;
cc::ForwardList<int>::iterator iter;
list.f();
return 0;
}

0 comments on commit c142075

Please sign in to comment.