collection.h
1 /* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2  *
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <memory>
8 #include <string>
9 
10 #include <morphio/morphology.h>
11 #include <morphio/mut/morphology.h>
12 
13 namespace morphio {
14 
15 class CollectionImpl;
16 
17 template <class M>
19 
23 template <class T, class U = void>
24 struct enable_if_immutable: public std::enable_if<std::is_same<T, Morphology>::value, U> {};
25 
29 template <class T, class U = void>
30 struct enable_if_mutable: public std::enable_if<std::is_same<T, mut::Morphology>::value, U> {};
31 
33 {
34  public:
35  Collection(std::shared_ptr<CollectionImpl> collection);
36 
48  Collection(std::string collection_path,
49  std::vector<std::string> extensions =
50  std::vector<std::string>{".h5", ".H5", ".asc", ".ASC", ".swc", ".SWC"});
51 
55  template <class M>
57  const std::string& morph_name,
58  unsigned int options = NO_MODIFIER,
59  std::shared_ptr<WarningHandler> warning_handler = nullptr) const;
60 
64  template <class M>
66  const std::string& morph_name,
67  unsigned int options = NO_MODIFIER,
68  std::shared_ptr<WarningHandler> warning_handler = nullptr) const;
69 
75  template <class M>
77  std::vector<std::string> morphology_names,
78  unsigned int options = NO_MODIFIER,
79  std::shared_ptr<WarningHandler> warning_handler = nullptr) const;
80 
89  std::vector<size_t> argsort(const std::vector<std::string>& morphology_names) const;
90 
102  void close();
103 
104  private:
105  std::shared_ptr<CollectionImpl> _collection;
106 };
107 
108 class LoadUnorderedImpl;
109 
142 template <class M>
143 class LoadUnordered
144 {
145  protected:
146  class Iterator
147  {
148  public:
149  Iterator(std::shared_ptr<LoadUnorderedImpl> load_unordered_impl, size_t k);
150 
151  template <class U = M>
152  typename enable_if_immutable<U, std::pair<size_t, M>>::type operator*() const;
153 
154  template <class U = M>
155  typename enable_if_mutable<U, std::pair<size_t, M>>::type operator*() const;
156 
157  Iterator& operator++();
158  Iterator operator++(int);
159 
160  bool operator==(const Iterator& other) const;
161  bool operator!=(const Iterator& other) const;
162 
163  private:
164  size_t _k;
165  std::shared_ptr<LoadUnorderedImpl> _load_unordered_impl;
166  };
167 
168  public:
169  LoadUnordered(std::shared_ptr<LoadUnorderedImpl> load_unordered_impl);
170 
171  Iterator begin() const;
172  Iterator end() const;
173 
174  protected:
175  std::shared_ptr<LoadUnorderedImpl> _load_unordered_impl;
176 };
177 
178 extern template class LoadUnordered<Morphology>;
179 extern template class LoadUnordered<mut::Morphology>;
180 
181 extern template class LoadUnordered<Morphology>::Iterator;
182 extern template class LoadUnordered<mut::Morphology>::Iterator;
183 
186 
187 extern template
190 
192 Collection::load<mut::Morphology>(const std::string& morph_name,
193  unsigned int options,
194  std::shared_ptr<WarningHandler> warning_handler) const;
195 
197 Collection::load<Morphology>(const std::string& morph_name,
198  unsigned int options,
199  std::shared_ptr<WarningHandler> warning_handler) const;
200 
201 extern template LoadUnordered<Morphology> Collection::load_unordered<Morphology>(
202  std::vector<std::string> morphology_names,
203  unsigned int options,
204  std::shared_ptr<WarningHandler> warning_handler) const;
205 
206 extern template LoadUnordered<mut::Morphology> Collection::load_unordered<mut::Morphology>(
207  std::vector<std::string> morphology_names,
208  unsigned int options,
209  std::shared_ptr<WarningHandler> warning_handler) const;
210 
211 } // namespace morphio
morphio::enums::NO_MODIFIER
@ NO_MODIFIER
Read morphology as is without any modification.
Definition: enums.h:18
morphio::Morphology
Definition: morphology.h:26
morphio::Collection::load
enable_if_mutable< M, M >::type load(const std::string &morph_name, unsigned int options=NO_MODIFIER, std::shared_ptr< WarningHandler > warning_handler=nullptr) const
morphio::Collection::load_unordered
LoadUnordered< M > load_unordered(std::vector< std::string > morphology_names, unsigned int options=NO_MODIFIER, std::shared_ptr< WarningHandler > warning_handler=nullptr) const
morphio::LoadUnordered::Iterator
Definition: collection.h:146
morphio::enable_if_immutable
Definition: collection.h:24
morphio::Collection::close
void close()
morphio::Collection
Definition: collection.h:32
morphio::LoadUnordered
Definition: collection.h:18
morphio::Collection::argsort
std::vector< size_t > argsort(const std::vector< std::string > &morphology_names) const
morphio::mut::Morphology
Definition: morphology.h:32
morphio::enable_if_mutable
Definition: collection.h:30