Chemical Data Processing Library C++ API - Version 1.4.0
FeatureContainerObject3DWriter.hpp
Go to the documentation of this file.
1 /*
2  * FeatureContainerObject3DWriter.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_VIS_FEATURECONTAINEROBJECT3DWRITER_HPP
30 #define CDPL_VIS_FEATURECONTAINEROBJECT3DWRITER_HPP
31 
32 #include <iosfwd>
33 #include <functional>
34 
36 #include "CDPL/Base/DataWriter.hpp"
37 #include "CDPL/Base/Exceptions.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Vis
44  {
45 
56  template <typename WriterImpl>
57  class FeatureContainerObject3DWriter : public Base::DataWriter<Pharm::FeatureContainer>
58  {
59 
60  public:
66  FeatureContainerObject3DWriter(std::ostream& os);
67 
69 
75 
82 
87  operator const void*() const;
88 
93  bool operator!() const;
94 
96 
100  void close();
101 
102  private:
104  WriterImpl o3dWriter;
105  };
106  } // namespace Vis
107 } // namespace CDPL
108 
109 
110 // Implementation
111 
112 template <typename WriterImpl>
114  o3dWriter(os)
115 {
116  o3dFactory.setParent(this);
117 
118  o3dWriter.setParent(this);
119  o3dWriter.registerIOCallback(std::bind(&Base::DataIOBase::invokeIOCallbacks, this, std::placeholders::_2));
120 }
121 
122 template <typename WriterImpl>
124 {
125  close();
126 }
127 
128 template <typename WriterImpl>
130 {
131  try {
132  auto obj = o3dFactory.create(cntnr);
133 
134  o3dWriter.write(*obj);
135 
136  } catch (const std::exception& e) {
137  throw Base::IOError(std::string("FeatureContainerObject3DWriter: ") + e.what());
138  }
139 
140  return *this;
141 }
142 
143 template <typename WriterImpl>
145 {
146  return o3dWriter.operator const void*();
147 }
148 
149 template <typename WriterImpl>
151 {
152  return o3dWriter.operator!();
153 }
154 
155 template <typename WriterImpl>
157 {
158  o3dWriter.close();
159 }
160 
161 #endif // CDPL_VIS_FEATURECONTAINEROBJECT3DWRITER_HPP
Definition of exception classes.
Definition of class CDPL::Base::DataWriter.
Definition of class CDPL::Vis::FeatureContainerObject3DFactory.
void setParent(const ControlParameterContainer *cntnr)
Sets or removes the parent control-parameter container used to resolve requests for missing entries.
void invokeIOCallbacks(double progress) const
Invokes all registered I/O callback functions with the argument *this.
Interface for writing data objects of a given type to an arbitrary data sink.
Definition: DataWriter.hpp:63
virtual DataWriter & write(const DataType &obj)=0
Writes the data object obj.
Thrown to indicate that an I/O operation has failed because of physical (e.g. broken pipe) or logical...
Definition: Base/Exceptions.hpp:250
Abstract base class for containers holding a sequence of Pharm::Feature objects with associated prope...
Definition: FeatureContainer.hpp:55
Class implementing the creation of Vis::Object3D instances providing a 3D representation of Pharm::Fe...
Definition: FeatureContainerObject3DFactory.hpp:59
Generic Base::DataWriter implementation for the generation and output of Pharm::FeatureContainer 3D v...
Definition: FeatureContainerObject3DWriter.hpp:58
~FeatureContainerObject3DWriter()
Destructor.
Definition: FeatureContainerObject3DWriter.hpp:123
FeatureContainerObject3DWriter(const FeatureContainerObject3DWriter &)=delete
bool operator!() const
Tells whether the embedded WriterImpl instance is in a bad (non-writable) state.
Definition: FeatureContainerObject3DWriter.hpp:150
Base::DataWriter< Pharm::FeatureContainer > & write(const Pharm::FeatureContainer &cntnr)
Builds a 3D scene representation of cntnr and outputs it using the embedded WriterImpl instance.
Definition: FeatureContainerObject3DWriter.hpp:129
FeatureContainerObject3DWriter & operator=(const FeatureContainerObject3DWriter &)=delete
FeatureContainerObject3DWriter(std::ostream &os)
Constructs a FeatureContainerObject3DWriter instance that will write 3D models of Pharm::FeatureConta...
Definition: FeatureContainerObject3DWriter.hpp:113
void close()
Closes the embedded WriterImpl instance.
Definition: FeatureContainerObject3DWriter.hpp:156
The namespace of the Chemical Data Processing Library.