JEMRIS  2.8.1
open-source MRI simulations
BinaryIO.h
Go to the documentation of this file.
1 
5 /*
6  * JEMRIS Copyright (C)
7  * 2006-2015 Tony Stoecker
8  * 2007-2015 Kaveh Vahedipour
9  * 2009-2015 Daniel Pflugfelder
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
26 
27 #ifndef BINARY_IO_H_
28 #define BINARY_IO_H_
29 
30 #include "Declarations.h"
31 #include "NDData.h"
32 
33 #include <stdlib.h>
34 #include <fstream>
35 #include <iostream>
36 
37 inline static std::string
38 URI (const std::string& URL, const std::string& URN) {
39  std::string uri ("/" + URL + "/" + URN);
40  size_t pos = uri.find(DSLASH);
41  while (pos != std::string::npos) {
42  uri.replace (pos, 2, SLASH);
43  pos = uri.find(DSLASH);
44  }
45  return uri;
46 }
47 
51 class BinaryIO {
52 
53 public:
54 
55 
56 
57  BinaryIO () : m_status(IO::OK), m_type(IO::NONE), m_fname (""), m_mode (IO::IN) {}
58 
62  BinaryIO (const std::string& fname, const IO::Mode mode) :
63  m_status(IO::OK), m_type(IO::NONE), m_fname (fname), m_mode (mode) {
64  FileAccess ();
65  }
66 
67 
71  virtual
72  ~BinaryIO () {};
73 
74 
80  inline const std::string
82  return m_fname;
83  }
84 
85 
87  IOStrategy () const {
88  return m_type;
89  }
90 
91 
97  template<class T> IO::Status
98  Read (NDData<T>& data, const std::string& urn, const std::string& url = "") {
99  std::cout << "Oh Oh: You are wrong here!" << std::endl;
100  }
101 
107  template<class T> IO::Status
108  Write (const NDData<T>& dc, const std::string& urn, const std::string& url = "") {
109  std::cout << "Oh Oh: You are wrong here!" << std::endl;
110  }
111 
112 
116  virtual IO::Status
118 
119  if (m_fname.length() > 0) {
120 
121  if (m_mode == IO::IN) {
122  std::ifstream in (m_fname.c_str(), std::ios::binary);
123  m_status = (in) ? IO::OK : IO::FILE_NOT_FOUND;
124  } else {
125  std::ofstream out (m_fname.c_str() , std::ios::binary);
126  m_status = (out) ? IO::OK : IO::INSUFFICIENT_PRIVILEGES;
127  }
128 
129  } else
130  m_status = IO::EMPTY_FILE_NAME;
131 
132  return m_status;
133 
134  }
135 
136 
140  inline const IO::Status
141  Status () {
142  return m_status;
143  }
144 
145 
146 
147 
148 
149 protected:
150 
151  std::string m_fname;
152  NDData<double> m_data;
153  IO::Mode m_mode;
154  IO::Status m_status;
155  IO::Strategy m_type;
156 
157 };
158 
159 #endif
Implementation of JEMRIS Declarations.
BinaryIO(const std::string &fname, const IO::Mode mode)
Contructor.
Definition: BinaryIO.h:62
const IO::Status Status()
Get last status.
Definition: BinaryIO.h:141
Definition: XMLIO.h:49
Mode
Definition: Declarations.h:176
Definition: Declarations.h:132
mode
Definition: Declarations.h:112
virtual ~BinaryIO()
Destructor.
Definition: BinaryIO.h:72
Strategy
Definition: Declarations.h:137
Base class for binary IO strategies.
Definition: BinaryIO.h:51
IO::Status Read(NDData< T > &data, const std::string &urn, const std::string &url="")
Read data from file to container.
Definition: BinaryIO.h:98
Simple nd-data structure.
Definition: NDData.h:53
const std::string GetFileName()
Get file name.
Definition: BinaryIO.h:81
Status
Definition: Declarations.h:148
IO::Status Write(const NDData< T > &dc, const std::string &urn, const std::string &url="")
Write data from container to file.
Definition: BinaryIO.h:108
virtual IO::Status FileAccess()
File access?
Definition: BinaryIO.h:117

-- last change 17.06.2016 | Tony Stoecker | Imprint --