PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PStream.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/devices/PStream.h
4// Purpose: Primary File Stream Interface Device
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PSTREAM_H__
28#define __PSTREAM_H__
29
30#include "PDevice.h"
31#include "../base/PEBLObject.h"
32#include <fstream>
33#include <string>
34
35//Enumeration used to specify whether this is a write or read stream
42
43//Enumeration used to specify text or binary access
44
50
51
52
58
59class PStream: public PDevice, virtual public PEBLObjectBase
60{
61
62public:
63
64
66 PStream(const std::string & filename, StreamDirection dir, StreamType type);
67 PStream (const PStream & ps);
68
70 virtual ~PStream();
71
72
73 void Open(const std::string & filename, StreamDirection dir, StreamType type);
74 void WriteChar(const char character);
75 void WriteString(const std::string & buffer);
76 void WriteBuffer(const std::string & buffer, unsigned int length);
77
78 char ReadChar();
79 std::string ReadToken(const char separator);
80 std::string ReadLine();
81 std::string ReadLineClean();
82
83 bool Eof();
84 bool Eol();
85 bool Close();
87
88
89
90 //overloaded generic PEBLObjectBase methods
91 virtual bool SetProperty(std::string, Variant v);
92 virtual Variant GetProperty(std::string)const;
93 virtual ObjectValidationError ValidateProperty(std::string, Variant v)const;
94 virtual ObjectValidationError ValidateProperty(std::string)const;
95
96
97protected:
98
99 //Inheritable printing Method.
100 virtual std::ostream& SendToStream(std::ostream& out)const;
101
102private:
103 std::string mStreamFileName;
104 std::fstream * mFileStream;
105 StreamDirection mStreamDirection;
106 StreamType mStreamType;
107
108};
109
110
111
112#endif
PEBL_DEVICE_TYPE
Definition PDevice.h:40
@ PDT_STREAM
Definition PDevice.h:49
ObjectValidationError
Definition PEBLObject.h:37
StreamDirection
Definition PStream.h:37
@ sdAppend
Definition PStream.h:40
@ sdWrite
Definition PStream.h:39
@ sdRead
Definition PStream.h:38
StreamType
Definition PStream.h:46
@ stASCII
Definition PStream.h:47
@ stBinary
Definition PStream.h:48
void WriteChar(const char character)
This method sends a single character to the stream.
Definition PStream.cpp:172
virtual std::ostream & SendToStream(std::ostream &out) const
Definition PStream.cpp:408
void WriteBuffer(const std::string &buffer, unsigned int length)
Definition PStream.cpp:190
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PStream.cpp:438
bool Eof()
Definition PStream.cpp:388
virtual bool SetProperty(std::string, Variant v)
Definition PStream.cpp:416
std::string ReadLineClean()
Definition PStream.cpp:323
virtual PEBL_DEVICE_TYPE GetDeviceType()
Definition PStream.h:86
virtual ~PStream()
The Standard destructor.
Definition PStream.cpp:401
std::string ReadToken(const char separator)
This reads up until the next separator token (or eof character)
Definition PStream.cpp:251
PStream(const std::string &filename, StreamDirection dir, StreamType type)
The Standard constructor.
void WriteString(const std::string &buffer)
This method just writes the char* string to the stream.
Definition PStream.cpp:211
virtual Variant GetProperty(std::string) const
Definition PStream.cpp:430
bool Eol()
Definition PStream.cpp:356
void Open(const std::string &filename, StreamDirection dir, StreamType type)
Definition PStream.cpp:118
bool Close()
Definition PStream.cpp:394
std::string ReadLine()
Definition PStream.cpp:290
char ReadChar()
Definition PStream.cpp:230