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