diff --git a/CMakeLists.txt b/CMakeLists.txt index 162150afa23ba671579b0c2e03d90719ba988c85..625db7c4eb73b61b3df12702bec06a15301aa192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required (VERSION 3.4.3) +set (CMAKE_INSTALL_MESSAGE LAZY) + set (CMAKE_CXX_STANDARD 14) project (corsika VERSION 8.0.0 DESCRIPTION "CORSIKA C++ project") diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 57cdd849235fbc73af01491ec9192df9be687b8a..3081b355fb399764fc3dd46b826af62ccbc074ed 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory (Units) add_subdirectory (Geometry) add_subdirectory (Logging) +add_subdirectory (StackInterface) diff --git a/Framework/StackInterface/CMakeList.txt b/Framework/StackInterface/CMakeList.txt new file mode 100644 index 0000000000000000000000000000000000000000..aea441bd22ca6fd91def7826534b5c5e3e98814d --- /dev/null +++ b/Framework/StackInterface/CMakeList.txt @@ -0,0 +1,10 @@ + +add_library (CORSIKAstack INTERFACE) + +target_include_directories (CORSIKAstack INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework> + $<INSTALL_INTERFACE:include/Framework> + ) + +install (FILES Stack.h StackIterator.h + DESTINATION include/Stack) + diff --git a/Framework/StackInterface/CMakeLists.txt b/Framework/StackInterface/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f37313a26f26c2595eb43682195a85304f00822e --- /dev/null +++ b/Framework/StackInterface/CMakeLists.txt @@ -0,0 +1,10 @@ + +add_library (CORSIKAstackinterface INTERFACE) + +target_include_directories (CORSIKAstackinterface INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework> + $<INSTALL_INTERFACE:include/Framework> + ) + +install (FILES Stack.h StackIterator.h + DESTINATION include/StackInterface) + diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h new file mode 100644 index 0000000000000000000000000000000000000000..3bf7a3c28db17c9ea00f2c7b3bbe5428e33c80d8 --- /dev/null +++ b/Framework/StackInterface/Stack.h @@ -0,0 +1,44 @@ +#ifndef _include_Stack_h__ +#define _include_Stack_h__ + +#include <StackIterator.h> // to help application programmres + +namespace stack { + + /** + Interface definition of a Stack object. + */ + + template<typename DataImpl, typename Particle> + class Stack : public DataImpl { + + public: + using DataImpl::Capacity; + using DataImpl::Size; + + using DataImpl::Clear; + using DataImpl::Copy; + + using DataImpl::IncrementSize; + using DataImpl::DecrementSize; + + public: + typedef Particle iterator; + typedef const Particle const_iterator; + + iterator Begin() { return iterator(*this, 0); } + iterator End() { return iterator(*this, Size()); } + iterator Last() { return iterator(*this, Size()-1); } + + const_iterator CBegin() const { return const_iterator(*this, 0); } + const_iterator CEnd() const { return const_iterator(*this, Size()); } + const_iterator CLast() const { return const_iterator(*this, Size()-1); } + + iterator NewParticle() { IncrementSize(); return iterator(*this, Size()-1); } + void DeleteLast() { DecrementSize(); } + }; + +} // end namespace + +#endif + diff --git a/Framework/StackInterface/StackIterator.h b/Framework/StackInterface/StackIterator.h new file mode 100644 index 0000000000000000000000000000000000000000..3070ae68a9ee96f11cde620a0d1de324c86e5afa --- /dev/null +++ b/Framework/StackInterface/StackIterator.h @@ -0,0 +1,70 @@ +#ifndef _include_StackIterator_h__ +#define _include_StackIterator_h__ + +#include <iostream> +#include <iomanip> + +namespace stack { + + template<class Stack, class Particle> class StackIteratorInfo; + + /** + The main interface to iterator over objects on a stack. + */ + + template<typename Stack, typename Particle> + class StackIterator : public Particle + { + friend Stack; + friend Particle; + friend StackIteratorInfo<Stack,Particle>; + + private: + int fIndex; + + //#warning stacks should not be copied because of this: + Stack* fData; + + public: + StackIterator() : fData(0), fIndex(0) { } + StackIterator(Stack& data, const int index) : fData(&data), fIndex(index) { } + StackIterator(const StackIterator& mit) : fData(mit.fData), fIndex(mit.fIndex) { } + + StackIterator& operator++() { ++fIndex; return *this; } + StackIterator operator++(int) { StackIterator tmp(*this); ++fIndex; return tmp; } + bool operator==(const StackIterator& rhs) { return fIndex == rhs.fIndex; } + bool operator!=(const StackIterator& rhs) { return fIndex != rhs.fIndex; } + + StackIterator& operator*() { return *this; } + const StackIterator& operator*() const { return *this; } + + protected: + int GetIndex() const { return fIndex; } + Stack& GetStack() { return *fData; } + const Stack& GetStack() const { return *fData; } + + inline StackIterator<Stack,Particle>& base_ref() { return static_cast<StackIterator<Stack, Particle>&>(*this); } + inline const StackIterator<Stack,Particle>& base_ref() const { return static_cast<const StackIterator<Stack, Particle>&>(*this); } + }; + + + /** + Internal helper class for StackIterator + */ + + template<class _Stack, class Particle> + class StackIteratorInfo { + + friend Particle; + private: + StackIteratorInfo() {} + + protected: + inline _Stack& Stack() { return static_cast<StackIterator<_Stack, Particle>*>(this)->GetStack(); } + inline int Index() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetIndex(); } + inline const _Stack& Stack() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetStack(); } + }; + +} // end namespace stack + +#endif