/*************************************************************************** * Copyright (C) 2005 by Nicolas PASCAL * * nicolas.pascal@icare.univ-lille1.fr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef HDFFILEMETADATA_H #define HDFFILEMETADATA_H #define TAB_INCREMENT " " #include #include #include #include #include #include "Hdf_file.hpp" #include "file_tools.h" #include "tools.h" #include "hdfmetadatanode.h" /** Give methods to read and access to the metadata of an HDF file. For that, build a tree with those metadata. @author Nicolas PASCAL */ class HDFFileMetaData{ Hdf_file *hdf_file; ofstream output_file; string output_filename; vector input_file_lines; HDFMetadataNode* root_node; bool stand_alone_read; // used to know if the Hdf_file has been initialized by this class, or outside of it. If init from outside, at the destruction of the object, the Hdf_file musn't be deleted bool persistent_xml_file; static string xml_header; string tab_increment; /** open output file, and write xml header */ void init_output_file( const string _output_filename="", const bool overwrite=false, const bool create_temp_file=true ); void write_xml_file( const string _output_filename="", const bool overwrite=false, const bool create_temp_file=true ); void parse_string_to_xml(vector ::iterator start,vector ::iterator end, int rank=1); HDFMetadataNode* parse_string(vector ::iterator start,vector ::iterator end); vector ::iterator find_end_tag(vector ::iterator start,const string &tag, const string &val); void extract_tag_val(string &tag, string &val,vector< string >::iterator &line); void load_input_file_metadata(); void load_metadata_named(const char *meta_name = "coremetadata"); void init_input_hdf_file(const char * input_file_name = NULL); void init(); void parse_xml_file(); const HDFMetadataNode::value_type get_val_type(const string &s); const HDFMetadataNode::value_type get_elt_type(const string &s_val); // elt is a stand alone value or an array element const HDFMetadataNode::value_type get_array_type(const string &s_val); void build_array_value(void* val, const string &s_val); void build_tree(); void view_node(const HDFMetadataNode* node, const int rank = 0); /** * used to recursively search for a node in the metadata tree * @param node * @param val the value to write (must be of the good type) * @param tag_name * @return true if found */ const bool get_node_value( HDFMetadataNode* node, void* val, const string & tag_name); const bool get_node_value_string( HDFMetadataNode* node, string &val, const string & tag_name); public: /************************************* *** CONSTRUCTORS/DESTRUCTORS *** *************************************/ /** * Constructor * @param _hdf_file a pointer to an hdf file instance */ HDFFileMetaData(const Hdf_file *_hdf_file = NULL); /** * Constructor * @param _hdf_file_name the hdf file to read */ HDFFileMetaData(const char *_hdf_file_name = NULL); /** * Constructor * @param _hdf_file_name the hdf file to read */ HDFFileMetaData(const std::string &_hdf_file_name = NULL); /** Destructor */ ~HDFFileMetaData(); /** Dump the metadata to an XML file @param output_filename the name of the output xml file. If not given, add the extension, and if NULL, build the output name with the pattern : "input_file_without_extension"+".xml" @param overwrite when true, if the output file already exists, overwrite it. (and so, if false, don't) */ void to_xml(const char* output_filename = NULL, const bool overwrite = false); /** Permit to retrieve a metadata value using a tag_name. It returns the value of the first crossed tag with this name. @param tag_name the tag name of the node @param val the searched value, or NULL in case of problem */ void get_value(void* val, const char * tag_name = "GRANULEID"); /** * find the first node in the metadata tree having the tag "tag_name". In fact, it finds the first leaf that is child of the node called tag_name. * @param val the value to write (must be of the good type) * @param tag_name the tag we are searching for the value * @return true if the value was found */ const bool get_tree_value( void* val, const string & tag_name); /** * find the first node in the metadata tree having the tag "tag_name". In fact, it finds the first leaf that is child of the node called tag_name. * @param val the value to write * @param tag_name the tag we are searching for the value * @return true if the value was found */ const bool get_tree_value_string( string &val, const string & tag_name); /** print out the build tree */ void view_tree(); }; #endif