ewmscp  ..
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
getlineWithTimeout Class Reference

#include <getlineWithTimeout.h>

Inheritance diagram for getlineWithTimeout:
[legend]
Collaboration diagram for getlineWithTimeout:
[legend]

Classes

class  nocopyLine
 

Public Member Functions

 getlineWithTimeout (std::istream &aStream, char aDelimiter)
 
 ~getlineWithTimeout ()
 
bool active ()
 

Private Member Functions

void reader ()
 
- Private Member Functions inherited from unwindCheck
 unwindCheck ()=default
 
 ~unwindCheck ()=default
 
bool isUnwinding () const
 

Private Attributes

std::istream & stream
 
char delimiter
 
bool waitingForData
 
std::string line
 
std::mutex lineMutex
 
std::condition_variable cv
 
std::thread readerThread
 
bool running
 

Detailed Description

Definition at line 9 of file getlineWithTimeout.h.

Constructor & Destructor Documentation

◆ getlineWithTimeout()

getlineWithTimeout::getlineWithTimeout ( std::istream &  aStream,
char  aDelimiter 
)
inline

Definition at line 33 of file getlineWithTimeout.h.

34  :
35  stream(aStream), delimiter(aDelimiter), waitingForData(true) {
36  running = true;
37  readerThread = std::thread(&getlineWithTimeout::reader, this);
38  };

References reader(), readerThread, and running.

Here is the call graph for this function:

◆ ~getlineWithTimeout()

getlineWithTimeout::~getlineWithTimeout ( )
inline

Definition at line 39 of file getlineWithTimeout.h.

39  {
40  if (!isUnwinding()) {
41  readerThread.join();
42  }
43  };

References unwindCheck::isUnwinding(), and readerThread.

Here is the call graph for this function:

Member Function Documentation

◆ active()

bool getlineWithTimeout::active ( )
inline

Definition at line 45 of file getlineWithTimeout.h.

45  {
46  return running;
47  }

References running.

Referenced by followJsonRequestProvider::followStream().

Here is the caller graph for this function:

◆ reader()

void getlineWithTimeout::reader ( )
inlineprivate

Definition at line 18 of file getlineWithTimeout.h.

18  {
19  running = true;
20  while (stream) {
21  std::unique_lock<decltype(lineMutex)> lock(lineMutex);
22  while (!waitingForData) {
23  cv.wait(lock);
24  }
25  std::getline(stream, line, delimiter);
26  waitingForData = false;
27  cv.notify_all();
28  }
29  cv.notify_all();
30  running = false;
31  }

References cv, delimiter, line, lineMutex, running, stream, and waitingForData.

Referenced by getlineWithTimeout().

Here is the caller graph for this function:

Member Data Documentation

◆ cv

std::condition_variable getlineWithTimeout::cv
private

◆ delimiter

char getlineWithTimeout::delimiter
private

Definition at line 11 of file getlineWithTimeout.h.

Referenced by reader().

◆ line

std::string getlineWithTimeout::line
private

Definition at line 13 of file getlineWithTimeout.h.

Referenced by getlineWithTimeout::nocopyLine::line(), and reader().

◆ lineMutex

std::mutex getlineWithTimeout::lineMutex
private

Definition at line 14 of file getlineWithTimeout.h.

Referenced by reader().

◆ readerThread

std::thread getlineWithTimeout::readerThread
private

Definition at line 16 of file getlineWithTimeout.h.

Referenced by getlineWithTimeout(), and ~getlineWithTimeout().

◆ running

bool getlineWithTimeout::running
private

Definition at line 17 of file getlineWithTimeout.h.

Referenced by active(), getlineWithTimeout(), and reader().

◆ stream

std::istream& getlineWithTimeout::stream
private

Definition at line 10 of file getlineWithTimeout.h.

Referenced by reader().

◆ waitingForData

bool getlineWithTimeout::waitingForData
private

The documentation for this class was generated from the following file:
getlineWithTimeout::lineMutex
std::mutex lineMutex
Definition: getlineWithTimeout.h:14
unwindCheck::isUnwinding
bool isUnwinding() const
Definition: unwindCheck.h:19
getlineWithTimeout::cv
std::condition_variable cv
Definition: getlineWithTimeout.h:15
getlineWithTimeout::delimiter
char delimiter
Definition: getlineWithTimeout.h:11
getlineWithTimeout::waitingForData
bool waitingForData
Definition: getlineWithTimeout.h:12
getlineWithTimeout::line
std::string line
Definition: getlineWithTimeout.h:13
getlineWithTimeout::stream
std::istream & stream
Definition: getlineWithTimeout.h:10
getlineWithTimeout::running
bool running
Definition: getlineWithTimeout.h:17
getlineWithTimeout::reader
void reader()
Definition: getlineWithTimeout.h:18
getlineWithTimeout::readerThread
std::thread readerThread
Definition: getlineWithTimeout.h:16