Alien-SmokeQt
view release on metacpan or search on metacpan
generator/parser/rpp/pp-stream.h view on Meta::CPAN
#ifndef STREAM_H
#define STREAM_H
#include <QtCore/QIODevice>
#include "../cppparser_export.h"
#include "../simplecursor.h"
#include "../indexedstring.h"
#include "anchor.h"
#include "chartools.h"
typedef QVector<unsigned int> PreprocessedContents;
namespace KDevelop {
class IndexedString;
}
namespace rpp {
class LocationTable;
/**
* Stream designed for character-at-a-time processing
*
* @author Hamish Rodda <rodda@kde.org>
*/
class CPPPARSER_EXPORT Stream
{
static const uint newline;
public:
Stream();
//If the given offset anchor has the member "collapsed" set to true, the position will be locked.
explicit Stream( const uint * string, uint stringSize, const Anchor& offset = Anchor(0,0), LocationTable* table = 0 );
explicit Stream( PreprocessedContents * string, const Anchor& offset = Anchor(0,0), LocationTable* table = 0 );
explicit Stream( PreprocessedContents * string, LocationTable* table );
virtual ~Stream();
bool isNull() const;
bool atEnd() const;
void toEnd();
/// Returns true if toEnd was called on this stream.
bool skippedToEnd() const;
int offset() const;
const uint& peek(uint offset = 1) const;
char peekNextCharacter() const {
const unsigned int* next = c+1;
if (next >= end || !isCharacter(*next))
return (char)0;
return characterFromIndex(*next);
}
//Slow, just for debugging
QByteArray stringFrom(int offset) const;
/// \warning the input and output lines are not updated when calling this function.
/// if you're seek()ing over a line boundary, you'll need to fix the line and column
/// numbers.
void seek(int offset);
/// Start from the beginning again
void reset();
/// Lock/unlock the input position. If the input position is locked, it will not be moved forwards.
void lockInputPosition(bool lock);
/// If a macro-expansion is set, all anchors given to mark() will get that macro-expansion set.
/// It marks the position from where the macro-expansion was started that leads to the current output @see rpp::Anchor
void setMacroExpansion(const SimpleCursor&);
SimpleCursor macroExpansion() const;
//Checks whether the current index represents a character, and eventually compares it
bool operator==(const char otherc) const {
return isCharacter(*c) && *c == indexFromCharacter(otherc);
}
//Checks whether the current index represents a character, and eventually compares it
bool operator!=(const char otherc) const {
return !isCharacter(*c) || *c != indexFromCharacter(otherc);
}
inline const uint& current() const { return *c; } //krazy:exclude=inline
inline operator const uint&() const { return *c; } //krazy:exclude=inline
inline Stream& operator++() //krazy:exclude=inline
{
if (c == end)
return *this;
if(m_inputPositionLocked)
++m_inputLineStartedAt;
else if (*c == newline) {
++m_inputLine;
m_inputLineStartedAt = m_pos + 1;
}else if(!isCharacter(*c)) {
//We have to do some special hacking here to keep the column-number correct.
m_inputLineStartedAt += 1-IndexedString::fromIndex(*c).length();
}
++c;
++m_pos;
return *this;
}
///@warning Doesn't handle newlines correctly!
Stream& operator--();
///Removes the last added item from the output, and returns it
uint popLastOutput();
///Allows peeking at the items that were added to the output recently
uint peekLastOutput(uint backOffset = 0) const;
( run in 0.404 second using v1.01-cache-2.11-cpan-119454b85a5 )