Browse Source

- separate files in subdirs

- fixed header file problems using different #ifdef to avoid multiple includes
- added src/test/test_bag.cpp
master
parent
commit
5860cd89d8
  1. 19
      src/CMakeLists.txt
  2. 18
      src/include/bag.hpp
  3. 0
      src/include/bagmetadata.hpp
  4. 0
      src/include/fetchfile.hpp
  5. 0
      src/include/manifest.hpp
  6. 0
      src/include/othertags.hpp
  7. 21
      src/include/payload.hpp
  8. 0
      src/include/tagmanifest.hpp
  9. 18
      src/lib/load_bag.cpp
  10. 0
      src/lib/make_bag.cpp
  11. 0
      src/lib/modify_bag.cpp
  12. 51
      src/lib/payload.cpp
  13. 0
      src/lib/store_bag.cpp
  14. 0
      src/lib/validate_bag.cpp
  15. 6
      src/load_bag.cpp
  16. 52
      src/payload.cpp
  17. 22
      src/payload.hpp
  18. 11
      src/test/test_bag.cpp
  19. 18
      src/test/test_payload.cpp
  20. 15
      src/test_payload.cpp

19
src/CMakeLists.txt

@ -1,7 +1,8 @@
cmake_minimum_required (VERSION 2.6)
project (libcbag)
#include_directories("${PROJECT_SOURCE_DIR}/headers")
#include_directories("${PROJECT_SOURCE_DIR}/validate_icc")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/lib/")
include_directories("${PROJECT_SOURCE_DIR}/")
include (CheckSymbolExists)
include (CheckFunctionExists)
@ -12,13 +13,17 @@ message(status "** Boost Libraries: ${Boost_LIBRARIES}")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
file( GLOB libcbag_SOURCES
"${PROJECT_SOURCE_DIR}/*.cpp"
file( GLOB libcbag_SOURCES_LIB
"${PROJECT_SOURCE_DIR}/lib/*.cpp"
)
add_library(libcbag ${libcbag_SOURCES} )
add_library(libcbag ${libcbag_SOURCES_LIB} )
target_include_directories(libcbag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(test_payload test_payload.cpp ${libcbag_SOURCES})
TARGET_LINK_LIBRARIES(test_payload ${Boost_LIBRARIES})
add_executable(test_payload ${PROJECT_SOURCE_DIR}/test/test_payload.cpp ${libcbag_SOURCES_lib})
TARGET_LINK_LIBRARIES(test_payload ${Boost_LIBRARIES} libcbag)
add_executable(test_bag ${PROJECT_SOURCE_DIR}/test/test_bag.cpp ${libcbag_SOURCES_lib})
TARGET_LINK_LIBRARIES(test_bag ${Boost_LIBRARIES} libcbag)

18
src/bag.hpp → src/include/bag.hpp

@ -11,18 +11,18 @@
using namespace std;
class bag {
class Bag {
private:
string base_dir; // from where the bag was loaded, optional
class payload;
class manifest; // TODO: list of manifests
class tagmanifest; // TODO: list of tag manifests, optional
class bagmetadata;
class fetchfile;
class othertags; //TODO: optional
class Payload *payload_p;;
class Manifest *manifest_p; // TODO: list of manifests
class Tagmanifest *tagmanifest_p; // TODO: list of tag manifests, optional
class Bagmetadata *bagmetadata_p;
class Fetchfile *fetchfile_p;
class Othertags *othertags_p; //TODO: optional
public:
bag();
bag( string dfname);
Bag();
Bag(string dfname);
bool store( string dfname);
bool validate();
};

0
src/bagmetadata.hpp → src/include/bagmetadata.hpp

0
src/fetchfile.hpp → src/include/fetchfile.hpp

0
src/manifest.hpp → src/include/manifest.hpp

0
src/othertags.hpp → src/include/othertags.hpp

21
src/include/payload.hpp

@ -0,0 +1,21 @@
#ifndef LIBCBAG_PAYLOAD
#define LIBCBAG_PAYLOAD
#include <string>
#include <list>
#include <boost/filesystem.hpp>
#include <list>
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
class Payload{
private:
string basedir;
void scan_dir_recursively( fs::path directory, list<fs::path> &paths );
public:
Payload( string basedir );
list<string> get_all_relative_paths();
list<string> get_all_absolute_paths();
};
#endif
// vim: set tabstop=4

0
src/tagmanifest.hpp → src/include/tagmanifest.hpp

18
src/lib/load_bag.cpp

@ -0,0 +1,18 @@
#include "bag.hpp"
#include "payload.hpp"
#include <iostream>
#include <string>
Bag::Bag( string dfname ) {
cout << "load constructor (" << dfname << ")" << endl;
string payloaddir = dfname + "src/";
Bag::payload_p = new Payload( payloaddir ) ;
list<string> files = Bag::payload_p->get_all_relative_paths();
list<string>::iterator i;
for (i=files.begin(); i!=files.end(); i++) {
cout << "file/dir (rel):" << (*i) << endl;
//cout << "file/dir (abs):" << (*i) << endl;
}
}
// vim: set tabstop=4

0
src/make_bag.cpp → src/lib/make_bag.cpp

0
src/modify_bag.cpp → src/lib/modify_bag.cpp

51
src/lib/payload.cpp

@ -0,0 +1,51 @@
#include "payload.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
#include <list>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
Payload::Payload( string basedir ) {
fs::path p{ basedir };
fs::file_status s = fs::status( p );
cout << "basedir "<< p.string() << endl;
cout << "is dir: "<< fs::is_directory( s) << endl;
cout << "exists: "<< fs::exists(s) << endl;
this->basedir = basedir;
};
void Payload::scan_dir_recursively( fs::path directory, list<fs::path> &paths) {
fs::recursive_directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
fs::path subdir = iter->path();
paths.push_back( subdir );
}
}
list<string> Payload::get_all_relative_paths() {
list<fs::path> paths;
list<string> strpaths;
fs::path directory(this->basedir);
Payload::scan_dir_recursively( directory, paths);
list<fs::path>::iterator i;
for (i=paths.begin(); i!= paths.end(); i++) {
strpaths.push_back( (*i).relative_path().string() );
}
return strpaths;
}
list<string> Payload::get_all_absolute_paths() {
list<fs::path> paths;
list<string> strpaths;
fs::path directory(this->basedir);
Payload::scan_dir_recursively( directory, paths);
list<fs::path>::iterator i;
for (i=paths.begin(); i!= paths.end(); i++) {
strpaths.push_back( (*i).string() );
}
return strpaths;
}
// vim: set tabstop=4

0
src/store_bag.cpp → src/lib/store_bag.cpp

0
src/validate_bag.cpp → src/lib/validate_bag.cpp

6
src/load_bag.cpp

@ -1,6 +0,0 @@
#include "bag.hpp"
#include <iostream>
bag::bag( string dfname ) {
cout << "load constructor (" << dfname << endl;
}

52
src/payload.cpp

@ -1,52 +0,0 @@
#include "payload.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
#include <list>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
payload::payload( string basedir ) {
fs::path p{ basedir };
fs::file_status s = fs::status( p );
cout << "basedir "<< p.string() << endl;
cout << "is dir: "<< fs::is_directory( s) << endl;
cout << "exists: "<< fs::exists(s) << endl;
this->basedir = basedir;
};
void payload::scan_dir_recursively( fs::path directory, list<fs::path> &paths) {
fs::directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
fs::path subdir = iter->path();
paths.push_back( subdir );
// dive deeper
payload::scan_dir_recursively( subdir, paths );
}
}
list<string> payload::get_all_relative_paths() {
list<fs::path> paths;
list<string> strpaths;
fs::path directory(this->basedir);
payload::scan_dir_recursively( directory, paths);
list<fs::path>::iterator i;
for (i=paths.begin(); i!= paths.end(); i++) {
strpaths.push_back( (*i).relative_path().string() );
}
return strpaths;
}
list<string> payload::get_all_absolute_paths() {
list<string> paths;
fs::path directory(this->basedir);
fs::directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
paths.push_back( iter->path().string() );
}
return paths;
}

