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