Program Listing for File string.hpp
↰ Return to documentation for file (include/ecl/devices/string.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef ECL_DEVICES_STRING_HPP_
#define ECL_DEVICES_STRING_HPP_
/*****************************************************************************
** Includes
*****************************************************************************/
#include <string>
#include "traits.hpp"
#include "macros.hpp"
/*****************************************************************************
** Namespaces
*****************************************************************************/
namespace ecl {
/*****************************************************************************
** Interface [String]
*****************************************************************************/
class ecl_devices_PUBLIC String {
public:
explicit String(const char* str = "");
virtual ~String();
/*********************
** String Interface
**********************/
const char* c_str();
std::string str();
void clear();
/******************************************
** Device Source Interface
*******************************************/
long read(char &c);
long read(char* s, unsigned long n);
unsigned long remaining();
/******************************************
** Device Sink Interface
*******************************************/
long write(char c);
long write(const char* s, unsigned long n);
/******************************************
** Device Seekable Interface
*******************************************/
unsigned long size();
void flush() {};
/*********************
** Device Interface
**********************/
bool open() { return true; };
bool isOpen() { return true; };
private:
unsigned long buffer_length; // Actual reserved memory is this +1
char *buffer;
char* buffer_cur_write;
char* buffer_cur_read;
void grow(int no_bytes = 256);
};
/*****************************************************************************
** Traits
*****************************************************************************/
template <>
class is_sink<String> : public True {};
template <>
class is_source<String> : public True {};
template <>
class is_sourcesink<String> : public True {};
} // namespace ecl
#endif /* ECL_DEVICES_STRING_HPP_ */