/*************************************************************************** * 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. * ***************************************************************************/ #include "hdfmetadatanode.h" HDFMetadataNode* HDFMetadataNode::get_next_sibling() const { return next_sibling; } void HDFMetadataNode::set_next_sibling(HDFMetadataNode* val) { next_sibling = val; } HDFMetadataNode::HDFMetadataNode( void * _value, HDFMetadataNode::value_type _typecode) { value=_value; typecode=_typecode; next_sibling=0; child=0; } HDFMetadataNode::HDFMetadataNode( ) { value=0; typecode=HDFMetadataNode::BAD; next_sibling=0; child=0; } HDFMetadataNode* HDFMetadataNode::get_child() const { return child; } void HDFMetadataNode::set_child(HDFMetadataNode* val) { child = val; } HDFMetadataNode::~ HDFMetadataNode( ) { switch (typecode) { case HDFMetadataNode::INTEGER: if (value!=NULL) delete static_cast(value); break; case HDFMetadataNode::FLOAT: if (value!=NULL) delete static_cast(value); break; case HDFMetadataNode::STRING: if (value!=NULL) delete static_cast(value); break; case HDFMetadataNode::ARRAY_INTEGER: if (value!=NULL) delete static_cast< vector* >(value); break; case HDFMetadataNode::ARRAY_FLOAT: if (value!=NULL) delete static_cast*>(value); break; case HDFMetadataNode::ARRAY_STRING: if (value!=NULL) delete static_cast*>(value); break; default: break; } delete next_sibling; next_sibling=NULL; delete child; child=NULL; } void HDFMetadataNode::print_val() const { if (value!=NULL) { if (typecode==HDFMetadataNode::INTEGER) { cout<<(*static_cast(value)); } else if (typecode==HDFMetadataNode::FLOAT) { cout<<(*static_cast(value)); } else if (typecode==HDFMetadataNode::STRING) { cout<<(*static_cast(value)); } else if (typecode==HDFMetadataNode::ARRAY_INTEGER) { vector *v= static_cast< vector *>(value); for (vector ::iterator i = v->begin() ; i!=v->end();++i) cout<<(*i)<<","; } else if (typecode==HDFMetadataNode::ARRAY_FLOAT) { vector *v= static_cast< vector *>(value); for (vector ::iterator i = v->begin() ; i!=v->end();++i) cout<<(*i)<<","; } else if (typecode==HDFMetadataNode::ARRAY_STRING) { vector *v= static_cast< vector *>(value); for (vector ::iterator i = v->begin() ; i!=v->end();++i) cout<<(*i)<<","; } } } const bool HDFMetadataNode::is_leaf() const { return (next_sibling==NULL && child==NULL); } void HDFMetadataNode::read_node_value(void* val) { if (value!=NULL && val!=NULL) { if (typecode==HDFMetadataNode::INTEGER) { (*static_cast(val))=(*static_cast(value)); } else if (typecode==HDFMetadataNode::FLOAT) { (*static_cast(val))=(*static_cast(value)); } else if (typecode==HDFMetadataNode::STRING) { (*static_cast(val))=(*static_cast(value)); } else if (typecode==HDFMetadataNode::ARRAY_INTEGER) { vector *v_src= static_cast< vector *>(value); vector *v_dest= static_cast< vector *>(val); if (v_dest->capacity()size()) v_dest->reserve(v_src->size()); *v_dest=*v_src; } else if (typecode==HDFMetadataNode::ARRAY_FLOAT) { vector *v_src= static_cast< vector *>(value); vector *v_dest= static_cast< vector *>(val); if (v_dest->capacity()size()) v_dest->reserve(v_src->size()); *v_dest=*v_src; } else if (typecode==HDFMetadataNode::ARRAY_STRING) { vector *v_src= static_cast< vector *>(value); vector *v_dest= static_cast< vector *>(val); if (v_dest->capacity()size()) v_dest->reserve(v_src->size()); *v_dest=*v_src; } } } HDFMetadataNode::value_type HDFMetadataNode::get_typecode() const { if (typecode!=HDFMetadataNode::INTEGER && typecode!=HDFMetadataNode::FLOAT && typecode!=HDFMetadataNode::STRING && typecode!=HDFMetadataNode::ARRAY_INTEGER && typecode!=HDFMetadataNode::ARRAY_FLOAT && typecode!=HDFMetadataNode::ARRAY_STRING){ return HDFMetadataNode::BAD; } return typecode; } void* HDFMetadataNode::get_value() const { return value; }