Skip to content

Commit

Permalink
inline
Browse files Browse the repository at this point in the history
  • Loading branch information
msupernaw committed Nov 19, 2023
1 parent 0fa0c0a commit 0e150fc
Show file tree
Hide file tree
Showing 2 changed files with 534 additions and 401 deletions.
142 changes: 139 additions & 3 deletions inst/include/SharedRList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace Rcpp {

}

/**
* Named shared list in shared memory.
*/
class SharedList : public SharedRObject {

struct tuple {
Expand All @@ -36,6 +39,7 @@ class SharedList : public SharedRObject {

};

//used during open only
std::vector<std::shared_ptr<SharedRObject> > stash;

typedef std::string KeyType;
Expand Down Expand Up @@ -93,6 +97,7 @@ class SharedList : public SharedRObject {
typedef typename SMLIST::iterator iterator;
typedef typename SMLIST::const_iterator const_iterator;
typedef typename SMLIST::reverse_iterator reverse_iterator;
typedef typename SMLIST::const_reverse_iterator const_reverse_iterator;
typedef typename SMLIST::node_type node_type;

SharedList() {
Expand Down Expand Up @@ -136,7 +141,7 @@ class SharedList : public SharedRObject {
this->segment.destroy<SMLIST>(name.c_str());
}

void set(const std::string& key, SEXP object) {
void set(const key_type& key, SEXP object) {

if (this->is_SharedRObject(object)) {
SMTYPE type = this->getSharedRObjectType(object);
Expand Down Expand Up @@ -176,7 +181,7 @@ class SharedList : public SharedRObject {

}

SEXP get(const std::string& key) {
SEXP get(const key_type& key) {


if ((*this->tlist_m)[key].type == SMTYPE::SMNUMERIC) {
Expand All @@ -199,10 +204,139 @@ class SharedList : public SharedRObject {
// // return static_cast<SEXP> (R_ExternalPtrAddr((*this->tlist_m)[key].data));
}

size_t size() {

//Iterators:

inline iterator begin() {
return this->tlist_m->begin();
}

inline const_iterator begin() const {
return this->tlist_m->begin();
}

inline iterator end() {
return this->tlist_m->end();
}

inline const_iterator end() const {
return this->tlist_m->end();
}

inline reverse_iterator rbegin() {
return this->tlist_m->rbegin();
}

inline const_reverse_iterator rbegin() const {
return this->tlist_m->rbegin();
}

inline reverse_iterator rend() {
return this->tlist_m->rend();
}

inline const_reverse_iterator rend() const {
return this->tlist_m->rend();
}


//Capacity:

inline bool empty()const {
return this->tlist_m->empty();
}

inline size_type size() const {
return this->tlist_m->size();
}

inline size_type max_size() const {
return this->tlist_m->max_size();
}

//Element access:

inline SEXP operator[](const key_type& k) {
return this->get(k);
}

//Modifiers:

inline std::pair<iterator, bool> insert(const value_type& val) {
return this->tlist_m->insert(val);
}

inline iterator insert(iterator position, const value_type& val) {
return this->tlist_m->insert(position, val);
}

template <class InputIterator>
void insert(InputIterator first, InputIterator last) {
this->tlist_m->insert(first, last);
}

inline void erase(iterator position) {
this->tlist_m->erase(position);
}

inline size_type erase(const key_type& k) {
return this->tlist_m->erase(k);
}

inline void erase(iterator first, iterator last) {
this->tlist_m->erase(first, last);
}

inline void swap(SharedList& x) {
this->tlist_m->swap((*x.tlist_m));
}

inline void clear() {
this->tlist_m->clear();
}


//Operations:

inline iterator find(const key_type& k) {
return this->tlist_m->find(k);
}

inline const_iterator find(const key_type& k) const {
return this->tlist_m->find(k);
}

inline size_type count(const key_type& k) const {
return this->tlist_m->count(k);
}

inline iterator lower_bound(const key_type& k) {
return this->tlist_m->lower_bound(k);
}

inline const_iterator lower_bound(const key_type& k) const {
return this->tlist_m->lower_bound(k);
}

inline iterator upper_bound(const key_type& k) {
return this->tlist_m->upper_bound(k);
}

inline const_iterator upper_bound(const key_type& k) const {
return this->tlist_m->upper_bound(k);
}

inline std::pair<iterator, iterator> equal_range(const key_type& k) {
return this->tlist_m->equal_range(k);
}

inline std::pair<const_iterator, const_iterator> equal_range(const key_type& k) const {
return this->tlist_m->equal_range(k);
}


//Allocator:

};


Expand All @@ -213,6 +347,7 @@ namespace Rcpp {
template <> SEXP wrap<SharedList>(const SharedList& el) {
Rcpp::Rcout << __LINE__ << std::endl;
Rcpp::Language call("new", Symbol("SharedList"));

return call.eval();
}

Expand All @@ -236,6 +371,7 @@ namespace Rcpp {

return SharedList((* xptr.get()));
} catch (...) {

Rcpp::Rcout << __LINE__ << std::endl;
::Rf_error("supplied object could not be converted to SharedList.");
}
Expand Down
Loading

0 comments on commit 0e150fc

Please sign in to comment.