class Stream {
public:
Stream(StringRef Input, SourceMgr &);
+ ~Stream();
document_iterator begin();
document_iterator end();
};
Node(unsigned int Type, OwningPtr<Document>&, StringRef Anchor);
- virtual ~Node();
/// @brief Get the value of the anchor attached to this node. If it does not
/// have one, getAnchor().size() will be 0.
void setError(const Twine &Message, Token &Location) const;
bool failed() const;
- virtual void skip() {};
+ virtual void skip() {}
unsigned int getType() const { return TypeID; }
static inline bool classof(const Node *) { return true; }
OwningPtr<Document> &Doc;
SMRange SourceRange;
+ void operator delete(void *) throw() {}
+
+ virtual ~Node() {}
+
private:
unsigned int TypeID;
StringRef Anchor;
, SmallVectorImpl<char> &Storage) const;
};
-static bool getAs(const ScalarNode *SN, bool &Result) {
- SmallString<4> Storage;
- StringRef Value = SN->getValue(Storage);
- if (Value == "true")
- Result = true;
- else if (Value == "false")
- Result = false;
- else
- return false;
- return true;
-}
-
-template<class T>
-typename enable_if_c<std::numeric_limits<T>::is_integer, bool>::type
-getAs(const ScalarNode *SN, T &Result) {
- SmallString<4> Storage;
- return !SN->getValue(Storage).getAsInteger(0, Result);
-}
-
/// @brief A key and value pair. While not technically a Node under the YAML
/// representation graph, it is easier to treat them this way.
///
enum MappingType {
MT_Block,
MT_Flow,
- MT_Inline //< An inline mapping node is used for "[key: value]".
+ MT_Inline ///< An inline mapping node is used for "[key: value]".
};
MappingNode(OwningPtr<Document> &D, StringRef Anchor, MappingType MT)
/// @brief Iterator abstraction for Documents over a Stream.
class document_iterator {
public:
- document_iterator() : Doc(NullDoc) {}
- document_iterator(OwningPtr<Document> &D) : Doc(D) {}
+ document_iterator() : Doc(0) {}
+ document_iterator(OwningPtr<Document> &D) : Doc(&D) {}
+
+ bool operator ==(const document_iterator &Other) {
+ if (isAtEnd() || Other.isAtEnd())
+ return isAtEnd() && Other.isAtEnd();
+ return *Doc == *Other.Doc;
+ }
bool operator !=(const document_iterator &Other) {
- return Doc != Other.Doc;
+ return !(*this == Other);
}
document_iterator operator ++() {
- if (!Doc->skip()) {
- Doc.reset(0);
+ assert(Doc != 0 && "incrementing iterator past the end.");
+ if (!(*Doc)->skip()) {
+ Doc->reset(0);
} else {
- Stream &S = Doc->stream;
- Doc.reset(new Document(S));
+ Stream &S = (*Doc)->stream;
+ Doc->reset(new Document(S));
}
return *this;
}
Document &operator *() {
- return *Doc;
+ return *Doc->get();
}
OwningPtr<Document> &operator ->() {
- return Doc;
+ return *Doc;
}
private:
- static OwningPtr<Document> NullDoc;
- OwningPtr<Document> &Doc;
+ bool isAtEnd() const {
+ return Doc == 0 || *Doc == 0;
+ }
+
+ OwningPtr<Document> *Doc;
};
}