00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef _MSC_VER
00014 # pragma warning(disable:4786) // >255 characters in debug information
00015 #endif
00016
00017 #include <iostream>
00018 #include <vector>
00019
00020 #include "SIO_recordManager.h"
00021 #include "SIO_blockManager.h"
00022 #include "SIO_block.h"
00023 #include "SIO_functions.h"
00024
00025
00026
00027
00028 blockMap_c* SIO_blockManager::blockMap = NULL;
00029 SIO_verbosity SIO_blockManager::verbosity = SIO_SILENT;
00030
00031
00032
00033
00034 SIO_block* SIO_blockManager::add
00035 (
00036 SIO_block* block
00037 )
00038 {
00039
00040
00041
00042
00043 std::string
00044 *s_name;
00045
00046 std::pair< blockMap_i, bool >
00047 status;
00048
00049 const char
00050 *i_name;
00051
00052
00053
00054
00055 s_name = block->getName();
00056 i_name = s_name->c_str();
00057 if( !SIO_functions::validateName( i_name ) )
00058 {
00059 if( verbosity >= SIO_ERRORS )
00060 {
00061 std::cout << "SIO: [Block Manager] "
00062 << "Invalid block name"
00063 << i_name
00064 << std::endl;
00065 }
00066 return( NULL );
00067 }
00068
00069
00070
00071
00072 if( blockMap == NULL )
00073 blockMap = new blockMap_c;
00074
00075
00076
00077
00078 std::pair< std::string const, SIO_block* >
00079 entry( *s_name, block );
00080
00081
00082
00083
00084
00085
00086 status = blockMap->insert( entry );
00087 if( !status.second )
00088 {
00089 if( verbosity >= SIO_ERRORS )
00090 {
00091 std::cout << "SIO: [Block Manager] Block"
00092 << i_name
00093 << "not added (already exists)"
00094 << std::endl;
00095 }
00096 return( NULL );
00097 }
00098
00099 if( verbosity >= SIO_ALL )
00100 {
00101 std::cout << "SIO: [Block Manager] Added block "
00102 << i_name
00103 << std::endl;
00104 }
00105
00106
00107
00108
00109 return (status.first)->second;
00110 }
00111
00112
00113
00114
00115 SIO_block* SIO_blockManager::get
00116 (
00117 const char* i_name
00118 )
00119 {
00120
00121
00122
00123
00124 if( blockMap != NULL )
00125 {
00126 blockMap_i
00127 iter;
00128
00129 std::string
00130 s_name = i_name;
00131
00132 if( (iter = blockMap->find( s_name )) != blockMap->end() )
00133 {
00134 if( verbosity >= SIO_ALL )
00135 {
00136 std::cout << "SIO: [Block Manager] Block "
00137 << i_name
00138 << " is defined (pointer returned)"
00139 << std::endl;
00140 }
00141 return( iter->second );
00142 }
00143 }
00144
00145 if( verbosity >= SIO_ALL )
00146 {
00147 std::cout << "SIO: [Block Manager] Block "
00148 << i_name
00149 << " has not been defined"
00150 << std::endl;
00151 }
00152
00153
00154
00155
00156 return( NULL );
00157 }
00158
00159
00160
00161
00162 SIO_verbosity SIO_blockManager::getVerbosity() { return( verbosity ); }
00163
00164
00165
00166
00167
00168
00169 void SIO_blockManager::clear() {
00170
00171 blockMap_i iter;
00172 std::vector<std::string> blockNames ;
00173
00174 if( blockMap == 0 ) return ;
00175
00176
00177
00178 for(iter = blockMap->begin() ; iter != blockMap->end() ; iter++) {
00179 blockNames.push_back( iter->first ) ;
00180 }
00181
00182 for(int i=0 ;i<blockNames.size() ;i++){
00183 delete (*blockMap)[ blockNames[i] ] ;
00184 }
00185
00186 delete blockMap;
00187 blockMap = NULL;
00188
00189 }
00190
00191
00192
00193
00194 unsigned int SIO_blockManager::remove
00195 (
00196 const char* i_name
00197 )
00198 {
00199
00200
00201
00202
00203 if( blockMap != NULL )
00204 {
00205 blockMap_i
00206 iter;
00207
00208 std::string
00209 s_name = i_name;
00210
00211 if( (iter = blockMap->find( s_name )) != blockMap->end() )
00212 {
00213
00214
00215
00216
00217
00218 SIO_recordManager::disconnect( i_name );
00219
00220
00221
00222
00223
00224 blockMap->erase( iter );
00225
00226 if( verbosity >= SIO_ALL )
00227 {
00228 std::cout << "SIO: [Block Manager] Removed block "
00229 << i_name
00230 << std::endl;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239 return( SIO_BLOCK_SUCCESS );
00240 }
00241 }
00242
00243 if( verbosity >= SIO_ERRORS )
00244 {
00245 std::cout << "SIO: [Block Manager] Cannot remove block "
00246 << i_name
00247 << " (it was never added)"
00248 << std::endl;
00249 }
00250
00251
00252
00253
00254 return( SIO_BLOCK_NOTFOUND );
00255 }
00256
00257
00258
00259
00260 unsigned int SIO_blockManager::remove
00261 (
00262 SIO_block* block
00263 )
00264 { return( remove( block->getName()->c_str() ) ); }
00265
00266
00267
00268
00269 SIO_verbosity SIO_blockManager::setVerbosity
00270 (
00271 SIO_verbosity i_verb
00272 )
00273 { SIO_verbosity o_verb = verbosity; verbosity = i_verb; return( o_verb ); }