Skip to content
Snippets Groups Projects
Commit 9bafa72e authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny: Committed by Vakhtang Tsulaia
Browse files

Remove obsolete GeoModelCppHelpers package and clean code

parent 22b53872
No related branches found
No related tags found
1 merge request!334Remove obsolete GeoModelCppHelpers package and clean code
Pipeline #7679765 failed
......@@ -10,16 +10,16 @@ namespace GeoStrUtils {
template <class ObjType> std::string chainUp(const std::vector<ObjType>& vector,
const std::string_view glue) {
return chainUp(vector.size(), [&vector](const unsigned int ele)->ObjType {
return chainUp<ObjType>(vector.size(), [&vector](const unsigned int ele)->ObjType {
return vector.at(ele);
}, glue);
}
template <class ObjType> std::string chainUp(unsigned int numEles,
const std::function<ObjType(unsigned int)>& func,
const std::function<ObjType(const unsigned int)>& func,
const std::string_view glue) {
std::stringstream chain{};
for (unsigned int k =0; k < numEles; ++k) {
for (unsigned int k=0; k < numEles; ++k) {
chain<<func(k);
if (k + 1 < numEles)chain<<glue;
}
......
......@@ -10,7 +10,6 @@ add_subdirectory( TFPersistification )
add_subdirectory( GeoModelRead )
add_subdirectory( GeoModelWrite )
add_subdirectory( GeoModelIOHelpers )
add_subdirectory( GeoModelCppHelpers )
# Create and install the version description of the project.
include( CMakePackageConfigHelpers )
......
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
################################################################################
# Package: GeoModelCppHelpers
# author: Riccardo Maria BIANCHI <rbianchi@cern.ch> - 2024 Apr
################################################################################
# Find the header and source files.
file( GLOB SOURCES src/*.cpp )
file( GLOB HEADERS GeoModelCppHelpers/*.h )
# Set up the library.
add_library( GeoModelCppHelpers SHARED ${HEADERS} ${SOURCES} )
# target_link_libraries( GeoModelCppHelpers PUBLIC
# GeoModelHelpers )
# We link those to carry on the needed libs when including GeoModelCppHelpers,
# even if the latter is headers only
target_include_directories( GeoModelCppHelpers PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include> )
source_group( "GeoModelCppHelpers" FILES ${HEADERS} )
source_group( "src" FILES ${SOURCES} )
set_target_properties( GeoModelCppHelpers PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR} )
set_target_properties(GeoModelCppHelpers PROPERTIES LINKER_LANGUAGE CXX)
# Set up custom build flags for the library.
foreach( _flag GEOMODEL_IO_READ_DEBUG GEOMODEL_IO_DEBUG_VERBOSE
GEOMODEL_IO_READ_TIMING )
if( ${${_flag}} )
target_compile_definitions( GeoModelCppHelpers PRIVATE ${_flag}=true )
endif()
endforeach()
# Set up an alias with the same name that you would get by "finding" a pre-built
# version of the library.
add_library( GeoModelIO::GeoModelCppHelpers ALIAS GeoModelCppHelpers )
# Install the library.
install(TARGETS GeoModelCppHelpers
EXPORT ${PROJECT_NAME}-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Runtime
NAMELINK_COMPONENT Development # Requires CMake 3.12
)
install( FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GeoModelCppHelpers
COMPONENT Development )
// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
/*
* This header file provides helper C++ functions used in GeoModel IO code.
*
* Author: Riccardo Maria BIANCHI @ CERN
* Created on: Apr, 2024
*
*/
#ifndef GMCPPHelper_H
#define GMCPPHelper_H
// C++ includes
#include <cstdlib> // EXIT_FAILURE
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <variant>
#include <type_traits>
namespace GeoModelIO {
class CppHelper
{
public:
// dummy constructor
CppHelper(){};
// FIXME: should go to an utility class
static std::string joinVectorStrings(std::vector<std::string> vec,
std::string sep = "")
{
std::string s;
unsigned int ii = 0;
for (const auto &piece : vec)
{
++ii;
if (ii == vec.size())
{
s += (piece);
}
else
{
s += (piece + sep);
}
}
return s;
}
};
} // namespace GeoModelIO
#endif
# GeoModelCppHelpers
This package contains C++ helper functions for IO operations.
......@@ -14,7 +14,7 @@ file( GLOB HEADERS GeoModelDBManager/*.h )
# Set up the library.
add_library( GeoModelDBManager SHARED ${HEADERS} ${SOURCES} )
target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 GeoModelHelpers GeoModelCppHelpers )
target_link_libraries( GeoModelDBManager PRIVATE SQLite::SQLite3 GeoModelHelpers )
target_include_directories( GeoModelDBManager PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
......
......@@ -22,8 +22,6 @@
#include <GeoModelDBManager/GMDBManager.h>
#include "GeoModelCppHelpers/GMCppHelpers.h"
#include "GeoModelHelpers/throwExcept.h"
#include "GeoModelHelpers/StringUtils.h"
......@@ -214,7 +212,7 @@ void GMDBManager::printAllRecords(const std::string& tableName) const {
return;
}
// --- print table column names
std::cout << "- " << GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ")
std::cout << "- " << GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ")
<< std::endl;
// --- print records
std::vector<std::vector<std::string>> records;
......@@ -782,7 +780,7 @@ bool GMDBManager::addListOfRecordsToTable(
// get table columns and format them for query
std::string tableColString =
"(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")";
"(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")";
if (m_debug) std::cout << "tableColString:" << tableColString << std::endl;
unsigned int nRecords = records.size();
......@@ -803,7 +801,7 @@ bool GMDBManager::addListOfRecordsToTable(
// values when inserting them in the table, as we now
// do for the std::variant version!
}
std::string values = GeoModelIO::CppHelper::joinVectorStrings(items, ",");
std::string values = GeoStrUtils::chainUp(items, ",");
sql += " (" + std::to_string(id) + "," + values + ")"; // INT
if (id != nRecords) {
sql += ",";
......@@ -831,7 +829,7 @@ bool GMDBManager::addListOfRecordsToTable(
if (records.size() > 0) {
// get table columns and format them for query
std::string tableColString =
"(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")";
"(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")";
if (m_debug) std::cout << "tableColString:" << tableColString << std::endl;
unsigned int nRecords = records.size();
......@@ -874,7 +872,7 @@ bool GMDBManager::addListOfRecordsToTable(
THROW_EXCEPTION("No std::variant alternative found!");
}
// we build the long string containing all values
std::string values = GeoModelIO::CppHelper::joinVectorStrings(items, ",");
std::string values = GeoStrUtils::chainUp(items, ",");
sql += " (" + std::to_string(id) + "," + values + ")"; // INT
if (id != nRecords) {
sql += ",";
......@@ -893,19 +891,15 @@ bool GMDBManager::addListOfRecordsToTable(
return false;
}
bool GMDBManager::addRecordsToTable(
const std::string tableName,
const DBRowEntry
records)
const DBRowEntry records)
{
if (records.size() > 0) {
// get table columns and format them for query
std::string tableColString =
"(" + GeoModelIO::CppHelper::joinVectorStrings(m_tableNames.at(tableName), ", ") + ")";
if (m_debug)
std::cout << "tableColString:" << tableColString << std::endl;
"(" + GeoStrUtils::chainUp(m_tableNames.at(tableName), ", ") + ")";
if (m_debug) std::cout << "tableColString:" << tableColString << std::endl;
unsigned int nRecords = records.size();
......@@ -918,6 +912,8 @@ bool GMDBManager::addRecordsToTable(
unsigned int id = 0;
// a vector to store string-conversions of values, to build the SQL
// query
// TODO: we should remove this TEXT-conversion
// and we should use prepared statements instead!
std::vector<std::string> items;
// loop over all entries in a row/record
for (const std::variant<int, long, float, double, std::string> &item :
......@@ -968,14 +964,8 @@ bool GMDBManager::addRecordsToTable(
}
items.push_back(endRow);
}
// we build the long string containing all values
std::string values = GeoModelIO::CppHelper::joinVectorStrings(items);
// // TODO: replace CppHelper with global Helpers
// std::string valuesTest = GeoStrUtils::chainUp(items, ",");
// std::cout << "values: " << values << std::endl;
// std::cout << "valuesTest: " << valuesTest << std::endl;
// we build the long SQL string containing all values
std::string values = GeoStrUtils::chainUp<std::string>(items, "");
sql += " " + values + ";";
if (m_debug)
......
......@@ -12,7 +12,7 @@ file( GLOB HEADERS GeoModelRead/*.h GeoModelRead/*.tpp )
# Set up the library.
add_library( GeoModelRead SHARED ${HEADERS} ${SOURCES} )
target_link_libraries( GeoModelRead PUBLIC
GeoModelKernel GeoModelDBManager TFPersistification GeoModelCppHelpers GeoModelHelpers )
GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers )
target_include_directories( GeoModelRead PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ file( GLOB HEADERS GeoModelWrite/*.h )
# Set up the library.
add_library( GeoModelWrite SHARED ${HEADERS} ${SOURCES} )
target_link_libraries( GeoModelWrite PUBLIC
GeoModelKernel GeoModelDBManager TFPersistification GeoModelCppHelpers GeoModelHelpers)
GeoModelKernel GeoModelDBManager TFPersistification GeoModelHelpers)
target_include_directories( GeoModelWrite PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment