Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
Archive.cpp
1 /*===-- serialbox-c/Archive.cpp -----------------------------------------------------*- C++ -*-===*\
2  *
3  * S E R I A L B O X
4  *
5  * This file is distributed under terms of BSD license.
6  * See LICENSE.txt for more information
7  *
8  *===------------------------------------------------------------------------------------------===//
9  *
10  *! \file
11  *! This file contains the C Interface to the ArchiveFactory.
12  *
13 \*===------------------------------------------------------------------------------------------===*/
14 
15 #include "serialbox-c/Archive.h"
16 #include "serialbox-c/Utility.h"
18 
19 using namespace serialboxC;
20 
22  serialboxArrayOfString_t* array = NULL;
23  try {
24  const auto archiveVector = serialbox::ArchiveFactory::registeredArchives();
25 
26  array = allocate<serialboxArrayOfString_t>();
27  array->len = (int)archiveVector.size();
28  array->data = allocate<serialboxString_t>(array->len * sizeof(serialboxString_t));
29 
30  for(std::size_t i = 0; i < archiveVector.size(); ++i)
31  array->data[i] = allocateAndCopyString(archiveVector[i]);
32  } catch(std::exception& e) {
33  serialboxFatalError(e.what());
34  }
35  return array;
36 }
37 
38 char* serialboxArchiveGetArchiveFromExtension(const char* filename) {
39  char* archive = NULL;
40  try {
41  archive = allocateAndCopyString(serialbox::ArchiveFactory::archiveFromExtension(filename));
42  } catch(std::exception& e) {
43  serialboxFatalError(e.what());
44  }
45  return archive;
46 }
static std::string archiveFromExtension(std::string filename)
Deduce the name of the archive according to the extension of the filename
static std::vector< std::string > registeredArchives()
Get a vector of strings of the registered archives.
Array of strings.
Definition: Array.h:80
serialboxArrayOfString_t * serialboxArchiveGetRegisteredArchives(void)
Get an array of C-strings of all registered archives.
Definition: Archive.cpp:21
SERIALBOX_API typedef char * serialboxString_t
String type of serialbox.
Definition: Type.h:66
serialbox::Exception exception
Exception class which stores a human-readable error description.
Definition: Exception.h:33
void serialboxFatalError(const char *reason)
Report a fatal error.
char * serialboxArchiveGetArchiveFromExtension(const char *filename)
Deduce the name of the archive according to the extension of the filename
Definition: Archive.cpp:38