Skip to content

Commit

Permalink
shared_ptr has arrived to the standard. NFC
Browse files Browse the repository at this point in the history
We replace the CPP11_shared_ptr macro with its actual expansion to
std::shared_ptr nowadays.

We replace the inclusion of <CPP11_shared_ptr.hh> with <memory> and order
the includes from less generic to generic ones where applicable.
  • Loading branch information
vgvassilev committed Jul 29, 2019
1 parent 72e9ddf commit 587d436
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 89 deletions.
7 changes: 4 additions & 3 deletions Alignment/Geners/interface/AbsArchive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

#include "Alignment/Geners/interface/AbsRecord.hh"
#include "Alignment/Geners/interface/AbsReference.hh"
#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include "Alignment/Geners/interface/CatalogEntry.hh"
#include "Alignment/Geners/interface/SearchSpecifier.hh"

#include <memory>

namespace gs {
class AbsArchive;
}
Expand Down Expand Up @@ -66,8 +67,8 @@ namespace gs {

// Fetch metadata for the item with given id. NULL pointer is
// returned if there is no item in the archive with the given id
// (and there is an automatic cast from CPP11_shared_ptr to bool).
virtual CPP11_shared_ptr<const CatalogEntry> catalogEntry(unsigned long long id) = 0;
// (and there is an automatic cast from std::hared_ptr to bool).
virtual std::shared_ptr<const CatalogEntry> catalogEntry(unsigned long long id) = 0;

// Dump everything to storage (if the archive is open for writing
// and if this makes sense for the archive)
Expand Down
10 changes: 5 additions & 5 deletions Alignment/Geners/interface/AbsCatalog.hh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef GENERS_ABSCATALOG_HH_
#define GENERS_ABSCATALOG_HH_

#include <cassert>
#include <vector>

#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include "Alignment/Geners/interface/CatalogEntry.hh"
#include "Alignment/Geners/interface/ItemDescriptor.hh"
#include "Alignment/Geners/interface/SearchSpecifier.hh"

#include <cassert>
#include <memory>
#include <vector>

namespace gs {
//
// This abstract class defines interfaces for adding entries to
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace gs {

// The following function returns a shared pointer to the entry.
// The pointer will contain NULL in case the item is not found.
virtual CPP11_shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const = 0;
virtual std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const = 0;

// The following function fetches just the stream position
// associated with the entry. "true" is returned on success.
Expand Down
10 changes: 5 additions & 5 deletions Alignment/Geners/interface/AbsReference.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef GENERS_ABSREFERENCE_HH_
#define GENERS_ABSREFERENCE_HH_

#include <iostream>
#include <vector>

#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include "Alignment/Geners/interface/ClassId.hh"
#include "Alignment/Geners/interface/SearchSpecifier.hh"

#include <iostream>
#include <memory>
#include <vector>

namespace gs {
class AbsArchive;
class CatalogEntry;
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace gs {

// Catalog entry retrieval by index in the list of referenced items.
// Throws gs::IOOutOfRange exception if the index is out of range.
CPP11_shared_ptr<const CatalogEntry> indexedCatalogEntry(unsigned long index) const;
std::shared_ptr<const CatalogEntry> indexedCatalogEntry(unsigned long index) const;

protected:
// Use the following constructor to retrieve an item with
Expand Down
11 changes: 5 additions & 6 deletions Alignment/Geners/interface/ArchiveRecord.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#ifndef GENERS_ARCHIVERECORD_HH_
#define GENERS_ARCHIVERECORD_HH_

#include <vector>

#include "Alignment/Geners/interface/AbsRecord.hh"
#include "Alignment/Geners/interface/ArrayAdaptor.hh"
#include "Alignment/Geners/interface/IOIsAnyPtr.hh"

#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include "Alignment/Geners/interface/GenericIO.hh"

#include <memory>
#include <vector>

namespace gs {
template <typename T>
class ArchiveRecord : public AbsRecord
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace gs {
inline virtual bool writeData(std::ostream& os) const
{return write_item(os, *obj_, true);}

CPP11_shared_ptr<T> obj_;
std::shared_ptr<T> obj_;
};


Expand All @@ -97,9 +97,8 @@ namespace gs {
inline virtual bool writeData(std::ostream& os) const
{return write_array(os, obj_->begin(), obj_->size());}

CPP11_shared_ptr<std::vector<T> > obj_;
std::shared_ptr<std::vector<T> > obj_;
};
}

#endif // GENERS_ARCHIVERECORD_HH_

4 changes: 2 additions & 2 deletions Alignment/Geners/interface/BinaryArchiveBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ namespace gs {
const SearchSpecifier &categoryPattern,
std::vector<unsigned long long> *idsFound) const override;

inline CPP11_shared_ptr<const CatalogEntry> catalogEntry(const unsigned long long id) override {
inline std::shared_ptr<const CatalogEntry> catalogEntry(const unsigned long long id) override {
return catalog_ ? catalog_->retrieveEntry(id)
: CPP11_shared_ptr<const CatalogEntry>((const CatalogEntry *)nullptr);
: std::shared_ptr<const CatalogEntry>((const CatalogEntry *)nullptr);
}

// Inspection methods for compression options
Expand Down
8 changes: 4 additions & 4 deletions Alignment/Geners/interface/ClassId.hh
Original file line number Diff line number Diff line change
Expand Up @@ -591,22 +591,22 @@ namespace gs {

// Skip shared pointers in class ids
template <class T>
struct ClassIdSpecialization<CPP11_shared_ptr<T>> {
struct ClassIdSpecialization<std::shared_ptr<T>> {
inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization<T>::classId(true); }
};

template <class T>
struct ClassIdSpecialization<const CPP11_shared_ptr<T>> {
struct ClassIdSpecialization<const std::shared_ptr<T>> {
inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization<T>::classId(true); }
};

template <class T>
struct ClassIdSpecialization<volatile CPP11_shared_ptr<T>> {
struct ClassIdSpecialization<volatile std::shared_ptr<T>> {
inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization<T>::classId(true); }
};

template <class T>
struct ClassIdSpecialization<const volatile CPP11_shared_ptr<T>> {
struct ClassIdSpecialization<const volatile std::shared_ptr<T>> {
inline static ClassId classId(const bool /* isPtr */ = false) { return ClassIdSpecialization<T>::classId(true); }
};

Expand Down
10 changes: 5 additions & 5 deletions Alignment/Geners/interface/ContiguousCatalog.hh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef GENERS_CONTIGUOUSCATALOG_HH_
#define GENERS_CONTIGUOUSCATALOG_HH_

#include "Alignment/Geners/interface/AbsCatalog.hh"

#include <map>
#include <memory>
#include <vector>

#include "Alignment/Geners/interface/AbsCatalog.hh"
#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"

namespace gs {
class ContiguousCatalog : public AbsCatalog {
public:
Expand All @@ -19,7 +19,7 @@ namespace gs {
inline unsigned long long largestId() const override { return firstId_ + records_.size() - 1; }
inline bool isContiguous() const override { return true; }

CPP11_shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const override;
std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long id) const override;

bool retrieveStreampos(unsigned long long id,
unsigned *compressionCode,
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace gs {
bool isEqual(const AbsCatalog &) const override;

private:
typedef CPP11_shared_ptr<const CatalogEntry> SPtr;
typedef std::shared_ptr<const CatalogEntry> SPtr;

// In the following multimap, item name is the key and
// item id is the value
Expand Down
6 changes: 3 additions & 3 deletions Alignment/Geners/interface/GeneralCatalog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace gs {
inline bool isContiguous() const override { return false; }
inline bool itemExists(const unsigned long long id) const override { return records_.find(id) != records_.end(); }

CPP11_shared_ptr<const CatalogEntry> retrieveEntry(const unsigned long long id) const override;
std::shared_ptr<const CatalogEntry> retrieveEntry(const unsigned long long id) const override;

bool retrieveStreampos(unsigned long long id,
unsigned *compressionCode,
Expand All @@ -38,7 +38,7 @@ namespace gs {
// Add a new entry with id (presumably, from another catalog).
// Returns "true" on success. The entry is not included (and "false"
// is returned) in case the entry with the given id already exists.
bool addEntry(CPP11_shared_ptr<const CatalogEntry> ptr);
bool addEntry(std::shared_ptr<const CatalogEntry> ptr);

// Remove an entry with the given id. "false" is returned in case
// an entry with the specified id does not exist.
Expand All @@ -61,7 +61,7 @@ namespace gs {
bool isEqual(const AbsCatalog &) const override;

private:
typedef CPP11_shared_ptr<const CatalogEntry> SPtr;
typedef std::shared_ptr<const CatalogEntry> SPtr;

// In the following multimap, item name is the key and
// catalog entry pointer is the value
Expand Down
4 changes: 2 additions & 2 deletions Alignment/Geners/interface/GenericIO.hh
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ namespace gs {
ptr, str, s, processClassId);
if (status) {
assert(ptr);
a = CPP11_shared_ptr<Pointee>(ptr);
a = std::shared_ptr<Pointee>(ptr);
return true;
} else {
delete ptr;
Expand Down Expand Up @@ -553,7 +553,7 @@ namespace gs {
GenericReader<Stream, State, Pointee *, Int2Type<IOTraits<int>::ISNULLPOINTER>>::process(ptr, is, st, true);
if (status) {
assert(ptr);
CPP11_shared_ptr<Pointee> sptr(ptr);
std::shared_ptr<Pointee> sptr(ptr);
InsertContainerItem<Container>::insert(obj, sptr, itemN);
} else
delete ptr;
Expand Down
10 changes: 5 additions & 5 deletions Alignment/Geners/interface/IOIsSharedPtr.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GENERS_IOISSHAREDPTR_HH_
#define GENERS_IOISSHAREDPTR_HH_

#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include <memory>

namespace gs {
template <class T>
Expand All @@ -10,22 +10,22 @@ namespace gs {
};

template <class T>
struct IOIsSharedPtr<CPP11_shared_ptr<T>> {
struct IOIsSharedPtr<std::shared_ptr<T>> {
enum { value = 1 };
};

template <class T>
struct IOIsSharedPtr<const CPP11_shared_ptr<T>> {
struct IOIsSharedPtr<const std::shared_ptr<T>> {
enum { value = 1 };
};

template <class T>
struct IOIsSharedPtr<volatile CPP11_shared_ptr<T>> {
struct IOIsSharedPtr<volatile std::shared_ptr<T>> {
enum { value = 1 };
};

template <class T>
struct IOIsSharedPtr<const volatile CPP11_shared_ptr<T>> {
struct IOIsSharedPtr<const volatile std::shared_ptr<T>> {
enum { value = 1 };
};
} // namespace gs
Expand Down
9 changes: 5 additions & 4 deletions Alignment/Geners/interface/Reference.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "Alignment/Geners/interface/AbsReference.hh"
#include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"

#include <memory>

namespace gs {
template <typename T>
Expand Down Expand Up @@ -32,7 +33,7 @@ namespace gs {
// Methods to retrieve the item
void restore(unsigned long index, T *obj) const;
CPP11_auto_ptr<T> get(unsigned long index) const;
CPP11_shared_ptr<T> getShared(unsigned long index) const;
std::shared_ptr<T> getShared(unsigned long index) const;

private:
Reference() = delete;
Expand Down Expand Up @@ -76,8 +77,8 @@ namespace gs {
}

template <typename T>
inline CPP11_shared_ptr<T> Reference<T>::getShared(const unsigned long index) const {
return CPP11_shared_ptr<T>(getPtr(index));
inline std::shared_ptr<T> Reference<T>::getShared(const unsigned long index) const {
return std::shared_ptr<T>(getPtr(index));
}
} // namespace gs

Expand Down
2 changes: 1 addition & 1 deletion Alignment/Geners/interface/StringArchive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace gs {
catalog_.search(namePattern, categoryPattern, idsFound);
}

inline CPP11_shared_ptr<const CatalogEntry> catalogEntry(const unsigned long long id) override {
inline std::shared_ptr<const CatalogEntry> catalogEntry(const unsigned long long id) override {
return catalog_.retrieveEntry(id);
}

Expand Down
2 changes: 1 addition & 1 deletion Alignment/Geners/interface/WriteOnlyCatalog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace gs {

// The following methods will cause a run-time error: there is
// no way to read a write-only catalog or to search it
CPP11_shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long) const override;
std::shared_ptr<const CatalogEntry> retrieveEntry(unsigned long long) const override;

bool retrieveStreampos(unsigned long long id,
unsigned *compressionCode,
Expand Down
22 changes: 11 additions & 11 deletions Alignment/Geners/interface/binaryIO.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#ifndef GENERS_BINARYIO_HH_
#define GENERS_BINARYIO_HH_

#include <cassert>
#include <iostream>
#include <vector>

#include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
#include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
#include "Alignment/Geners/interface/ClassId.hh"
#include "Alignment/Geners/interface/IOException.hh"

#include <cassert>
#include <iostream>
#include <memory>
#include <vector>

namespace gs {
// The following functions perform binary I/O of built-in types.
// Note that all of them are "void". It is assumed that the
Expand Down Expand Up @@ -192,13 +192,13 @@ namespace gs {
// The following assumes that the array contains a bunch of
// shared pointers and that class T has the "read" function
template <typename T>
inline void read_heap_obj_array(std::istream &in, CPP11_shared_ptr<T> *arr, const unsigned long len) {
inline void read_heap_obj_array(std::istream &in, std::shared_ptr<T> *arr, const unsigned long len) {
if (len) {
assert(arr);
const ClassId id(in, 1);
for (unsigned long i = 0; i < len; ++i) {
T *obj = T::read(id, in);
arr[i] = CPP11_shared_ptr<T>(obj);
arr[i] = std::shared_ptr<T>(obj);
}
}
}
Expand All @@ -207,15 +207,15 @@ namespace gs {
template <typename Reader>
inline void read_base_obj_array(std::istream &in,
const Reader &f,
CPP11_shared_ptr<typename Reader::value_type> *arr,
std::shared_ptr<typename Reader::value_type> *arr,
const unsigned long len) {
typedef typename Reader::value_type T;
if (len) {
assert(arr);
const ClassId id(in, 1);
for (unsigned long i = 0; i < len; ++i) {
T *obj = f.read(id, in);
arr[i] = CPP11_shared_ptr<T>(obj);
arr[i] = std::shared_ptr<T>(obj);
}
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ namespace gs {
// The following assumes that the vector contains a bunch of
// shared pointers
template <typename T>
inline void read_heap_obj_vector(std::istream &in, std::vector<CPP11_shared_ptr<T>> *pv) {
inline void read_heap_obj_vector(std::istream &in, std::vector<std::shared_ptr<T>> *pv) {
unsigned long vlen = 0UL;
read_pod(in, &vlen);
if (in.fail())
Expand Down Expand Up @@ -289,7 +289,7 @@ namespace gs {
template <typename Reader>
inline void read_base_obj_vector(std::istream &in,
const Reader &f,
std::vector<CPP11_shared_ptr<typename Reader::value_type>> *pv) {
std::vector<std::shared_ptr<typename Reader::value_type>> *pv) {
unsigned long vlen = 0UL;
read_pod(in, &vlen);
if (in.fail())
Expand Down
Loading

0 comments on commit 587d436

Please sign in to comment.