DataStore.hpp 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
#ifndef __HEPNOS_DATA_STORE_H
#define __HEPNOS_DATA_STORE_H

#include <string>
#include <memory>

namespace hepnos {

class DataSet;

class DataStore {

    public:

        DataStore(const std::string& configFile);

        DataStore(const DataStore&) = delete;
        DataStore(DataStore&&);
        DataStore& operator=(const DataStore&) = delete;
        DataStore& operator=(DataStore&&);
    
        ~DataStore();

        class iterator;
        class const_iterator;

        iterator find(const std::string& datasetName);

        inline const_iterator find(const std::string& datasetName) const;

        iterator begin();

        iterator end();

        const_iterator cbegin() const;

        const_iterator cend() const;

        iterator lower_bound(const std::string& lb);

        const_iterator lower_bound(const std::string& lb) const;

        iterator upper_bound(const std::string& ub);

        const_iterator upper_bound(const std::string& ub) const;

        DataSet createDataSet(const std::string& name);

    private:

        class Impl;
        std::unique_ptr<Impl> m_impl;
};

class DataStore::const_iterator {

    friend class DataStore::Impl;
    friend class DataStore;

    protected:

        DataStore* m_datastore;

        const_iterator(DataStore& ds);

    public:

        typedef const_iterator self_type;
        typedef DataSet value_type;
        typedef DataSet& reference;
        typedef DataSet* pointer;
        typedef int difference_type;
        typedef std::forward_iterator_tag iterator_category;

        virtual ~const_iterator();
        const_iterator(const const_iterator&);
        const_iterator(const_iterator&&);
        const_iterator& operator=(const const_iterator&);
        const_iterator& operator=(const_iterator&&);

        self_type operator++();
        self_type operator++(int);
        const reference operator*();
        const pointer operator->();
        bool operator==(const self_type& rhs) const;
        bool operator!=(const self_type& rhs) const;
};

class DataStore::iterator : public DataStore::const_iterator {

        friend class DataStore::Impl;
        friend class DataStore;

    private:

        iterator(DataStore& ds);

    public:

        typedef iterator self_type;
        typedef DataSet value_type;
        typedef DataSet& reference;
        typedef DataSet* pointer;
        typedef int difference_type;
        typedef std::forward_iterator_tag iterator_category;

        ~iterator();
        iterator(const iterator&);
        iterator(iterator&&);
        iterator& operator=(const iterator&);
        iterator& operator=(iterator&&);

        reference operator*();
        pointer operator->();
};

}

#endif