• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

get_header.hh

00001 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_IO_RAW_GET_HEADER_HH
00027 # define MLN_IO_RAW_GET_HEADER_HH
00028 
00032 
00033 # include <iostream>
00034 # include <fstream>
00035 
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/core/routine/initialize.hh>
00038 # include <mln/core/box_runstart_piter.hh>
00039 # include <mln/core/pixel.hh>
00040 # include <mln/data/memcpy_.hh>
00041 # include <mln/util/array.hh>
00042 
00043 namespace mln
00044 {
00045 
00046   namespace io
00047   {
00048 
00049     namespace raw
00050     {
00051 
00053       struct raw_header
00054       {
00055         unsigned dim;
00056         std::string value_type;
00057         util::array<unsigned> size;
00058       };
00059 
00060 
00062       raw_header get_header(const std::string& filename);
00063 
00064 
00065 # ifndef MLN_INCLUDE_ONLY
00066 
00067 
00068       raw_header get_header(const std::string& filename)
00069       {
00070         trace::entering("mln::io::raw::get_header");
00071 
00072         raw_header header;
00073 
00074         std::string info_filename = filename + ".info";
00075 
00076         std::ifstream info_file(info_filename.c_str());
00077         if (! info_file)
00078         {
00079           std::cerr << "io::raw::get_header - Error: cannot open file '"
00080                     << filename << "'!"
00081                     << std::endl;
00082           abort();
00083         }
00084 
00085         std::string file_type;
00086         info_file >> file_type;
00087         if (file_type != "milena/raw")
00088         {
00089           std::cerr << "io::raw::load - Error: invalid file type. '"
00090                     << filename
00091                     << "' is NOT a valid milena/raw info file!"
00092                     << std::endl;
00093           abort();
00094         }
00095 
00096         char dev_null[30];
00097 
00098         // Dimension ?
00099         // Reading line title "Dim: "
00100         info_file.read(dev_null, 5);
00101         info_file >> header.dim;
00102 
00103         // Size information - Skip it, useless.
00104         header.size.resize(header.dim);
00105         for (unsigned i = 0; i < header.dim; ++i)
00106           info_file >> header.size[i];
00107         // Skipping endline.
00108         char c;
00109         info_file.get(c);
00110 
00111 
00112         // Value type name ?
00113         // Reading line title "data type: "
00114         info_file.read(dev_null, 11);
00115         // WARNING: value type name limited to 255 characters...
00116         char value_type[255];
00117         info_file.getline(value_type, 255);
00118         header.value_type = value_type;
00119 
00120         info_file.close();
00121 
00122         trace::exiting("mln::io::raw::get_header");
00123         return header;
00124       }
00125 
00126 
00127 # endif // ! MLN_INCLUDE_ONLY
00128 
00129     } // end of namespace mln::io::raw
00130 
00131   } // end of namespace mln::io
00132 
00133 } // end of namespace mln
00134 
00135 #endif // ! MLN_IO_RAW_GET_HEADER_HH
00136 

Generated on Tue Oct 4 2011 15:23:48 for Milena (Olena) by  doxygen 1.7.1