proxygen
folly::gen::detail::Window::Generator< Value, Source, StorageType > Class Template Reference

#include <Base-inl.h>

Inheritance diagram for folly::gen::detail::Window::Generator< Value, Source, StorageType >:
folly::gen::GenImpl< StorageType &&, Generator< Value, Source, StorageType > > folly::gen::FBounded< Self >

Public Member Functions

 Generator (Source source, size_t windowSize)
 
template<class Handler >
bool apply (Handler &&handler) const
 
- Public Member Functions inherited from folly::gen::GenImpl< StorageType &&, Generator< Value, Source, StorageType > >
bool apply (Handler &&handler) const
 
void foreach (Body &&body) const
 
- Public Member Functions inherited from folly::gen::FBounded< Self >
const Self & self () const
 
Self & self ()
 

Static Public Attributes

static constexpr bool infinite = Source::infinite
 
- Static Public Attributes inherited from folly::gen::GenImpl< StorageType &&, Generator< Value, Source, StorageType > >
static constexpr bool infinite
 

Private Attributes

Source source_
 
size_t windowSize_
 

Additional Inherited Members

- Public Types inherited from folly::gen::GenImpl< StorageType &&, Generator< Value, Source, StorageType > >
typedef StorageType && ValueType
 
typedef std::decay< StorageType && >::type StorageType
 
- Protected Member Functions inherited from folly::gen::GenImpl< StorageType &&, Generator< Value, Source, StorageType > >
 GenImpl ()=default
 
 GenImpl (GenImpl &&)=default
 
 GenImpl (const GenImpl &)=default
 
GenImploperator= (GenImpl &&)=default
 
GenImploperator= (const GenImpl &)=default
 

Detailed Description

template<class Value, class Source, class StorageType = typename std::decay<Value>::type>
class folly::gen::detail::Window::Generator< Value, Source, StorageType >

Definition at line 1532 of file Base-inl.h.

Constructor & Destructor Documentation

template<class Value , class Source , class StorageType = typename std::decay<Value>::type>
folly::gen::detail::Window::Generator< Value, Source, StorageType >::Generator ( Source  source,
size_t  windowSize 
)
inlineexplicit

Definition at line 1538 of file Base-inl.h.

1539  : source_(std::move(source)), windowSize_(windowSize) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class Value , class Source , class StorageType = typename std::decay<Value>::type>
template<class Handler >
bool folly::gen::detail::Window::Generator< Value, Source, StorageType >::apply ( Handler &&  handler) const
inline

Definition at line 1542 of file Base-inl.h.

References buffer(), handler(), i, folly::gen::move, value, and testing::Value().

1542  {
1543  std::vector<StorageType> buffer;
1544  buffer.reserve(windowSize_);
1545  size_t readIndex = 0;
1546  bool shouldContinue = source_.apply([&](Value value) -> bool {
1547  if (buffer.size() < windowSize_) {
1548  buffer.push_back(std::forward<Value>(value));
1549  } else {
1550  StorageType& entry = buffer[readIndex++];
1551  if (readIndex == windowSize_) {
1552  readIndex = 0;
1553  }
1554  if (!handler(std::move(entry))) {
1555  return false;
1556  }
1557  entry = std::forward<Value>(value);
1558  }
1559  return true;
1560  });
1561  if (!shouldContinue) {
1562  return false;
1563  }
1564  if (buffer.size() < windowSize_) {
1565  for (StorageType& entry : buffer) {
1566  if (!handler(std::move(entry))) {
1567  return false;
1568  }
1569  }
1570  } else {
1571  for (size_t i = readIndex;;) {
1572  StorageType& entry = buffer[i++];
1573  if (!handler(std::move(entry))) {
1574  return false;
1575  }
1576  if (i == windowSize_) {
1577  i = 0;
1578  }
1579  if (i == readIndex) {
1580  break;
1581  }
1582  }
1583  }
1584  return true;
1585  }
std::vector< uint8_t > buffer(kBufferSize+16)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
bool Value(const T &value, M matcher)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)

Member Data Documentation

template<class Value , class Source , class StorageType = typename std::decay<Value>::type>
constexpr bool folly::gen::detail::Window::Generator< Value, Source, StorageType >::infinite = Source::infinite
static

Definition at line 1588 of file Base-inl.h.

template<class Value , class Source , class StorageType = typename std::decay<Value>::type>
Source folly::gen::detail::Window::Generator< Value, Source, StorageType >::source_
private

Definition at line 1534 of file Base-inl.h.

template<class Value , class Source , class StorageType = typename std::decay<Value>::type>
size_t folly::gen::detail::Window::Generator< Value, Source, StorageType >::windowSize_
private

Definition at line 1535 of file Base-inl.h.


The documentation for this class was generated from the following file: