74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
/* _______________ ,----------------------------------------------------------------.
|
|
//`````````````\\ \ \
|
|
//~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \
|
|
//=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \
|
|
// \\ \ \
|
|
// \\ \ code released under the zlib license [git.nugget.fun/pudding] \
|
|
// ☆ GUNKISS ☆ \\ \ \
|
|
//_________________________\\ `---------------------------------------------------------------*/
|
|
|
|
#ifndef CAROUSEL_H_
|
|
#define CAROUSEL_H_
|
|
|
|
#include <cstdint>
|
|
#include <iterator>
|
|
#include "utility.hpp"
|
|
|
|
class Carousel
|
|
{
|
|
|
|
private:
|
|
|
|
std::uint32_t offset = 0;
|
|
|
|
public:
|
|
|
|
template<typename Container>
|
|
auto current(Container& container)
|
|
{
|
|
auto location = container.begin();
|
|
if (location != container.end())
|
|
{
|
|
std::advance(location, offset);
|
|
return location;
|
|
}
|
|
else
|
|
{
|
|
throw std::out_of_range("Container is empty");
|
|
}
|
|
}
|
|
|
|
template<typename Container>
|
|
auto next(const Container& container)
|
|
{
|
|
offset = ++offset % container.size();
|
|
}
|
|
|
|
template<typename Container>
|
|
auto previous(const Container& container)
|
|
{
|
|
offset = sb::mod(--offset, container.size());
|
|
}
|
|
|
|
template<typename Container>
|
|
auto increment(const Container& container, int amount)
|
|
{
|
|
offset = sb::mod(offset + amount, container.size());
|
|
}
|
|
|
|
template<typename Container>
|
|
auto beginning()
|
|
{
|
|
offset = 0;
|
|
}
|
|
|
|
template<typename Container>
|
|
auto end(const Container& container)
|
|
{
|
|
offset = container.size() - 1;
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|