Chemical Data Processing Library C++ API - Version 1.4.0
MMCIFData.hpp
Go to the documentation of this file.
1 /*
2  * MMCIFData.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_BIOMOL_MMCIFDATA_HPP
30 #define CDPL_BIOMOL_MMCIFDATA_HPP
31 
32 #include <cstddef>
33 #include <string>
34 #include <memory>
35 #include <iosfwd>
36 
37 #include <boost/ptr_container/ptr_vector.hpp>
38 #include <boost/ptr_container/ptr_deque.hpp>
39 
41 
42 
43 namespace CDPL
44 {
45 
46  namespace Biomol
47  {
48 
54  {
55 
56  public:
58  typedef std::shared_ptr<MMCIFData> SharedPointer;
59 
64  {
65 
66  typedef std::vector<std::string> ValueList;
67 
68  public:
70  typedef ValueList::const_iterator ConstValueIterator;
72  typedef ValueList::iterator ValueIterator;
73 
78  Item(const std::string& name):
79  name(name) {}
80 
85  const std::string& getName() const;
86 
91  std::size_t getNumValues() const;
92 
96  void clear();
97 
104  const std::string& getValue(std::size_t index) const;
105 
112  void setValue(std::size_t index, const std::string& value);
113 
120  void setValue(std::size_t index, std::string&& value);
121 
126  void addValue(const std::string& value);
127 
132  void addValue(std::string&& value);
133 
140 
146  void removeValue(std::size_t index);
147 
152  void swap(Item& item);
153 
159 
165 
171 
177 
183 
189 
195 
201 
202  private:
203  std::string name;
204  ValueList values;
205  };
206 
211  {
212 
213  typedef boost::ptr_vector<Item> ItemList;
214 
215  public:
217  typedef ItemList::const_iterator ConstItemIterator;
219  typedef ItemList::iterator ItemIterator;
220 
225  Category(const std::string& name):
226  name(name) {}
227 
232  const std::string& getName() const;
233 
237  void clear();
238 
243  std::size_t getNumItems() const;
244 
251  Item& getItem(std::size_t index);
252 
259  const Item& getItem(std::size_t index) const;
260 
267  Item& getItem(const std::string& name);
268 
275  const Item& getItem(const std::string& name) const;
276 
282  const Item* findItem(const std::string& name) const;
283 
289  Item* findItem(const std::string& name);
290 
300  Item& addItem(const std::string& name);
301 
308 
314  bool removeItem(const std::string& name);
315 
321  void removeItem(std::size_t index);
322 
327  void swap(Category& cat);
328 
334 
340 
346 
352 
358 
364 
370 
376 
381  std::size_t getNumValueRows() const;
382 
383  private:
384  ItemIterator getItemIter(const std::string& name);
385 
386  ConstItemIterator getItemIter(const std::string& name) const;
387 
388  std::string name;
389  ItemList items;
390  };
391 
392  private:
393  typedef boost::ptr_deque<Category> CategoryList;
394 
395  public:
397  typedef CategoryList::const_iterator ConstCategoryIterator;
399  typedef CategoryList::iterator CategoryIterator;
400 
404  MMCIFData() = default;
405 
410  MMCIFData(const std::string& id);
411 
416  void setID(const std::string& id);
417 
422  const std::string& getID() const;
423 
427  void clear();
428 
433  std::size_t getNumCategories() const;
434 
441  Category& getCategory(std::size_t index);
442 
449  const Category& getCategory(std::size_t index) const;
450 
457  Category& getCategory(const std::string& name);
458 
465  const Category& getCategory(const std::string& name) const;
466 
472  const Category* findCategory(const std::string& name) const;
473 
479  Category* findCategory(const std::string& name);
480 
486  const Category& lastCategory() const;
487 
494 
505  Category& addCategory(const std::string& name, bool front = false);
506 
513 
519  bool removeCategory(const std::string& name);
520 
526  void removeCategory(std::size_t index);
527 
532  void swap(MMCIFData& data);
533 
539 
545 
551 
557 
563 
569 
575 
581 
582  private:
583  CategoryIterator getCategoryIter(const std::string& name);
584 
585  ConstCategoryIterator getCategoryIter(const std::string& name) const;
586 
587  std::string id;
588  CategoryList categories;
589  };
590 
598  CDPL_BIOMOL_API std::ostream& operator<<(std::ostream& os, const MMCIFData& data);
599 
607  CDPL_BIOMOL_API std::ostream& operator<<(std::ostream& os, const MMCIFData::Category& cat);
608 
609  } // namespace Biomol
610 } // namespace CDPL
611 
612 #endif // CDPL_BIOMOL_MMCIFDATA_HPP
Definition of the preprocessor macro CDPL_BIOMOL_API.
#define CDPL_BIOMOL_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
A single mmCIF data category, holding an ordered list of data items (columns).
Definition: MMCIFData.hpp:211
ConstItemIterator getItemsBegin() const
Returns a constant iterator pointing to the beginning of the item list.
const Item & getItem(const std::string &name) const
Returns a const reference to the item with name name.
ConstItemIterator end() const
Returns a constant iterator pointing one past the last item (alias of getItemsEnd()).
void clear()
Removes all items from the category.
ItemIterator begin()
Returns a mutable iterator pointing to the beginning of the item list (alias of getItemsBegin()).
std::size_t getNumItems() const
Returns the number of items in the category.
void swap(Category &cat)
Swaps the contents of this category with those of cat.
Item * findItem(const std::string &name)
Returns a mutable pointer to the item with name name, or nullptr if no matching item exists.
bool removeItem(const std::string &name)
Removes the item with name name.
std::size_t getNumValueRows() const
Returns the number of value rows of the category, i.e. the maximum value count over all items.
ItemIterator getItemsEnd()
Returns a mutable iterator pointing one past the last item.
Item & getItem(std::size_t index)
Returns a mutable reference to the item at the zero-based index index.
Item & getItem(const std::string &name)
Returns a mutable reference to the item with name name.
ItemList::const_iterator ConstItemIterator
A constant iterator over the items of the category.
Definition: MMCIFData.hpp:217
ConstItemIterator begin() const
Returns a constant iterator pointing to the beginning of the item list (alias of getItemsBegin()).
ConstItemIterator getItemsEnd() const
Returns a constant iterator pointing one past the last item.
ItemIterator removeItem(const ItemIterator &it)
Removes the item pointed to by the iterator it.
ItemIterator end()
Returns a mutable iterator pointing one past the last item (alias of getItemsEnd()).
ItemIterator getItemsBegin()
Returns a mutable iterator pointing to the beginning of the item list.
const std::string & getName() const
Returns the mmCIF category name.
ItemList::iterator ItemIterator
A mutable iterator over the items of the category.
Definition: MMCIFData.hpp:219
void removeItem(std::size_t index)
Removes the item at the zero-based index index.
Category(const std::string &name)
Constructs an empty Category with the name name.
Definition: MMCIFData.hpp:225
const Item & getItem(std::size_t index) const
Returns a const reference to the item at the zero-based index index.
const Item * findItem(const std::string &name) const
Returns a pointer to the item with name name, or nullptr if no matching item exists.
Item & addItem(const std::string &name)
Appends a new (empty) item with name name to the category.
A single data item (column) of an mmCIF category, holding an ordered list of string values.
Definition: MMCIFData.hpp:64
ValueIterator removeValue(const ValueIterator &it)
Removes the value pointed to by the iterator it.
ConstValueIterator getValuesEnd() const
Returns a constant iterator pointing one past the last value.
void addValue(const std::string &value)
Appends the value value to the item's value list.
ValueList::const_iterator ConstValueIterator
A constant iterator over the value list of the item.
Definition: MMCIFData.hpp:70
Item(const std::string &name)
Constructs an empty Item with the data-item name name.
Definition: MMCIFData.hpp:78
std::size_t getNumValues() const
Returns the number of values stored in the item.
void setValue(std::size_t index, std::string &&value)
Replaces the value at the zero-based index index by moving value.
ValueIterator begin()
Returns a mutable iterator pointing to the beginning of the value list (alias of getValuesBegin()).
ValueList::iterator ValueIterator
A mutable iterator over the value list of the item.
Definition: MMCIFData.hpp:72
ValueIterator end()
Returns a mutable iterator pointing one past the last value (alias of getValuesEnd()).
ConstValueIterator end() const
Returns a constant iterator pointing one past the last value (alias of getValuesEnd()).
void clear()
Removes all values from the item.
void setValue(std::size_t index, const std::string &value)
Replaces the value at the zero-based index index by value.
ConstValueIterator getValuesBegin() const
Returns a constant iterator pointing to the beginning of the value list.
ValueIterator getValuesBegin()
Returns a mutable iterator pointing to the beginning of the value list.
ValueIterator getValuesEnd()
Returns a mutable iterator pointing one past the last value.
const std::string & getName() const
Returns the fully-qualified mmCIF data-item name.
ConstValueIterator begin() const
Returns a constant iterator pointing to the beginning of the value list (alias of getValuesBegin()).
void removeValue(std::size_t index)
Removes the value at the zero-based index index.
const std::string & getValue(std::size_t index) const
Returns the value at the zero-based index index.
void swap(Item &item)
Swaps the contents of this item with those of item.
void addValue(std::string &&value)
Appends the value value to the item's value list by moving.
Data structure for the storage of imported MMCIF data (see [MMCIF]).
Definition: MMCIFData.hpp:54
Category & addCategory(const std::string &name, bool front=false)
Adds a new (empty) category with name name to the data record.
std::shared_ptr< MMCIFData > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MMCIFData instances.
Definition: MMCIFData.hpp:58
const Category & getCategory(std::size_t index) const
Returns a const reference to the category at the zero-based index index.
MMCIFData()=default
Constructs an empty MMCIFData instance with an empty data-block ID.
const std::string & getID() const
Returns the mmCIF data-block ID.
void setID(const std::string &id)
Sets the mmCIF data-block ID to id.
const Category * findCategory(const std::string &name) const
Returns a pointer to the category with name name, or nullptr if no matching category exists.
Category & getCategory(const std::string &name)
Returns a mutable reference to the category with name name.
CategoryIterator end()
Returns a mutable iterator pointing one past the last category (alias of getCategoriesEnd()).
CategoryIterator begin()
Returns a mutable iterator pointing to the beginning of the category list (alias of getCategoriesBegi...
Category * findCategory(const std::string &name)
Returns a mutable pointer to the category with name name, or nullptr if no matching category exists.
void clear()
Removes all categories from the data record (without changing the data-block ID).
std::size_t getNumCategories() const
Returns the number of categories in the data record.
CategoryIterator removeCategory(const CategoryIterator &it)
Removes the category pointed to by the iterator it.
const Category & getCategory(const std::string &name) const
Returns a const reference to the category with name name.
CategoryIterator getCategoriesBegin()
Returns a mutable iterator pointing to the beginning of the category list.
bool removeCategory(const std::string &name)
Removes the category with name name.
CategoryList::const_iterator ConstCategoryIterator
A constant iterator over the categories of the data record.
Definition: MMCIFData.hpp:397
Category & lastCategory()
Returns a mutable reference to the last category of the data record.
CategoryList::iterator CategoryIterator
A mutable iterator over the categories of the data record.
Definition: MMCIFData.hpp:399
ConstCategoryIterator getCategoriesBegin() const
Returns a constant iterator pointing to the beginning of the category list.
void swap(MMCIFData &data)
Swaps the contents of this data record with those of data.
CategoryIterator getCategoriesEnd()
Returns a mutable iterator pointing one past the last category.
Category & getCategory(std::size_t index)
Returns a mutable reference to the category at the zero-based index index.
MMCIFData(const std::string &id)
Constructs an empty MMCIFData instance with the data-block ID id.
const Category & lastCategory() const
Returns a const reference to the last category of the data record.
ConstCategoryIterator getCategoriesEnd() const
Returns a constant iterator pointing one past the last category.
ConstCategoryIterator end() const
Returns a constant iterator pointing one past the last category (alias of getCategoriesEnd()).
ConstCategoryIterator begin() const
Returns a constant iterator pointing to the beginning of the category list (alias of getCategoriesBeg...
void removeCategory(std::size_t index)
Removes the category at the zero-based index index.
CDPL_BIOMOL_API std::ostream & operator<<(std::ostream &os, const MMCIFData &data)
Writes the mmCIF data record data in textual mmCIF format to the output stream os.
The namespace of the Chemical Data Processing Library.