Converted indexing to std::size_t, and fixed the Node templated overloads to properly index any index type (determining what is an index type is a bit of a hack - it should be is_convertible<T, std::size_t> (I think), but I just explicitly wrote down a list)

This commit is contained in:
Jesse Beder
2009-08-19 20:58:07 +00:00
parent ba11f5ae15
commit 81c2e6b6ca
17 changed files with 134 additions and 78 deletions

View File

@@ -37,12 +37,12 @@ namespace YAML
return m_pRef->GetEnd(i);
}
Node* AliasContent::GetNode(unsigned n) const
Node* AliasContent::GetNode(std::size_t n) const
{
return m_pRef->GetNode(n);
}
unsigned AliasContent::GetSize() const
std::size_t AliasContent::GetSize() const
{
return m_pRef->GetSize();
}

View File

@@ -20,8 +20,8 @@ namespace YAML
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const;
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const;
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const;
virtual Node* GetNode(unsigned) const;
virtual unsigned GetSize() const;
virtual Node* GetNode(std::size_t) const;
virtual std::size_t GetSize() const;
virtual bool IsScalar() const;
virtual bool IsMap() const;
virtual bool IsSequence() const;

View File

@@ -33,8 +33,8 @@ namespace YAML
virtual bool GetBegin(std::map <Node *, Node *, ltnode>::const_iterator&) const { return false; }
virtual bool GetEnd(std::vector <Node *>::const_iterator&) const { return false; }
virtual bool GetEnd(std::map <Node *, Node *, ltnode>::const_iterator&) const { return false; }
virtual Node *GetNode(unsigned) const { return 0; }
virtual unsigned GetSize() const { return 0; }
virtual Node *GetNode(std::size_t) const { return 0; }
virtual std::size_t GetSize() const { return 0; }
virtual bool IsScalar() const { return false; }
virtual bool IsMap() const { return false; }
virtual bool IsSequence() const { return false; }

View File

