2012-07-19 18:26:47 +00:00
/********************************************************************************
2011-07-25 14:56:40 +00:00
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell 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 *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
2011-09-03 13:58:59 +00:00
# include <iostream>
2015-01-10 22:13:52 +00:00
# include <algorithm>
2011-07-25 14:56:40 +00:00
2015-01-05 14:11:42 +00:00
# include "../ifcparse/IfcException.h"
# include "IfcUtil.h"
2014-05-04 14:42:55 +00:00
void IfcEntityList : : push ( IfcUtil : : IfcBaseClass * l ) {
2011-07-25 14:56:40 +00:00
if ( l ) ls . push_back ( l ) ;
}
2014-05-04 14:42:55 +00:00
void IfcEntityList : : push ( const IfcEntityList : : ptr & l ) {
2011-07-25 14:56:40 +00:00
for ( it i = l - > begin ( ) ; i ! = l - > end ( ) ; + + i ) {
if ( * i ) ls . push_back ( * i ) ;
}
}
2015-01-10 22:13:52 +00:00
unsigned int IfcEntityList : : size ( ) const { return ( unsigned int ) ls . size ( ) ; }
2011-07-25 14:56:40 +00:00
IfcEntityList : : it IfcEntityList : : begin ( ) { return ls . begin ( ) ; }
IfcEntityList : : it IfcEntityList : : end ( ) { return ls . end ( ) ; }
2014-05-04 14:42:55 +00:00
IfcUtil : : IfcBaseClass * IfcEntityList : : operator [ ] ( int i ) {
2011-07-25 14:56:40 +00:00
return ls [ i ] ;
}
2015-01-10 22:13:52 +00:00
bool IfcEntityList : : contains ( IfcUtil : : IfcBaseClass * instance ) const {
return std : : find ( ls . begin ( ) , ls . end ( ) , instance ) ! = ls . end ( ) ;
2011-07-25 14:56:40 +00:00
}
2015-01-05 14:11:42 +00:00
unsigned int IfcUtil : : IfcBaseType : : getArgumentCount ( ) const { return 1 ; }
Argument * IfcUtil : : IfcBaseType : : getArgument ( unsigned int i ) const { return entity - > getArgument ( i ) ; }
const char * IfcUtil : : IfcBaseType : : getArgumentName ( unsigned int i ) const { if ( i = = 0 ) { return " wrappedValue " ; } else { throw IfcParse : : IfcException ( " argument out of range " ) ; } }
2012-08-11 13:24:08 +00:00
void Logger : : SetOutput ( std : : ostream * l1 , std : : ostream * l2 ) {
log1 = l1 ;
log2 = l2 ;
if ( ! log2 ) {
log2 = & log_stream ;
}
}
2014-05-04 14:42:55 +00:00
void Logger : : Message ( Logger : : Severity type , const std : : string & message , IfcAbstractEntity * entity ) {
2012-08-11 13:24:08 +00:00
if ( log2 & & type > = verbosity ) {
( * log2 ) < < " [ " < < severity_strings [ type ] < < " ] " < < message < < std : : endl ;
if ( entity ) ( * log2 ) < < entity - > toString ( ) < < std : : endl ;
}
}
void Logger : : Status ( const std : : string & message , bool new_line ) {
if ( log1 ) {
( * log1 ) < < message ;
if ( new_line ) ( * log1 ) < < std : : endl ;
else ( * log1 ) < < std : : flush ;
}
}
2013-03-24 10:48:39 +00:00
void Logger : : ProgressBar ( int progress ) {
if ( log1 ) {
Status ( " \r [ " + std : : string ( progress , ' # ' ) + std : : string ( 50 - progress , ' ' ) + " ] " , false ) ;
}
}
2012-08-11 13:24:08 +00:00
std : : string Logger : : GetLog ( ) {
return log_stream . str ( ) ;
}
void Logger : : Verbosity ( Logger : : Severity v ) { verbosity = v ; }
Logger : : Severity Logger : : Verbosity ( ) { return verbosity ; }
std : : ostream * Logger : : log1 = 0 ;
std : : ostream * Logger : : log2 = 0 ;
std : : stringstream Logger : : log_stream ;
Logger : : Severity Logger : : verbosity = Logger : : LOG_NOTICE ;
2015-01-05 14:11:42 +00:00
const char * Logger : : severity_strings [ ] = { " Notice " , " Warning " , " Error " } ;
static const char * const argument_type_string [ ] = {
" NULL " ,
" DERIVED " ,
" INT " ,
" BOOL " ,
" DOUBLE " ,
" STRING " ,
" VECTOR_INT " ,
" VECTOR_DOUBLE " ,
" VECTOR_STRING " ,
" ENUMERATION " ,
" ENTITY " ,
" ENTITY_LIST " ,
" ENTITY_LIST_LIST " ,
" UNKNOWN "
} ;
const char * IfcUtil : : ArgumentTypeToString ( ArgumentType argument_type ) {
return argument_type_string [ static_cast < int > ( argument_type ) ] ;
}