Skip to content

Commit

Permalink
Run clang-format on non-autogen C++ source code (#765)
Browse files Browse the repository at this point in the history
* clang-format src/array_buffers.h

* src/arrow_adapter.h

* src/arrowio.cpp

* clang-format some files

* clang-format src/libtiledb.cpp

* src/nullable.cpp

* src/shmem.cpp

* src/virtualfile.cpp

* Run Rscript -e "Rcpp::compileAttributes()"

* fixups

* rebase

* format src/libtiledb.cpp post-rebase

* roxygenise

* remove some blocks of commented-out code [skip ci]
  • Loading branch information
johnkerl authored Oct 3, 2024
1 parent 64f7f74 commit 7da1be9
Show file tree
Hide file tree
Showing 17 changed files with 5,097 additions and 4,756 deletions.
34 changes: 18 additions & 16 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ tiledb_datatype_string_to_sizeof <- function(str) {

#' Map from TileDB type to R datatype
#'
#' This function maps from the TileDB types to the (fewer) key datatypes in R. This
#' can be lossy as TileDB integers range from (signed and unsigned) 8 to 64 bit whereas
#' R only has (signed) 32 bit values. Similarly, R only has 64 bit doubles whereas TileDB
#' has 32 and 64 bit floating point types. TileDB also has more character encodings, and the
#' full range of (NumPy) date and time types.
#' This function maps from the TileDB types to the (fewer) key datatypes in
#' R. This can be lossy as TileDB integers range from (signed and unsigned) 8
#' to 64 bit whereas R only has (signed) 32 bit values. Similarly, R only has
#' 64 bit doubles whereas TileDB has 32 and 64 bit floating point types.
#' TileDB also has more character encodings, and the full range of (NumPy)
#' date and time types.
#'
#' @param datatype A string describing one TileDB datatype
#' @return A string describing the closest match for an R datatype
Expand Down Expand Up @@ -1247,22 +1248,23 @@ vlcbuf_from_shmem <- function(datapath, dtype) {
#' Create a custom file connection
#'
#' @details
#' This \code{vfs_file()} connection works like the \code{file()} connection in R itself.
#' This \code{vfs_file()} connection works like the \code{file()} connection
#' in R itself.
#'
#' This connection works with both ASCII and binary data, e.g. using
#' \code{readLines()} and \code{readBin()}.
#'
#' @param description path to a filename; contrary to \code{rconnection} a connection
#' object is not supported.
#' @param mode character string. A description of how to open the connection if
#' it is to be opened upon creation e.g. "rb". Default "" (empty string) means
#' to not open the connection on creation - user must still call \code{open()}.
#' Note: If an "open" string is provided, the user must still call \code{close()}
#' otherwise the contents of the file aren't completely flushed until the
#' connection is garbage collected.
#' @param description path to a filename; contrary to \code{rconnection} a
#' connection object is not supported.
#' @param mode character string. A description of how to open the connection
#' if it is to be opened upon creation e.g. "rb". Default "" (empty string)
#' means to not open the connection on creation - user must still call
#' \code{open()}. Note: If an "open" string is provided, the user must still
#' call \code{close()} otherwise the contents of the file aren't completely
#' flushed until the connection is garbage collected.
#' @param verbosity integer value 0, 1, or 2. Default: 0.
#' Set to \code{0} for no debugging messages, \code{1} for some high-level messages
#' and \code{verbosity = 2} for all debugging messages.
#' Set to \code{0} for no debugging messages, \code{1} for some high-level
#' messages and \code{verbosity = 2} for all debugging messages.
#'
#' @export
#'
Expand Down
11 changes: 6 additions & 5 deletions man/tiledb_datatype_R_type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions man/vfs_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 64 additions & 69 deletions src/array_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef ARRAY_BUFFERS_H
#define ARRAY_BUFFERS_H

#include <stdexcept> // for windows: error C2039: 'runtime_error': is not a member of 'std'
#include <stdexcept> // for windows: error C2039: 'runtime_error': is not a member of 'std'

#include <span/span.hpp>
#include <tiledb/tiledb>
Expand All @@ -45,77 +45,72 @@ namespace tiledb {
using namespace tiledb;

class ArrayBuffers {
public:
ArrayBuffers() = default;
ArrayBuffers(const ArrayBuffers&) = delete;
ArrayBuffers(ArrayBuffers&&) = default;
~ArrayBuffers() = default;

/**
* @brief Return the buffer with the given name.
*
* @param name Column name
* @return std::shared_ptr<ColumnBuffer> Column buffer
*/
std::shared_ptr<ColumnBuffer> at(const std::string& name) {
if (!contains(name)) {
Rcpp::stop("[ArrayBuffers] column '%s' does not exist", name);
}
return buffers_[name];
public:
ArrayBuffers() = default;
ArrayBuffers(const ArrayBuffers &) = delete;
ArrayBuffers(ArrayBuffers &&) = default;
~ArrayBuffers() = default;

/**
* @brief Return the buffer with the given name.
*
* @param name Column name
* @return std::shared_ptr<ColumnBuffer> Column buffer
*/
std::shared_ptr<ColumnBuffer> at(const std::string &name) {
if (!contains(name)) {
Rcpp::stop("[ArrayBuffers] column '%s' does not exist", name);
}

/**
* @brief Return true if a buffer with the given name exists.
*
* @param name Column name
* @return True if a buffer with the given name exists
*/
bool contains(const std::string& name) {
return buffers_.find(name) != buffers_.end();
}

/**
* @brief Add a column buffer with the given name to the ArrayBuffers,
* maintaining the insertion order.
*
* @param name Column name
* @param buffer Column buffer
*/
void emplace(
const std::string& name, std::shared_ptr<ColumnBuffer> buffer) {
if (contains(name)) {
Rcpp::stop("[ArrayBuffers] column '%s' already exists", name);
}
names_.push_back(name);
buffers_.emplace(name, buffer);
}

/**
* @brief Returns the ordered vector of names.
*
* @return const std::vector<std::string>& Vector of names
*/
const std::vector<std::string>& names() {
return names_;
return buffers_[name];
}

/**
* @brief Return true if a buffer with the given name exists.
*
* @param name Column name
* @return True if a buffer with the given name exists
*/
bool contains(const std::string &name) {
return buffers_.find(name) != buffers_.end();
}

/**
* @brief Add a column buffer with the given name to the ArrayBuffers,
* maintaining the insertion order.
*
* @param name Column name
* @param buffer Column buffer
*/
void emplace(const std::string &name, std::shared_ptr<ColumnBuffer> buffer) {
if (contains(name)) {
Rcpp::stop("[ArrayBuffers] column '%s' already exists", name);
}

/**
* @brief Returns the number of rows in the array buffer.
*
* @return uint64_t Number of rows
*/
uint64_t num_rows() const {
return buffers_.at(names_.front())->size();
}

private:
// A vector of column names that maintains the order the columns were added
std::vector<std::string> names_;

// Map: column name -> ColumnBuffer
std::unordered_map<std::string, std::shared_ptr<ColumnBuffer>> buffers_;
names_.push_back(name);
buffers_.emplace(name, buffer);
}

/**
* @brief Returns the ordered vector of names.
*
* @return const std::vector<std::string>& Vector of names
*/
const std::vector<std::string> &names() { return names_; }

/**
* @brief Returns the number of rows in the array buffer.
*
* @return uint64_t Number of rows
*/
uint64_t num_rows() const { return buffers_.at(names_.front())->size(); }

private:
// A vector of column names that maintains the order the columns were added
std::vector<std::string> names_;

// Map: column name -> ColumnBuffer
std::unordered_map<std::string, std::shared_ptr<ColumnBuffer>> buffers_;
};

} // namespace tiledb
} // namespace tiledb

#endif
Loading

0 comments on commit 7da1be9

Please sign in to comment.