Skip to content

Commit

Permalink
Merge pull request #49 from open-space-collective/dev@lucas
Browse files Browse the repository at this point in the history
Dev@lucas
  • Loading branch information
lucas-bremond authored Sep 20, 2018
2 parents 45b26d3 + 6b9b3ac commit 6c489b1
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Library :: Core
===============
Library Core
==============

Fundamental types, containers and utilities.

Expand Down
2 changes: 1 addition & 1 deletion docs/doxygen/html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="topbanner"><a href="https://github.com/open-space-collective/library-core" title="Library :: Core"><i class="githublogo"></i></a></div>
<div id="topbanner"><a href="https://github.com/open-space-collective/library-core" title="Library Core"><i class="githublogo"></i></a></div>
$searchbox
<!--END TITLEAREA-->
<!-- end header part -->
31 changes: 30 additions & 1 deletion include/Library/Core/Containers/Table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Table
/// @endcode
///
/// @param [in] aTable A table
/// @return True if tables not are equal
/// @return True if tables are not equal

bool operator != ( const Table& aTable ) const ;

Expand All @@ -137,11 +137,26 @@ class Table
/// @endcode
///
/// @param [in] aRowIndex A row index
/// @param [in] aColumnIndex A column index
/// @return Reference to cell

const Cell& operator () ( const Index& aRowIndex,
const Index& aColumnIndex ) const ;

/// @brief Function call operator (cell accessor)
///
/// @code
/// Table table = { { "Column A", "Column B" }, { { Cell::Integer(123), Cell::Real(123.456) } } } ;
/// const Cell& cell = table(0, "Column A") ; // Cell::Integer(123)
/// @endcode
///
/// @param [in] aRowIndex A row index
/// @param [in] aColumnName A column name
/// @return Reference to cell

const Cell& operator () ( const Index& aRowIndex,
const String& aColumnName ) const ;

/// @brief Output stream operator
///
/// @code
Expand All @@ -165,6 +180,13 @@ class Table

bool isEmpty ( ) const ;

/// @brief Returns true is table has column with a given name
///
/// @param [in] aColumnName A column name
/// @return True is table has column with a given name

bool hasColumnWithName ( const String& aColumnName ) const ;

/// @brief Get number of rows
///
/// @code
Expand All @@ -187,6 +209,13 @@ class Table

Size getColumnCount ( ) const ;

/// @brief Returns the index of column with a given name
///
/// @param [in] aColumnName A column name
/// @return Index of column with a given name

Index getIndexOfColumnWithName ( const String& aColumnName ) const ;

/// @brief Add row
///
/// @code
Expand Down
3 changes: 3 additions & 0 deletions include/Library/Core/Containers/Table/Row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace table

using library::core::types::Index ;
using library::core::types::Size ;
using library::core::types::String ;
using library::core::ctnr::Array ;
using library::core::ctnr::table::Cell ;

Expand Down Expand Up @@ -70,6 +71,8 @@ class Row

const Cell& operator [] ( const Index& aColumnIndex ) const ;

const Cell& operator [] ( const String& aColumnName ) const ;

bool isEmpty ( ) const ;

Size getSize ( ) const ;
Expand Down
2 changes: 1 addition & 1 deletion include/Library/Core/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Logger

#define LOG_SCOPE0() BOOST_LOG_NAMED_SCOPE("?")
#define LOG_SCOPE1(aScope) BOOST_LOG_NAMED_SCOPE(aScope)
#define LOG_SCOPE2(aClass, aMethod) BOOST_LOG_NAMED_SCOPE(aClass " :: " aMethod)
#define LOG_SCOPE2(aClass, aMethod) BOOST_LOG_NAMED_SCOPE(aClass " " aMethod)

#define LOG_SCOPE(...) GET_MACRO(_0, ##__VA_ARGS__, LOG_SCOPE2, LOG_SCOPE1, LOG_SCOPE0)(__VA_ARGS__)

