A.I.M.S


aimsGraphR_d.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * Region Of Interest
36  */
37 #ifndef AIMS_IO_AIMSGRAPHR_D_H
38 #define AIMS_IO_AIMSGRAPHR_D_H
39 
40 #include <aims/io/aimsGraphR.h>
41 #include <aims/io/reader.h>
42 #include <aims/io/datatypecode.h>
43 #include <aims/io/finder.h>
44 #include <aims/graph/graphmanip.h>
45 #include <cartobase/smart/rcptr.h>
46 
47 namespace aims
48 {
49 
50  namespace internal
51  {
52 
54  {
55  friend class aims::AimsGraphReader;
56 
57  private:
58  static void
59  loadGlobalObjects( std::map<std::string, aims::AimsGraphReader::Wrapper*>
60  & objects,
61  const std::map<std::string,
62  std::map<std::string, std::string> > & globals,
63  const std::string & basepath,
64  std::map<std::string,
65  std::map<std::string, GraphElementCode> > & objmap,
66  AimsGraphReader & agr );
67 
68  std::string filename;
69  std::set<std::string> readfilter;
70  std::set<std::string> excludefilter;
72  };
73 
74  }
75 
76  // Implementation
77 
78  template<typename T> AimsGraphReader::Wrapper *
80  {
81  typename T::const_iterator io;
82  io = data->find( index );
83  T *obj = new T;
84  if( io != data->end() )
85  (*obj)[0] = io->second;
86  DataManip::adjustVoxelSize( *obj, *data );
87  return( new ObjectWrapper<T>( obj ) );
88  }
89 
90 
91  template<typename T> std::string
93  {
94  return( carto::DataTypeCode<T>().objectType() );
95  }
96 
97 
98  template<typename T> std::string
100  {
101  return( carto::DataTypeCode<T>().dataType() );
102  }
103 
104 
105  template<class T> bool
106  AimsGraphReader::read( Process & p, const std::string & fname, Finder & f )
107  {
108  T *obj = new T;
109  Reader<T> r( fname );
110  try
111  {
112  r.read( *obj );
113  }
114  catch( std::exception & e )
115  {
116  std::cerr << e.what() << std::endl;
117  delete obj;
118  return false;
119  }
120 
121  AimsGraphReader & ap = (AimsGraphReader &) p;
122  internal::AimsGraphReader_Private & ps = *ap._priv;
123  ElementInfo & info = ps.postproc.info;
124 
125  // ensure postprocessor has this type registered
126  const std::map<std::string, std::map<std::string, ProcFunc> > & pcs
127  = ps.postproc.processTypes();
128  std::map<std::string, std::map<std::string, ProcFunc> >::const_iterator
129  ipcs = pcs.find( f.objectType() );
130  if( ipcs == pcs.end()
131  || ipcs->second.find( f.dataType() ) == ipcs->second.end() )
132  ps.postproc.registerProcessType
133  ( f.objectType(), f.dataType(),
134 #if ( __GNUC__-0 == 2 && __GNUC_MINOR__-0 <= 91 )
135  &defaultInsertFunction<T> );
136 #else
137  &AimsGraphReader::defaultInsertFunction<T> );
138 #endif
139 
140  info.object = new AimsGraphReader::ObjectWrapper<T>( obj );
141  return( true );
142  }
143 
144 
145  template<class T> bool
146  AimsGraphReader::defaultInsertFunction( Process & p, const std::string &,
147  Finder & )
148  {
149  PostProcessor & pp = (PostProcessor &) p;
150  const ElementInfo & info = pp.elementInfo();
151  T * obj = ((const ObjectWrapper<T> *) info.object)->data;
152  if( obj )
153  info.element->setProperty( info.attribute, carto::rc_ptr<T>( obj ) );
154  return( true );
155  }
156 
157 
158 }
159 
160 
161 #endif
const std::map< std::string, std::map< std::string, ProcFunc > > & processTypes() const
Query registered process types.
Definition: process.h:235
void registerProcessType(const std::string &objType, const std::string &dataType, ProcFunc procFunc)
Registers the process to call on a given (object type, data type) couple (just fills the map) ...
std::string dataType() const
Definition: finder.h:142
Reader / postprocessor for graph reading.
Definition: aimsGraphR.h:58
virtual std::string dataType() const
Definition: aimsGraphR_d.h:99
static bool read(Process &, const std::string &, Finder &)
Aims object reading function - called by the Process mechanism.
Definition: aimsGraphR_d.h:106
Generic finder / checker for all data objects and file formats This will replace the old AimsFinder...
Definition: finder.h:117
Generic reader for every format of Aims object.
Definition: reader.h:69
void adjustVoxelSize(T &, const T &)
utility function to copy voxel sizes from an object to another (if applicable)
virtual std::string objectType() const
Definition: aimsGraphR_d.h:92
virtual bool read(T &obj, int border=0, const std::string *format=0, int frame=-1)
Finds the correct format and reads the object. if format is specified, this format is tried first...
Definition: reader_d.h:137
Link mechanism between the Finder and a process operating on arbitrary data types.
Definition: process.h:199
std::string objectType() const
Definition: finder.h:140