diff --git a/bob/io/base/bobskin.cpp b/bob/io/base/bobskin.cpp index 12117c18277fe94087da39c0c82644f26a115766..8a23c6627861bfd6c1f378f464acdc382c23ea32 100644 --- a/bob/io/base/bobskin.cpp +++ b/bob/io/base/bobskin.cpp @@ -5,6 +5,7 @@ * @brief Implementation of our bobskin class */ +#define BOB_IO_BASE_MODULE #include "bobskin.h" #include <stdexcept> diff --git a/bob/io/base/cpp/CodecRegistry.cpp b/bob/io/base/cpp/CodecRegistry.cpp index e3ce5fd5cb13bbc7c758650b86c326c0400d852b..483215e46471d68e80a7ab8003eb2a86b866ef31 100644 --- a/bob/io/base/cpp/CodecRegistry.cpp +++ b/bob/io/base/cpp/CodecRegistry.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include "CodecRegistry.h" diff --git a/bob/io/base/cpp/HDF5Attribute.cpp b/bob/io/base/cpp/HDF5Attribute.cpp index 05d79bc3632d69981d3470606aca65bf2403172f..2d42802a65a7ad51eff3eca6d760f2b62e4cb9ae 100644 --- a/bob/io/base/cpp/HDF5Attribute.cpp +++ b/bob/io/base/cpp/HDF5Attribute.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include <bob.io.base/HDF5Attribute.h> diff --git a/bob/io/base/cpp/HDF5Dataset.cpp b/bob/io/base/cpp/HDF5Dataset.cpp index ac0167cfab9eff2abfa123c497727d49d16e9314..3e4b93d8b1e9b2328702a3f822c1ec2b89b0258c 100644 --- a/bob/io/base/cpp/HDF5Dataset.cpp +++ b/bob/io/base/cpp/HDF5Dataset.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include <boost/format.hpp> diff --git a/bob/io/base/cpp/HDF5File.cpp b/bob/io/base/cpp/HDF5File.cpp index 796e31fe7cfcc6692e97dd0e25ee3a72261dba9d..3f838b48e188937cd0512548db72807e5d1d47fe 100644 --- a/bob/io/base/cpp/HDF5File.cpp +++ b/bob/io/base/cpp/HDF5File.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.io.base/HDF5File.h> #include <boost/format.hpp> diff --git a/bob/io/base/cpp/HDF5Group.cpp b/bob/io/base/cpp/HDF5Group.cpp index 43d2c1af4c77cedc7f9f7ac341ad78e1f18f44dc..486b7ea5e2e3221eec7e353f40a693683c67c1be 100644 --- a/bob/io/base/cpp/HDF5Group.cpp +++ b/bob/io/base/cpp/HDF5Group.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include <boost/make_shared.hpp> diff --git a/bob/io/base/cpp/HDF5Types.cpp b/bob/io/base/cpp/HDF5Types.cpp index 3f1f07d54744e54a3b106c3b39022b99b96233bb..e628d5299bf347f9fe30dce110619a9de5f87a9d 100644 --- a/bob/io/base/cpp/HDF5Types.cpp +++ b/bob/io/base/cpp/HDF5Types.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include <sstream> diff --git a/bob/io/base/cpp/HDF5Utils.cpp b/bob/io/base/cpp/HDF5Utils.cpp index 3cbff40478240d40c581019735c1121403384bd8..f06bd11ba9748e8051e962ef6161324c44ce0685 100644 --- a/bob/io/base/cpp/HDF5Utils.cpp +++ b/bob/io/base/cpp/HDF5Utils.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <bob.core/logging.h> #include <boost/format.hpp> diff --git a/bob/io/base/cpp/blitz_array.cpp b/bob/io/base/cpp/blitz_array.cpp index 0fd283744dbc54caa70ba8dc9c753fd9a282ff3a..4ea4a7c44f1b1906e3f78145e8425145716cf689 100644 --- a/bob/io/base/cpp/blitz_array.cpp +++ b/bob/io/base/cpp/blitz_array.cpp @@ -7,6 +7,7 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#define BOB_IO_BASE_MODULE #include <stdexcept> #include <bob.io.base/blitz_array.h> diff --git a/bob/io/base/file.cpp b/bob/io/base/file.cpp index 321bcadb0c15e6c46ec92061c5c1976e715c0577..3f36c382fc50759d8657ddc43bb17fb7fc1ae45e 100644 --- a/bob/io/base/file.cpp +++ b/bob/io/base/file.cpp @@ -8,6 +8,7 @@ #define BOB_IO_BASE_MODULE #include "bobskin.h" #include <bob.io.base/api.h> +#include <bob.io.base/File.h> #include <numpy/arrayobject.h> #include <bob.blitz/capi.h> #include <bob.blitz/cleanup.h> @@ -118,10 +119,10 @@ static int PyBobIoFile_Init(PyBobIoFileObject* self, PyObject *args, PyObject* k try { if (pretend_extension) { - self->f = BobIo_OpenWithExtension(c_filename, mode, pretend_extension); + self->f = BobIoFile_OpenWithExtension(c_filename, mode, pretend_extension); } else { - self->f = BobIo_Open(c_filename, mode); + self->f = BobIoFile_Open(c_filename, mode); } } catch (std::exception& e) { @@ -493,7 +494,7 @@ Returns the current position of the newly written array.\n\ " ); -PyObject* PyBobIo_TypeInfoAsTuple (const BobIoTypeinfo& ti) { +PyObject* PyBobIo_TypeinfoAsTuple (const BobIoTypeinfo& ti) { if (ti.dtype == NPY_NOTYPE) return 0; @@ -529,7 +530,7 @@ static PyObject* PyBobIoFile_Describe(PyBobIoFileObject* self, PyObject *args, P else info = &self->f->type(); /* Now return type description and tuples with shape and strides */ - return PyBobIo_TypeInfoAsTuple(*info); + return PyBobIo_TypeinfoAsTuple(*info); } PyDoc_STRVAR(s_describe_str, "describe"); diff --git a/bob/io/base/include/bob.io.base/HDF5Dataset.h b/bob/io/base/include/bob.io.base/HDF5Dataset.h index 557241079ca1a289f8ea5d778cb082837ea648a9..9059baba2087be3a64504aed157b4edd47c75a77 100644 --- a/bob/io/base/include/bob.io.base/HDF5Dataset.h +++ b/bob/io/base/include/bob.io.base/HDF5Dataset.h @@ -13,6 +13,7 @@ #include <vector> #include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> #include <blitz/array.h> #include <hdf5.h> diff --git a/bob/io/base/include/bob.io.base/api.h b/bob/io/base/include/bob.io.base/api.h index 9f6551b7c3832a1b6d863ca5b75df955e7c01c62..59b1dbb5eb0e403fc9ec78cefffafdeb9878bc7f 100644 --- a/bob/io/base/include/bob.io.base/api.h +++ b/bob/io/base/include/bob.io.base/api.h @@ -148,10 +148,10 @@ typedef struct { #define BobIoReorder_ColToRow_PROTO (const void*, void*, const BobIoTypeinfo*) #define BobIoReorder_RowToColComplex_RET int -#define BobIoReorder_RowToColComplex_PROTO (const void*, void*, const BobIoTypeinfo*) +#define BobIoReorder_RowToColComplex_PROTO (const void*, void*, void*, const BobIoTypeinfo*) #define BobIoReorder_ColToRowComplex_RET int -#define BobIoReorder_ColToRowComplex_PROTO (const void*, void*, const BobIoTypeinfo*) +#define BobIoReorder_ColToRowComplex_PROTO (const void*, const void*, void*, const BobIoTypeinfo*) /********************************** * Bindings for bob.io.base.File * diff --git a/bob/io/base/include/bob.io.base/utils.h b/bob/io/base/include/bob.io.base/utils.h deleted file mode 100644 index 04931e06c833e9e4e61f4ac55870ab8578b19af8..0000000000000000000000000000000000000000 --- a/bob/io/base/include/bob.io.base/utils.h +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @author Andre Anjos <andre.anjos@idiap.ch> - * @date Wed 3 Oct 07:46:49 2012 - * - * @brief Utilities for easy manipulation of filed data. - */ - -#ifndef BOB_IO_BASE_BASE_UTILS_H -#define BOB_IO_BASE_BASE_UTILS_H - -#include <bob.io.base/File.h> -#include <boost/shared_ptr.hpp> - -namespace bob { namespace io { namespace base { - - /** - * Creates a new array codec using the filename extension to determine which - * codec to use. The opening mode is passed to the underlying registered File - * implementation. - * - * Here are the meanings of the mode flag: - * - * 'r': opens for reading only - no modifications can occur; it is an - * error to open a file that does not exist for read-only operations. - * 'w': opens for reading and writing, but truncates the file if it - * exists; it is not an error to open files that do not exist with - * this flag. - * 'a': opens for reading and writing - any type of modification can - * occur. If the file does not exist, this flag is effectively like - * 'w'. - */ - boost::shared_ptr<File> open (const char* filename, char mode); - - /** - * Opens the file pretending it has a different extension (that is, using a - * different codec) then the one expected (if any). This allows you to write - * a file with the extension you want, but still using one of the available - * codecs. - */ - boost::shared_ptr<File> open (const char* filename, char mode, - const char* pretend_extension); - - /** - * Peeks the file and returns the type information for reading individual - * frames (or samples) from the file. - * - * This method is equivalent to calling open() with 'r' as mode flag and then - * calling type() on the returned bob::io::base::File object. - */ - BobIoTypeinfo peek (const char* filename); - - /** - * Peeks the file and returns the type information for reading the whole - * contents in a single shot. - * - * This method is equivalent to calling open() with 'r' as mode flag and then - * calling type_all() on the returned bob::io::base::File object. - */ - BobIoTypeinfo peek_all (const char* filename); - - /** - * Opens for reading and load all contents - * - * This method is equivalent to calling open() with 'r' as mode flag and then - * calling read_all() on the returned bob::io::base::File object. - */ - template <typename T, int N> blitz::Array<T,N> load (const char* filename) { - return open(filename, 'r')->read_all<T,N>(); - } - - /** - * Opens for reading and load a particular frame (or sample) - * - * This method is equivalent to calling open() with 'r' as mode flag and then - * calling read(index) on the returned bob::io::base::File object. - */ - template <typename T, int N> blitz::Array<T,N> load (const char* filename, size_t index) { - return open(filename, 'r')->read<T,N>(index); - } - - /** - * Opens for appending and add an array to it - * - * This method is equivalent to calling open() with 'a' as mode flag and then - * calling append(data) on the returned bob::io::base::File object. - */ - template <typename T, int N> void append (const char* filename, const blitz::Array<T,N>& data) { - open(filename, 'a')->append(data); - } - - /** - * Opens for writing and write an array to it. If the file exists before the - * call to this method, it is truncated. - * - * This method is equivalent to calling open() with 'w' as mode flag and then - * calling write(data) on the returned bob::io::base::File object. - */ - template <typename T, int N> void save (const char* filename, const blitz::Array<T,N>& data) { - open(filename, 'w')->write(data); - } - -}}} - -#endif /* BOB_IO_BASE_BASE_UTILS_H */ diff --git a/bob/io/base/typeinfo.cpp b/bob/io/base/typeinfo.cpp index ff275c93009efb88809143309c388a6c4d8f1a66..386843fe3a66d9dd282fff63284351bad6f345a2 100644 --- a/bob/io/base/typeinfo.cpp +++ b/bob/io/base/typeinfo.cpp @@ -67,7 +67,7 @@ int BobIoTypeinfo_SignedSet (BobIoTypeinfo* self, int dtype, Py_ssize_t nd, } int BobIoTypeinfo_SetWithStrides (BobIoTypeinfo* self, int dtype, - Py_ssize_t nd, const Py_ssize_t* shape, const Py_ssize_t* stride) { + size_t nd, const size_t* shape, const size_t* stride) { self->dtype = dtype; if (nd > (BOB_BLITZ_MAXDIMS+1)) { diff --git a/bob/io/base/utils.cpp b/bob/io/base/utils.cpp index 17a7fde340709f8606ba25006d27646eee676b20..53ebd5fb28160f3fcdc1e090345d623b38bdac95 100644 --- a/bob/io/base/utils.cpp +++ b/bob/io/base/utils.cpp @@ -9,28 +9,29 @@ #define BOB_IO_BASE_MODULE #include <bob.io.base/api.h> +#include <bob.io.base/File.h> #include "cpp/CodecRegistry.h" -boost::shared_ptr<bob::io::base::File> BobIoFile_Open (const char* filename, - char mode, const char* pretend_extension) { +boost::shared_ptr<bob::io::base::File> BobIoFile_Open + (const char* filename, char mode) { boost::shared_ptr<bob::io::base::CodecRegistry> instance = bob::io::base::CodecRegistry::instance(); - return instance->findByExtension(pretend_extension)(filename, mode); + return instance->findByFilenameExtension(filename)(filename, mode); } -boost::shared_ptr<bob::io::base::File> BobIoFile_OpenWithExtension - (const char* filename, char mode) { +boost::shared_ptr<bob::io::base::File> BobIoFile_OpenWithExtension (const char* filename, + char mode, const char* pretend_extension) { boost::shared_ptr<bob::io::base::CodecRegistry> instance = bob::io::base::CodecRegistry::instance(); - return instance->findByFilenameExtension(filename)(filename, mode); + return instance->findByExtension(pretend_extension)(filename, mode); } void BobIoFile_Peek (const char* filename, BobIoTypeinfo* info) { - BobIoTypeinfo_Copy(info, BobIoFile_Open(filename, 'r')->type()); + BobIoTypeinfo_Copy(info, &BobIoFile_Open(filename, 'r')->type()); } void BobIoFile_PeekAll (const char* filename, BobIoTypeinfo* info) { - BobIoTypeinfo_Copy(info, BobIoFile_Open(filename, 'r')->type_all()); + BobIoTypeinfo_Copy(info, &BobIoFile_Open(filename, 'r')->type_all()); } diff --git a/setup.py b/setup.py index 5d2078a0f912f4a8dd7491b8ab20ba080ac64294..70f76bfe3c95d76b1d9b6f9274f09a23ddeb8bbf 100644 --- a/setup.py +++ b/setup.py @@ -168,11 +168,9 @@ setup( ), Extension("bob.io.base._library", [ - "bob/io/base/utils.cpp", "bob/io/base/cpp/TensorFileHeader.cpp", "bob/io/base/cpp/TensorFile.cpp", "bob/io/base/cpp/blitz_array.cpp", - "bob/io/base/cpp/CodecRegistry.cpp", "bob/io/base/cpp/HDF5Attribute.cpp", "bob/io/base/cpp/HDF5Dataset.cpp", @@ -181,6 +179,8 @@ setup( "bob/io/base/cpp/HDF5Types.cpp", "bob/io/base/cpp/HDF5Utils.cpp", + "bob/io/base/file.cpp", + "bob/io/base/utils.cpp", "bob/io/base/csv.cpp", "bob/io/base/hdf5plugin.cpp", "bob/io/base/torch3.cpp", @@ -189,7 +189,6 @@ setup( "bob/io/base/typeinfo.cpp", "bob/io/base/bobskin.cpp", "bob/io/base/codec.cpp", - "bob/io/base/file.cpp", "bob/io/base/hdf5.cpp", "bob/io/base/main.cpp", ],