22
src/payload.hpp

@ -1,22 +0,0 @@
#ifndef LIBCBAG
#define LIBCBAG
#include <string>
#include <list>
#include <boost/filesystem.hpp>
#include <list>
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
class payload{
private:
string basedir;
void scan_dir_recursively( fs::path directory, list<fs::path> &paths );
public:
payload( string basedir );
list<string> get_all_relative_paths();
list<string> get_all_absolute_paths();
};
#endif
// vim: set tabstop=4

11
src/test/test_bag.cpp

@ -0,0 +1,11 @@
#include "bag.hpp"
using namespace std;
#include <iostream>
int main() {
Bag bag( "../" );
return 0;
}
// vim: set tabstop=4

18
src/test/test_payload.cpp

@ -0,0 +1,18 @@
#include "payload.hpp"
using namespace std;
#include <iostream>
int main() {
Payload p( "./CMakeFiles" );
//list<string> files = p.get_all_absolute_paths();
list<string> files = p.get_all_relative_paths();
list<string>::iterator i;
for (i=files.begin(); i!=files.end(); i++) {
cout << "file/dir (rel):" << (*i) << endl;
//cout << "file/dir (abs):" << (*i) << endl;
}
return 0;
}
// vim: set tabstop=4

15
src/test_payload.cpp

@ -1,15 +0,0 @@
#include "payload.hpp"
using namespace std;
#include <iostream>
int main() {
payload p( "/tmp/" );
list<string> files = p.get_all_relative_paths();
list<string>::iterator i;
for (i=files.begin(); i!=files.end(); i++) {
cout << "file/dir (rel):" << (*i) << endl;
}
return 0;
}
Loading…
Cancel
Save