@@ -22,7 +22,7 @@ namespace
template <typename T>
bool IsEntirely(const std::string& str, T func)
{
for(unsigned i=0;i<str.size();i++)
for(std::size_t i=0;i<str.size();i++)
if(!func(str[i]))
return false;

View File

@@ -54,7 +54,7 @@ namespace YAML
bool WriteSingleQuotedString(ostream& out, const std::string& str)
{
out << "'";
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
char ch = str[i];
if(!IsPrintable(ch))
return false;
@@ -71,7 +71,7 @@ namespace YAML
bool WriteDoubleQuotedString(ostream& out, const std::string& str)
{
out << "\"";
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
char ch = str[i];
if(IsPrintable(ch)) {
if(ch == '\"')
@@ -95,7 +95,7 @@ namespace YAML
{
out << "|\n";
out << IndentTo(indent);
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
if(str[i] == '\n')
out << "\n" << IndentTo(indent);
else
@@ -108,7 +108,7 @@ namespace YAML
{
unsigned curIndent = out.col();
out << "#" << Indentation(postCommentIndent);
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
if(str[i] == '\n')
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
else
@@ -120,7 +120,7 @@ namespace YAML
bool WriteAlias(ostream& out, const std::string& str)
{
out << "*";
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
if(!IsPrintable(str[i]) || str[i] == ' ' || str[i] == '\t' || str[i] == '\n' || str[i] == '\r')
return false;
@@ -132,7 +132,7 @@ namespace YAML
bool WriteAnchor(ostream& out, const std::string& str)
{
out << "&";
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
if(!IsPrintable(str[i]) || str[i] == ' ' || str[i] == '\t' || str[i] == '\n' || str[i] == '\r')
return false;

View File

@@ -10,7 +10,7 @@ namespace YAML
unsigned ParseHex(const std::string& str, const Mark& mark)
{
unsigned value = 0;
for(unsigned i=0;i<str.size();i++) {
for(std::size_t i=0;i<str.size();i++) {
char ch = str[i];
int digit = 0;
if('a' <= ch && ch <= 'f')

View File

@@ -126,7 +126,7 @@ namespace YAML
m_tag = state.TranslateTag(token.value);
for(unsigned i=0;i<token.params.size();i++)
for(std::size_t i=0;i<token.params.size();i++)
m_tag += token.params[i];
pScanner->pop();
}
@@ -209,7 +209,7 @@ namespace YAML
// size
// . Returns the size of this node, if it's a sequence node.
// . Otherwise, returns zero.
unsigned Node::size() const
std::size_t Node::size() const
{
if(!m_pContent)
return 0;
@@ -217,28 +217,12 @@ namespace YAML
return m_pContent->GetSize();
}
const Node& Node::operator [] (unsigned u) const
const Node *Node::FindAtIndex(std::size_t i) const
{
if(!m_pContent)
throw BadDereference();
Node *pNode = m_pContent->GetNode(u);
if(pNode)
return *pNode;
return GetValue(u);
}
const Node& Node::operator [] (int i) const
{
if(!m_pContent)
throw BadDereference();
Node *pNode = m_pContent->GetNode(i);
if(pNode)
return *pNode;
return GetValue(i);
return 0;
return m_pContent->GetNode(i);
}
bool Node::GetScalar(std::string& s) const

View File

@@ -43,8 +43,8 @@ namespace YAML
ostream& operator << (ostream& out, const char *str)
{
unsigned length = std::strlen(str);
for(unsigned i=0;i<length;i++)
std::size_t length = std::strlen(str);
for(std::size_t i=0;i<length;i++)
out.put(str[i]);
return out;
}

View File

@@ -22,7 +22,7 @@ namespace YAML
RegEx::RegEx(const std::string& str, REGEX_OP op): m_op(op)
{
for(unsigned i=0;i<str.size();i++)
for(std::size_t i=0;i<str.size();i++)
m_params.push_back(RegEx(str[i]));
}

View File

@@ -125,7 +125,7 @@ namespace YAML
// OrOperator
template <typename Source>
inline int RegEx::MatchOpOr(const Source& source) const {
for(unsigned i=0;i<m_params.size();i++) {
for(std::size_t i=0;i<m_params.size();i++) {
int n = m_params[i].MatchUnchecked(source);
if(n >= 0)
return n;
@@ -140,7 +140,7 @@ namespace YAML
template <typename Source>
inline int RegEx::MatchOpAnd(const Source& source) const {
int first = -1;
for(unsigned i=0;i<m_params.size();i++) {
for(std::size_t i=0;i<m_params.size();i++) {
int n = m_params[i].MatchUnchecked(source);
if(n == -1)
return -1;
@@ -164,7 +164,7 @@ namespace YAML
template <typename Source>
inline int RegEx::MatchOpSeq(const Source& source) const {
int offset = 0;
for(unsigned i=0;i<m_params.size();i++) {
for(std::size_t i=0;i<m_params.size();i++) {
int n = m_params[i].Match(source + offset); // note Match, not MatchUnchecked because we need to check validity after the offset
if(n == -1)
return -1;

View File

@@ -136,13 +136,13 @@ namespace YAML
// post-processing
if(params.trimTrailingSpaces) {
unsigned pos = scalar.find_last_not_of(' ');
std::size_t pos = scalar.find_last_not_of(' ');
if(pos < scalar.size())
scalar.erase(pos + 1);
}
if(params.chomp <= 0) {
unsigned pos = scalar.find_last_not_of('\n');
std::size_t pos = scalar.find_last_not_of('\n');
if(params.chomp == 0 && pos + 1 < scalar.size())
scalar.erase(pos + 2);
else if(params.chomp == -1 && pos < scalar.size())

View File

@@ -20,7 +20,7 @@ namespace YAML
void Sequence::Clear()
{
for(unsigned i=0;i<m_data.size();i++)
for(std::size_t i=0;i<m_data.size();i++)
delete m_data[i];
m_data.clear();
}
@@ -37,14 +37,14 @@ namespace YAML
return true;
}
Node *Sequence::GetNode(unsigned i) const
Node *Sequence::GetNode(std::size_t i) const
{
if(i < m_data.size())
return m_data[i];
return 0;
}
unsigned Sequence::GetSize() const
std::size_t Sequence::GetSize() const
{
return m_data.size();
}
@@ -145,7 +145,7 @@ namespace YAML
void Sequence::Write(Emitter& out) const
{
out << BeginSeq;
for(unsigned i=0;i<m_data.size();i++)
for(std::size_t i=0;i<m_data.size();i++)
out << *m_data[i];
out << EndSeq;
}
@@ -157,13 +157,13 @@ namespace YAML
int Sequence::Compare(Sequence *pSeq)
{
unsigned n = m_data.size(), m = pSeq->m_data.size();
std::size_t n = m_data.size(), m = pSeq->m_data.size();
if(n < m)
return -1;
else if(n > m)
return 1;
for(unsigned i=0;i<n;i++) {
for(std::size_t i=0;i<n;i++) {
int cmp = m_data[i]->Compare(*pSeq->m_data[i]);
if(cmp != 0)
return cmp;

View File

@@ -20,8 +20,8 @@ namespace YAML
void Clear();
virtual bool GetBegin(std::vector <Node *>::const_iterator& it) const;
virtual bool GetEnd(std::vector <Node *>::const_iterator& it) const;
virtual Node *GetNode(unsigned i) const;
virtual unsigned GetSize() const;
virtual Node *GetNode(std::size_t i) const;
virtual std::size_t GetSize() const;
virtual void Parse(Scanner *pScanner, const ParserState& state);
virtual void Write(Emitter& out) const;

View File

@@ -59,7 +59,7 @@ namespace YAML
friend std::ostream& operator << (std::ostream& out, const Token& token) {
out << TokenNames[token.type] << std::string(": ") << token.value;
for(unsigned i=0;i<token.params.size();i++)
for(std::size_t i=0;i<token.params.size();i++)
out << std::string(" ") << token.params[i];
return out;
}