a4z avatar a4z committed 2878c63

start rearrange a view things for upcomming changes

Comments (0)

Files changed (8)

        
     src/cli/report.hpp
     src/cli/report.cpp
+    
+    src/cli/report_sync.hpp
+    src/cli/report_sync.cpp
+    
+    src/cli/report_utils.hpp
+    src/cli/report_utils.cpp    
 
     src/cli/lookup_fileinpackages.hpp
     src/cli/lookup_fileinpackages.cpp

src/cli/appcli.cpp

 #include "lookup_fileinpackages.hpp"
 // and that is this one.. TODO continue refactoring
 #include "report.hpp"
+#include "report_sync.hpp"
 
 #include "featurex.hpp"
 

src/cli/report.cpp

 
 
 #include "report.hpp"
+#include "report_utils.hpp"
 
 #include <sbbdep/log.hpp>
 #include <sbbdep/pkgname.hpp>
 namespace sbbdep {
 namespace cli{
 
-
-
 //--------------------------------------------------------------------------------------------------
 
-
-void printSyncReport(Cache::SyncData syncdata)
-{
-  using StringSet = std::set<std::string> ; //make it sortd
-
-  StringSet deleted, reinstalled, installed, upgraded;
-
-
-  // take removed, than check inserted, if inserted is also in deleted, its an update
-  deleted.insert(syncdata.removed.begin(),syncdata.removed.end() );
-  // so make all inserted to deleted,
-  // take all installed and search if deleted,
-  // if found , remove from deleted and add to upgraded, else it is inserted
-
-  for(auto& val : syncdata.installed)
-    {   // need package name, if the name is in removed and in installed, than
-      PkgName pkgname(val);
-      auto compair = [&pkgname](const std::string& fullname)->bool
-        {
-          return pkgname.Name() == PkgName(fullname).Name();
-        };
-
-      auto isdeleted = std::find_if(deleted.begin(), deleted.end(), compair);
-      if( isdeleted == deleted.end() )
-        {
-          installed.insert(val);
-        }
-      else
-        {
-          PkgName delname(*isdeleted);
-          std::string updateinfo = val +
-              "  (was " + delname.FullName().substr( delname.Name().size()+1 ) +")";
-          upgraded.insert(updateinfo);
-          deleted.erase(isdeleted);
-        }
-
-    }
-
-  // finally transfer the re installed and then print all
-  reinstalled.insert(syncdata.reinstalled.begin(), syncdata.reinstalled.end());
-
-
-  if(not deleted.empty()
-      or not upgraded.empty()
-      or not installed.empty()
-      or not reinstalled.empty())
-    LogInfo()    << "\n---synchronisation summary:\n" ;
-
-
-  for(auto& val : deleted) LogInfo()    << "deleted: " << val << std::endl;
-  for(auto& val : upgraded) LogInfo()   << "upgraded: " << val  << std::endl;
-  for(auto& val : installed) LogInfo()  << "installed: " << val  << std::endl;
-  for(auto& val : reinstalled) LogInfo()<< "reinstalled: " << val  << std::endl;
-
-  LogInfo() << "\n";
-}
-
-//--------------------------------------------------------------------------------------------------
-
-
 namespace
 {
-
-class ReportSet : public a4sqlt3::Dataset
-{
-public:
-  ReportSet(const std::vector<std::string> fieldnames)
-  {
-    for(std::size_t i = 0; i < fieldnames.size(); ++i)
-        _namemap.insert( NameMap::value_type(fieldnames[i], i) ) ;
-  }
-
-  void merge( const a4sqlt3::Dataset& other )
-  {
-    a4sqlt3::Dataset::merge(other) ;
-  }
-
-  void addFields(a4sqlt3::DbValueList fields)
-  {
-    if( fields.size() != _namemap.size() )
-      throw "TODO"; //TODO
-
-    _rows.emplace_back(fields);
-  }
-
-} ;
-
-
-
-auto no_conversion = [](const std::string& val) -> std::string { return val;};
-
-template<typename T>
-std::string joinToString(T container,  const std::string join,
-    std::function<std::string(const std::string&)> converter = no_conversion )
-{
-
-  std::string retval;
-
-  if( container.empty() )
-    return retval;
-
-  auto pos = container.begin();
-  retval+=converter(*pos);
-
-  while( ++pos != container.end())
-    {
-      retval += join  + converter (*pos) ;
-    }
-
-  return retval;
-
+  using NotFoundMap = std::map<std::string, utils::StringSet>; // from file, so names
 }
 
-using StringVec = std::vector<std::string>;
-using StringSet = std::set<std::string>;
-using NotFoundMap = std::map<std::string, StringSet>; // from file, so names
 
-template<typename T>
-StringSet getKeySet(const T& keyvalmap){
-  StringSet retval;
-  for(auto val: keyvalmap) retval.insert(val.first);
-  return retval;
-}
-
-
-
-
-struct ReportElement{
-
-  using Node =  std::map< std::string, ReportElement >  ;
-
-  Node node ;
-
-  ReportElement() = default;
-
-  ReportElement( std::string s, ReportElement e ) : node {{s,e}}
-  {
-  }
-
-  void add(StringVec path)
-  {
-    if(not path.empty())
-      node[*(path.begin())].add( StringVec(  ++(path.begin()), path.end() ) ) ;
-  }
-
-};
-
-
-struct ReportTree
-{
-  ReportElement::Node node ;
-
-  void add(StringVec path)
-  {
-    if(not path.empty())
-      node[*(path.begin())].add( StringVec(  ++(path.begin()), path.end() ) ) ;
-  }
-};
-
-#ifdef DEBUG
-void printTree(ReportTree& tree)
-{
-
-  std::function<void(ReportElement, int)> printChild = [&printChild]( ReportElement elem , int level ){
-
-    for(auto node: elem.node){
-       for(int i = 0; i < level; ++i)
-            std::cout << " " ;
-
-      LogDebug() << node.first << "\n";
-      printChild(node.second, level+2);
-    }
-
-  } ;
-
-  for( auto elem : tree.node )
-  {
-      LogDebug() << elem.first << std::endl;
-    printChild(elem.second, 2) ;
-  }
-}
-#endif // DEBUG
-//--------------------------------------------------------------------------------------------------
-
-
-bool isRRunPath(const std::string& dirname)
-{
-  using namespace a4sqlt3;
-  SqlCommand* cmd = Cache::getInstance()->DB().getCommand("isRRunpathDirectory");
-  if( cmd == nullptr )
-    {
-      std::string sql = "SELECT count(*)  FROM rrunpath WHERE rrunpath.lddir NOT IN "
-          " (SELECT dirname FROM lddirs UNION SELECT dirname FROM ldlnkdirs) "
-          " AND rrunpath.lddir = ? ;" ;
-
-      cmd = Cache::getInstance()->DB().createStoredCommand(
-          "isRRunpathDirectory" ,  sql );
-    }
-
-  cmd->Parameters().Nr(1).set(dirname);
-
-  Dataset ds;
-  Cache::getInstance()->DB().Execute(cmd, ds);
-  return ds.getField(0).getInt64() > 0 ;
-
-}
-//--------------------------------------------------------------------------------------------------
-
-bool isLinkPath(const std::string& dirname)
-{
-  using namespace a4sqlt3;
-  SqlCommand* cmd = Cache::getInstance()->DB().getCommand("isLinkPathDirectory");
-  if( cmd == nullptr )
-    {
-      std::string sql =" SELECT count(*) FROM "
-         " (SELECT dirname FROM lddirs WHERE dirname = ? "
-            " UNION SELECT dirname FROM ldlnkdirs WHERE dirname = ?) ";
-
-      cmd = Cache::getInstance()->DB().createStoredCommand(
-          "isLinkPathDirectory" ,  sql );
-    }
-
-  cmd->Parameters().setValues( {DbValue(dirname), DbValue(dirname)} ) ;
-
-  Dataset ds;
-  Cache::getInstance()->DB().Execute(cmd, ds);
-  return ds.getField(0).getInt64() > 0 ;
-
-}
-//--------------------------------------------------------------------------------------------------
 
 a4sqlt3::Dataset
 getPkgsOfFile(const PathName& fname)
 }
 
 
-} // ano ns
 //--------------------------------------------------------------------------------------------------
 
-ReportSet elfdeps(const PathName& fromfile, const ElfFile::StringVec& needed,
+utils::ReportSet elfdeps(const PathName& fromfile, const ElfFile::StringVec& needed,
     int arch, const ElfFile::StringVec& rrnupaths)
 {
 
   };
   // TODO , check len  needed or sql , there is are SQLite limits
 
-  std::string insonames = joinToString(needed, ",", quote);
+  std::string insonames = utils::joinToString(needed, ",", quote);
   std::string archstr = std::to_string( arch );
   std::string unionrunpath;
 
   if(not rrnupaths.empty())
     {
-      std::string inrunpath = joinToString(rrnupaths , ",", quoterpath);
+      std::string inrunpath = utils::joinToString(rrnupaths , ",", quoterpath);
       unionrunpath = " UNION SELECT lddir FROM rrunpath WHERE lddir IN (" + inrunpath + ") ";
     }
 
   sql+= " );" ;
 
 
-  ReportSet ds{{}} ;
+  utils::ReportSet ds{{}} ;
   Cache::getInstance()->DB().Execute(sql, ds) ;
   return ds;
 
 }
 //--------------------------------------------------------------------------------------------------
 
-std::tuple<ReportSet, NotFoundMap> // ds(pkgname, filename , soname) and NotFound
+std::tuple<utils::ReportSet, NotFoundMap> // ds(pkgname, filename , soname) and NotFound
 getRequiredInfosLDD(const Pkg& pkg)
 {
   //lot of redundant code with getRequiredInfos but care later if this works
   using namespace a4sqlt3;
 
-  StringSet known_needed;
-  using StringMap = std::map<std::string, std::string> ;
+  utils::StringSet known_needed;
+
 
   NotFoundMap not_found;
 
-  ReportSet rs {{ "pkgname", "filename", "soname" , "requiredby" } };
+  utils::ReportSet rs {{ "pkgname", "filename", "soname" , "requiredby" } };
 
   for(const ElfFile& elf : pkg.getDynLinked())
     {
 
-      StringVec needed = elf.getNeeded();
+      utils::StringVec needed = elf.getNeeded();
 
       // but already looked up to the end
       auto knownbegin = std::remove_if(std::begin(needed), std::end(needed),
         known_needed.insert(knownbegin, needed.end());
 
 
-      StringMap ldmap = getLddMap(elf.getName()) ;
+      utils::StringMap ldmap = getLddMap(elf.getName()) ;
 
-      StringSet rem_so; // for delete an insert as problems
+      utils::StringSet rem_so; // for delete an insert as problems
       for(auto so_needed : ldmap)
         { // is 'not found', but search for on "/"
           if( so_needed.second.find("/") == std::string::npos )
       if(ldmap.empty())
         continue;
 
-      ReportSet elfds {{ "pkgname", "filename", "soname" , "requiredby" } };
+      utils::ReportSet elfds {{ "pkgname", "filename", "soname" , "requiredby" } };
 
 
       for(auto so_needed : ldmap)
 }
 
 
-std::tuple<ReportSet, NotFoundMap> // ds(pkgname, filename , soname) and NotFound
+std::tuple<utils::ReportSet, NotFoundMap> // ds(pkgname, filename , soname) and NotFound
 getRequiredInfos(const Pkg& pkg)
 {
 
   using namespace a4sqlt3;
 
-  StringSet known_needed;
+  utils::StringSet known_needed;
 
   NotFoundMap not_found;
 
-  ReportSet rs {{ "pkgname", "filename", "soname" , "requiredby" } };
+  utils::ReportSet rs {{ "pkgname", "filename", "soname" , "requiredby" } };
 
   for(const ElfFile& elf : pkg.getDynLinked())
     {
 
-      StringVec needed = elf.getNeeded();
+      utils::StringVec needed = elf.getNeeded();
 
       // but already looked up to the end
       auto knownbegin = std::remove_if(std::begin(needed), std::end(needed),
 
       // if ldd option, than here the branch
 
-      ReportSet ds = elfdeps(elf.getName(), needed, elf.getArch(), elf.getRRunPaths());
+      utils::ReportSet ds = elfdeps(elf.getName(), needed, elf.getArch(), elf.getRRunPaths());
       // pkgs.fullname as pkgname,  dynlinked.filename , dynlinked.soname
 
       // move found stuff to the end
             });
 
       // if something was not found, it's now at the begin
-      StringSet notFounds;
+      utils::StringSet notFounds;
       notFounds.insert(needed.begin(), notfound_end);
       if(not notFounds.empty())
           not_found.insert(NotFoundMap::value_type(elf.getName().Str(), notFounds));
 
 
 
-
-
 void printRequired( const Pkg& pkg, bool addversion, bool xdl )
 {
 
-  std::tuple<ReportSet, NotFoundMap> requiredinfo = getRequiredInfos(pkg);
-  ReportTree reptree;
+  std::tuple<utils::ReportSet, NotFoundMap> requiredinfo = getRequiredInfos(pkg);
+  utils::ReportTree reptree;
 
   //pkgname,  filename , soname
-  ReportSet& rs = std::get<0>(requiredinfo) ;
+  utils::ReportSet& rs = std::get<0>(requiredinfo) ;
   NotFoundMap& notFounds = std::get<1>(requiredinfo) ;
 
 
               for(auto file_pkgs : so_files.second.node)
                 {
                   Log::AppMessage() << "    " << file_pkgs.first << "( "
-                      << joinToString(getKeySet(file_pkgs.second.node), " | ", makename) << " )\n";
+                      << utils::joinToString(getKeySet(file_pkgs.second.node), " | ", makename)
+                      << " )\n";
                 }
             }
         }
     }
   else
     {
-      StringSet pkglist;
+      utils::StringSet pkglist;
       std::string ignore_name ;
       if(pkg.getType() == PkgType::Installed)
         ignore_name = pkg.getPath().getBase();
 
       for(auto so_files: reptree.node) // filename so, just what the pkgs...
         {
-          StringSet pkgsofso;
+          utils::StringSet pkgsofso;
           for(auto file_pkgs : so_files.second.node )
             {
               if(not ignore_name.empty() &&
             }
 
           if(not pkgsofso.empty())
-            pkglist.insert( joinToString(pkgsofso, " | ", makename ) ) ;
+            pkglist.insert( utils::joinToString(pkgsofso, " | ", makename ) ) ;
         }
 
-      Log::AppMessage() << joinToString(pkglist, addversion ? "\n" : ", " ) ;
+      Log::AppMessage() << utils::joinToString(pkglist, addversion ? "\n" : ", " ) ;
 
     }
     Log::AppMessage() << std::endl;
         Log::AppMessage() << std::endl;
         Log::AppMessage() << "sonames not found via standard paths: \n" ;
 
-        for(auto val : notFounds)
-            Log::AppMessage() << " for " << val.first << ": "<<joinToString(val.second, ", ") << "\n" ;
+        for(auto val : notFounds){
+            Log::AppMessage() << " for " << val.first << ": "<<utils::joinToString(val.second, ", ")
+            << "\n" ;
+        }
 
         Log::AppMessage() << "this does not necessarily mean there is a problem\n";
         Log::AppMessage() << "the application can either have its own environment or the soname is resolved via a link name \n" ;
 void printWhoNeed( const Pkg& pkg, bool addversion, bool xdl )
 {
 
-  ReportSet rs {{ "pkg", "filename" , "soname" , "fromfile"  } };
+  utils::ReportSet rs {{ "pkg", "filename" , "soname" , "fromfile"  } };
 
 
   if(pkg.getType() == PkgType::BinLib  )
 
   if(xdl)
     {
-      ReportTree reptree;
+      utils::ReportTree reptree;
       for(auto& row : rs )
         {
           reptree.add( { row.getField(3).getString() + " (" + row.getField(2).getString() +")",
 
         }
 
-      std::function<void(ReportElement, int)> printChild = [&printChild]( ReportElement elem , int level ){
+      std::function<void(utils::ReportElement, int)> printChild =
+          [&printChild]( utils::ReportElement elem , int level ){
         for(auto node: elem.node){
            for(int i = 0; i < level; ++i)
              Log::AppMessage() << " " ;
     }
   else
     {
-      StringSet pkgnames ;
+      utils::StringSet pkgnames ;
       for(auto& row : rs )
         {
           pkgnames.insert(addversion ?
               row.getField(0).getString() : PkgName(row.getField(0).getString()).Name() ) ;
         }
 
-      Log::AppMessage()<< joinToString( pkgnames, addversion ? "\n": ", " ) << std::endl ;
+      Log::AppMessage()<< utils::joinToString( pkgnames, addversion ? "\n": ", " ) << std::endl ;
     }
 
 

src/cli/report.hpp

 #ifndef SBBDEP_CLI_REPORT_HPP_
 #define SBBDEP_CLI_REPORT_HPP_
 
-#include <sbbdep/cache.hpp>
-
 
 
 namespace sbbdep{
 namespace cli{
 
 
-void printSyncReport(Cache::SyncData syncdata) ;
-
-
 
 
 void printRequired( const Pkg& pkg, bool addversion, bool xdl ) ;

src/cli/report_sync.cpp

+/*
+--------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+-----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+
+#include "report_sync.hpp"
+
+#include <sbbdep/log.hpp>
+#include <sbbdep/pkgname.hpp>
+
+
+#include <set>
+#include <algorithm>
+
+namespace sbbdep {
+namespace cli{
+
+
+
+//--------------------------------------------------------------------------------------------------
+
+
+void printSyncReport(Cache::SyncData syncdata)
+{
+  using StringSet = std::set<std::string> ; //make it sortd
+
+  StringSet deleted, reinstalled, installed, upgraded;
+
+
+  // take removed, than check inserted, if inserted is also in deleted, its an update
+  deleted.insert(syncdata.removed.begin(),syncdata.removed.end() );
+  // so make all inserted to deleted,
+  // take all installed and search if deleted,
+  // if found , remove from deleted and add to upgraded, else it is inserted
+
+  for(auto& val : syncdata.installed)
+    {   // need package name, if the name is in removed and in installed, than
+      PkgName pkgname(val);
+      auto compair = [&pkgname](const std::string& fullname)->bool
+        {
+          return pkgname.Name() == PkgName(fullname).Name();
+        };
+
+      auto isdeleted = std::find_if(deleted.begin(), deleted.end(), compair);
+      if( isdeleted == deleted.end() )
+        {
+          installed.insert(val);
+        }
+      else
+        {
+          PkgName delname(*isdeleted);
+          std::string updateinfo = val +
+              "  (was " + delname.FullName().substr( delname.Name().size()+1 ) +")";
+          upgraded.insert(updateinfo);
+          deleted.erase(isdeleted);
+        }
+
+    }
+
+  // finally transfer the re installed and then print all
+  reinstalled.insert(syncdata.reinstalled.begin(), syncdata.reinstalled.end());
+
+
+  if(not deleted.empty()
+      or not upgraded.empty()
+      or not installed.empty()
+      or not reinstalled.empty())
+    LogInfo()    << "\n---synchronisation summary:\n" ;
+
+
+  for(auto& val : deleted) LogInfo()    << "deleted: " << val << std::endl;
+  for(auto& val : upgraded) LogInfo()   << "upgraded: " << val  << std::endl;
+  for(auto& val : installed) LogInfo()  << "installed: " << val  << std::endl;
+  for(auto& val : reinstalled) LogInfo()<< "reinstalled: " << val  << std::endl;
+
+  LogInfo() << "\n";
+}
+
+//--------------------------------------------------------------------------------------------------
+
+
+
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+}} // ns

src/cli/report_sync.hpp

+/*
+--------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+-----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+
+#ifndef SBBDEP_CLI_REPORT_SYNC_HPP_
+#define SBBDEP_CLI_REPORT_SYNC_HPP_
+
+#include <sbbdep/cache.hpp>
+
+
+
+namespace sbbdep{
+
+namespace cli{
+
+
+void printSyncReport(Cache::SyncData syncdata) ;
+
+
+
+}}
+
+
+#endif

src/cli/report_utils.cpp

+/*
+--------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+-----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+
+#include "report_utils.hpp"
+
+#include <sbbdep/log.hpp>
+#include <sbbdep/cache.hpp>
+
+#include <a4sqlt3/sqlcommand.hpp>
+
+
+namespace sbbdep {
+namespace cli{
+namespace utils{
+
+
+//--------------------------------------------------------------------------------------------------
+ReportSet::ReportSet(const std::vector<std::string> fieldnames)
+{
+  for(std::size_t i = 0; i < fieldnames.size(); ++i)
+      _namemap.insert( NameMap::value_type(fieldnames[i], i) ) ;
+}
+
+void
+ReportSet::addFields(a4sqlt3::DbValueList fields)
+{
+  if( fields.size() != _namemap.size() )
+    throw "TODO"; //TODO
+
+  _rows.emplace_back(fields);
+}
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+
+
+
+
+
+ReportElement::ReportElement( std::string s, ReportElement e ) : node {{s,e}}
+{
+}
+
+void
+ReportElement::add(StringVec path)
+{
+  if(not path.empty())
+    node[*(path.begin())].add( StringVec(  ++(path.begin()), path.end() ) ) ;
+}
+
+
+
+void
+ReportTree::add(StringVec path)
+{
+  if(not path.empty())
+    node[*(path.begin())].add( StringVec(  ++(path.begin()), path.end() ) ) ;
+}
+
+
+
+#ifdef DEBUG
+void printTree(ReportTree& tree)
+{
+
+  std::function<void(ReportElement, int)> printChild = [&printChild]( ReportElement elem , int level ){
+
+    for(auto node: elem.node){
+       for(int i = 0; i < level; ++i)
+            LogInfo() << " " ;
+
+      LogDebug() << node.first << "\n";
+      printChild(node.second, level+2);
+    }
+
+  } ;
+
+  for( auto elem : tree.node )
+  {
+      LogDebug() << elem.first << std::endl;
+    printChild(elem.second, 2) ;
+  }
+}
+#endif // DEBUG
+//--------------------------------------------------------------------------------------------------
+
+
+bool isRRunPath(const std::string& dirname)
+{
+  using namespace a4sqlt3;
+  SqlCommand* cmd = Cache::getInstance()->DB().getCommand("isRRunpathDirectory");
+  if( cmd == nullptr )
+    {
+      std::string sql = "SELECT count(*)  FROM rrunpath WHERE rrunpath.lddir NOT IN "
+          " (SELECT dirname FROM lddirs UNION SELECT dirname FROM ldlnkdirs) "
+          " AND rrunpath.lddir = ? ;" ;
+
+      cmd = Cache::getInstance()->DB().createStoredCommand(
+          "isRRunpathDirectory" ,  sql );
+    }
+
+  cmd->Parameters().Nr(1).set(dirname);
+
+  Dataset ds;
+  Cache::getInstance()->DB().Execute(cmd, ds);
+  return ds.getField(0).getInt64() > 0 ;
+
+}
+//--------------------------------------------------------------------------------------------------
+
+bool isLinkPath(const std::string& dirname)
+{
+  using namespace a4sqlt3;
+  SqlCommand* cmd = Cache::getInstance()->DB().getCommand("isLinkPathDirectory");
+  if( cmd == nullptr )
+    {
+      std::string sql =" SELECT count(*) FROM "
+         " (SELECT dirname FROM lddirs WHERE dirname = ? "
+            " UNION SELECT dirname FROM ldlnkdirs WHERE dirname = ?) ";
+
+      cmd = Cache::getInstance()->DB().createStoredCommand(
+          "isLinkPathDirectory" ,  sql );
+    }
+
+  cmd->Parameters().setValues( {DbValue(dirname), DbValue(dirname)} ) ;
+
+  Dataset ds;
+  Cache::getInstance()->DB().Execute(cmd, ds);
+  return ds.getField(0).getInt64() > 0 ;
+
+}
+//--------------------------------------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+}
+}} // ns

src/cli/report_utils.hpp

+/*
+--------------Copyright (c) 2010-2013 H a r a l d  A c h i t z---------------
+-----------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+
+#ifndef SBBDEP_CLI_REPORT_UTILS_HPP_
+#define SBBDEP_CLI_REPORT_UTILS_HPP_
+
+
+#include <a4sqlt3/dataset.hpp>
+
+#include <string>
+#include <vector>
+#include <set>
+#include <map>
+
+
+namespace sbbdep{
+namespace cli{
+namespace utils{ // ??
+
+
+using StringVec = std::vector<std::string>;
+using StringSet = std::set<std::string>;
+using StringMap = std::map<std::string, std::string>;
+
+
+class ReportSet : public a4sqlt3::Dataset
+{
+public:
+  ReportSet(const std::vector<std::string> fieldnames);
+
+  void addFields(a4sqlt3::DbValueList fields);
+
+} ;
+//--------------------------------------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------------------------------------
+
+auto no_conversion = [](const std::string& val) -> std::string { return val;};
+
+template<typename T>
+std::string joinToString(T container,  const std::string join,
+    std::function<std::string(const std::string&)> converter = no_conversion )
+{
+
+  std::string retval;
+
+  if( container.empty() )
+    return retval;
+
+  auto pos = container.begin();
+  retval+=converter(*pos);
+
+  while( ++pos != container.end())
+    {
+      retval += join  + converter (*pos) ;
+    }
+
+  return retval;
+
+}
+//--------------------------------------------------------------------------------------------------
+
+template<typename T>
+StringSet getKeySet(const T& keyvalmap){
+  StringSet retval;
+  for(auto val: keyvalmap) retval.insert(val.first);
+  return retval;
+}
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+
+
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+struct ReportElement{
+
+  using Node =  std::map< std::string, ReportElement >  ;
+
+  Node node ;
+
+  ReportElement() = default;
+
+  ReportElement( std::string s, ReportElement e );
+
+  void add(StringVec path);
+
+};
+//--------------------------------------------------------------------------------------------------
+
+
+struct ReportTree
+{
+  ReportElement::Node node ;
+
+  void add(StringVec path) ;
+
+};
+//--------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------
+
+#ifdef DEBUG
+void printTree(ReportTree& tree);
+#endif
+
+
+bool isRRunPath(const std::string& dirname);
+bool isLinkPath(const std::string& dirname);
+
+
+
+
+} // utils
+}}
+
+
+#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.