Expand Down
4 changes: 2 additions & 2 deletions share/python/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Library :: Core :: Python Bindings
==================================
Library Core Python Bindings
================================
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Library :: Core"
"# Library Core"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion share/util/Test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::ostream& operator << (
const TestClass& aTestClass )
{

anOutputStream << "Class :: " << aTestClass.integer_ << " " << aTestClass.double_ ;
anOutputStream << "Class " << aTestClass.integer_ << " " << aTestClass.double_ ;

return anOutputStream ;

Expand Down
53 changes: 52 additions & 1 deletion src/Library/Core/Containers/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ const Cell& Table::operator () (

}

const Cell& Table::operator () ( const Index& aRowIndex,
const String& aColumnName ) const
{

if (aRowIndex >= rows_.getSize())
{
throw library::core::error::RuntimeError("Row index [{}] out of range [0 - {}].", aRowIndex, rows_.getSize()) ;
}

return rows_[aRowIndex][this->getIndexOfColumnWithName(aColumnName)] ;

}

std::ostream& operator << ( std::ostream& anOutputStream,
const Table& aTable )
{
Expand Down Expand Up @@ -200,6 +213,18 @@ bool Table::isEmpty ( )
return rows_.isEmpty() ;
}

bool Table::hasColumnWithName ( const String& aColumnName ) const
{

if (aColumnName.isEmpty())
{
throw library::core::error::runtime::Undefined("Column name") ;
}

return header_.contains(aColumnName) ;

}

Size Table::getRowCount ( ) const
{
return rows_.getSize() ;
Expand All @@ -210,6 +235,23 @@ Size Table::getColumnCount ( )
return header_.getSize() ;
}

Index Table::getIndexOfColumnWithName ( const String& aColumnName ) const
{

if (aColumnName.isEmpty())
{
throw library::core::error::runtime::Undefined("Column name") ;
}

if (!header_.contains(aColumnName)) // Double query... should be optimized
{
throw library::core::error::RuntimeError("Table does not have any column with name [{}].", aColumnName) ;
}

return header_.getIndexOf(aColumnName) ;

}

void Table::addRow ( const Row& aRow )
{

Expand Down Expand Up @@ -310,7 +352,16 @@ Table Table::LoadCsv (

for (const auto& columnName : document.GetColumnNames())
{
header.add(columnName) ;

if ((columnName.front() == '"') && (columnName.back() == '"'))
{
header.add(columnName.substr(1, columnName.length() - 2)) ;
}
else
{
header.add(columnName) ;
}

}

}
Expand Down
13 changes: 13 additions & 0 deletions src/Library/Core/Containers/Table/Row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Library/Core/Containers/Table/Row.hpp>
#include <Library/Core/Containers/Table.hpp>
#include <Library/Core/Error.hpp>
#include <Library/Core/Utilities.hpp>

Expand Down Expand Up @@ -108,6 +109,18 @@ const Cell& Row::operator [] (

}

const Cell& Row::operator [] ( const String& aColumnName ) const
{

if (tablePtr_ == nullptr)
{
throw library::core::error::RuntimeError("No associated table.") ;
}

return (*this)[tablePtr_->getIndexOfColumnWithName(aColumnName)] ;

}

bool Row::isEmpty ( ) const
{
return cells_.isEmpty() ;
Expand Down
16 changes: 14 additions & 2 deletions src/Library/Core/Types/Real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,16 @@ types::String Real::toString (

if (this->isInteger())
{
return boost::lexical_cast<std::string>(value_) + ".0" ;

types::String realString = boost::lexical_cast<std::string>(value_) ;

if (realString.find('e') == std::string::npos)
{
realString += ".0" ;
}

return realString ;

}

// types::String realString = std::to_string(value_) ;
Expand All @@ -769,7 +778,10 @@ types::String Real::toString (

// types::String realString = stringStream.str() ;

realString.erase(realString.find_last_not_of('0') + 1, std::string::npos) ; // Remove trailing zeros if any
if (realString.find('e') == std::string::npos)
{
realString.erase(realString.find_last_not_of('0') + 1, std::string::npos) ; // Remove trailing zeros if any
}

return realString ;

Expand Down
Loading

0 comments on commit 6c489b1

Please sign in to comment.