[DEBUG] add missing file

This commit is contained in:
Edouard DUPIN 2016-04-19 23:58:45 +02:00
parent f08b7431e4
commit 6c35663d89
2 changed files with 190 additions and 0 deletions

95
ejson/FilePos.cpp Normal file
View File

@ -0,0 +1,95 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <ejson/FilePos.h>
ejson::FilePos::FilePos() :
m_col(0),
m_line(0) {
}
ejson::FilePos::FilePos(size_t _line, size_t _col) :
m_col(_col),
m_line(_line) {
}
ejson::FilePos& ejson::FilePos::operator ++() {
m_col++;
return *this;
}
ejson::FilePos& ejson::FilePos::operator --() {
if(m_col>0) {
m_col--;
}
return *this;
}
ejson::FilePos& ejson::FilePos::operator +=(const ejson::FilePos& _obj) {
if (_obj.m_line == 0) {
m_col += _obj.m_col;
} else {
m_col = _obj.m_col;
m_line += _obj.m_line;
}
return *this;
}
ejson::FilePos& ejson::FilePos::operator +=(size_t _col) {
m_col += _col;
return *this;
}
ejson::FilePos& ejson::FilePos::operator= (const ejson::FilePos& _obj ) {
m_col = _obj.m_col;
m_line = _obj.m_line;
return *this;
}
void ejson::FilePos::newLine() {
m_col=0;
m_line++;
}
bool ejson::FilePos::check(char32_t _val) {
m_col++;
if (_val == '\n') {
newLine();
return true;
}
return false;
}
void ejson::FilePos::set(size_t _line, size_t _col) {
m_col = _col;
m_line = _line;
}
void ejson::FilePos::clear() {
m_col = 0;
m_line = 0;
}
size_t ejson::FilePos::getCol() const {
return m_col;
}
size_t ejson::FilePos::getLine() const {
return m_line;
}
std::ostream& ejson::operator <<(std::ostream& _os, const ejson::FilePos& _obj) {
_os << "(l=";
_os << _obj.getLine();
_os << ",c=";
_os << _obj.getCol();
_os << ")";
return _os;
}

95
ejson/FilePos.h Normal file
View File

@ -0,0 +1,95 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <etk/types.h>
namespace ejson {
/**
* @brief Position in the file of the original data.
*/
class FilePos {
private:
size_t m_col; //!< source text colomn
size_t m_line; //!< source Line colomn
public:
/**
* @brief default contructor (set line and col at 0)
*/
FilePos();
/**
* @brief initialize constructor
* @param[in] _line Line in the file
* @param[in] _col Colomn in the file
*/
FilePos(size_t _line, size_t _col);
/**
* @brief Increment the colomn position
* @return Reference on this
*/
FilePos& operator ++();
/**
* @brief Decrement the colomn position
* @return Reference on this
*/
FilePos& operator --();
/**
* @brief Addition operator
* @param[in] _obj Addition object..
* @return Reference on this
*/
FilePos& operator +=(const FilePos& _obj);
/**
* @brief Colomn addition operator
* @param[in] _col Number of colomn to add
* @return Reference on this
*/
FilePos& operator +=(size_t _col);
/**
* @brief Asignment operator
* @param[in] _obj Object to copy
* @return Reference on this
*/
FilePos& operator= (const FilePos& _obj);
/**
* @brief Find a new line & reset colomn at 0
*/
void newLine();
/**
* @brief Check if the value is a new line and update internal property
* @param[in] _val Char value to check
* @return true We find a new line
* @return false We NOT find a new line
*/
bool check(char32_t _val);
/**
* @brief Setter of specific data
* @param[in] _line Line in the file
* @param[in] _col Colomn in the file
*/
void set(size_t _line, size_t _col);
/**
* @brief Reset position at 0,0
*/
void clear();
/**
* @brief Get the colomn position
* @return Colomn in number of utf8-char
*/
size_t getCol() const;
/**
* @brief Get the line number position
* @return line ID (start at 0)
*/
size_t getLine() const;
};
//! @not-in-doc
std::ostream& operator <<(std::ostream& _os, const FilePos& _obj);
}