• 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_DUMP_GET_HEADER_HH
00027 # define MLN_IO_DUMP_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 dump
00050     {
00051 
00053       struct dump_header
00054       {
00055         unsigned dim;
00056         std::string value_type;
00057         util::array<unsigned> size;
00058       };
00059 
00060 
00062       dump_header get_header(const std::string& filename);
00063 
00064 
00065 # ifndef MLN_INCLUDE_ONLY
00066 
00067 
00068       dump_header get_header(const std::string& filename)
00069       {
00070         trace::entering("mln::io::dump::get_header");
00071 
00072         dump_header header;
00073 
00074         std::ifstream file(filename.c_str());
00075         if (! file)
00076         {
00077           std::cerr << "io::dump::get_header - Error: cannot open file '"
00078                     << filename << "'!"
00079                     << std::endl;
00080           abort();
00081         }
00082 
00083 
00084         // Milena's file type ?
00085         std::string file_type;
00086         file >> file_type;
00087         if (file_type != "milena/dump")
00088         {
00089           std::cerr << "io::dump::load - Error: invalid file type. '"
00090                     << filename
00091                     << "' is NOT a valid milena/dump file!"
00092                     << std::endl;
00093           abort();
00094         }
00095 
00096         // Dimension
00097         file >> header.dim;
00098 
00099         // Size information - Skip it, useless.
00100         header.size.resize(header.dim);
00101         for (unsigned i = 0; i < header.dim; ++i)
00102           file >> header.size[i];
00103 
00104         // Skipping endline.
00105         char c;
00106         file.get(c);
00107 
00108         // Value type name ?
00109         // WARNING: value type name limited to 255 characters...
00110         char value_type[255];
00111         file.getline(value_type, 255);
00112         header.value_type = value_type;
00113 
00114         trace::exiting("mln::io::dump::get_header");
00115         return header;
00116       }
00117 
00118 
00119 # endif // ! MLN_INCLUDE_ONLY
00120 
00121     } // end of namespace mln::io::dump
00122 
00123   } // end of namespace mln::io
00124 
00125 } // end of namespace mln
00126 
00127 #endif // ! MLN_IO_DUMP_GET_HEADER_HH
00128 

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