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 
55  {
56 
57  public:
58 
62  typedef std::shared_ptr<MMCIFData> SharedPointer;
63 
68  {
69 
70  typedef std::vector<std::string> ValueList;
71 
72  public:
76  typedef ValueList::const_iterator ConstValueIterator;
77 
81  typedef ValueList::iterator ValueIterator;
82 
87  Item(const std::string& name):
88  name(name) {}
89 
94  const std::string& getName() const;
95 
100  std::size_t getNumValues() const;
101 
105  void clear();
106 
113  const std::string& getValue(std::size_t index) const;
114 
121  void setValue(std::size_t index, const std::string& value);
122 
129  void setValue(std::size_t index, std::string&& value);
130 
135  void addValue(const std::string& value);
136 
141  void addValue(std::string&& value);
142 
149 
155  void removeValue(std::size_t index);
156 
161  void swap(Item& item);
162 
168 
174 
180 
186 
192 
198 
204 
210 
211  private:
212  std::string name;
213  ValueList values;
214  };
215 
220  {
221 
222  typedef boost::ptr_vector<Item> ItemList;
223 
224  public:
228  typedef ItemList::const_iterator ConstItemIterator;
229 
233  typedef ItemList::iterator ItemIterator;
234 
239  Category(const std::string& name):
240  name(name) {}
241 
246  const std::string& getName() const;
247 
251  void clear();
252 
257  std::size_t getNumItems() const;
258 
265  Item& getItem(std::size_t index);
266 
273  const Item& getItem(std::size_t index) const;
274 
281  Item& getItem(const std::string& name);
282 
289  const Item& getItem(const std::string& name) const;
290 
296  const Item* findItem(const std::string& name) const;
297 
303  Item* findItem(const std::string& name);
304 
314  Item& addItem(const std::string& name);
315 
323 
329  bool removeItem(const std::string& name);
330 
336  void removeItem(std::size_t index);
337 
342  void swap(Category& cat);
343 
349 
355 
361 
367 
373 
379 
385 
391 
396  std::size_t getNumValueRows() const;
397 
398  private:
399  ItemIterator getItemIter(const std::string& name);
400 
401  ConstItemIterator getItemIter(const std::string& name) const;
402 
403  std::string name;
404  ItemList items;
405  };
406 
407  private:
408  typedef boost::ptr_deque<Category> CategoryList;
409 
410  public:
414  typedef CategoryList::const_iterator ConstCategoryIterator;
415 
419  typedef CategoryList::iterator CategoryIterator;
420 
424  MMCIFData() = default;
425 
430  MMCIFData(const std::string& id);
431 
436  void setID(const std::string& id);
437 
442  const std::string& getID() const;
443 
447  void clear();
448 
453  std::size_t getNumCategories() const;
454 
461  Category& getCategory(std::size_t index);
462 
469  const Category& getCategory(std::size_t index) const;
470 
477  Category& getCategory(const std::string& name);
478 
485  const Category& getCategory(const std::string& name) const;
486 
492  const Category* findCategory(const std::string& name) const;
493 
499  Category* findCategory(const std::string& name);
500 
506  const Category& lastCategory() const;
507 
514 
525  Category& addCategory(const std::string& name, bool front = false);
526 
534 
540  bool removeCategory(const std::string& name);
541 
547  void removeCategory(std::size_t index);
548 
553  void swap(MMCIFData& data);
554 
560 
566 
572 
578 
584 
590 
596 
602 
603  private:
604  CategoryIterator getCategoryIter(const std::string& name);
605 
606  ConstCategoryIterator getCategoryIter(const std::string& name) const;
607 
608  std::string id;
609  CategoryList categories;
610  };
611 
620  CDPL_BIOMOL_API std::ostream& operator<<(std::ostream& os, const MMCIFData& data);
621 
630  CDPL_BIOMOL_API std::ostream& operator<<(std::ostream& os, const MMCIFData::Category& cat);
631 
632  } // namespace Biomol
633 } // namespace CDPL
634 
635 #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:220
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 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:228
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:233
void removeItem(std::size_t index)
Removes the item at index index.
Category(const std::string &name)
Constructs an empty Category instance with the name name.
Definition: MMCIFData.hpp:239
const Item & getItem(std::size_t index) const
Returns a const reference to the item at 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:68
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.
Definition: MMCIFData.hpp:76
Item(const std::string &name)
Constructs an empty Item instance with the data item name name.
Definition: MMCIFData.hpp:87
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 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.
Definition: MMCIFData.hpp:81
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 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 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 index index.
const std::string & getValue(std::size_t index) const
Returns the value at 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 preprocessed Macromolecular Crystallographic Information File (mmCI...
Definition: MMCIFData.hpp:55
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:62
const Category & getCategory(std::size_t index) const
Returns a const reference to the category at 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:414
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:419
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 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 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.