Changeset 353 for box/trunk/lib/common/ExcludeList.cpp
- Timestamp:
- 30/01/2006 20:04:53 (6 years ago)
- File:
-
- 1 edited
-
box/trunk/lib/common/ExcludeList.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/common/ExcludeList.cpp
r217 r353 18 18 #include "Utils.h" 19 19 #include "Configuration.h" 20 #include "Archive.h" 20 21 21 22 #include "MemLeakFindOn.h" … … 131 132 // Store in list of regular expressions 132 133 mRegex.push_back(pregex); 134 // Store in list of regular expression string for Serialize 135 mRegexStr.push_back(i->c_str()); 133 136 } 134 137 catch(...) … … 214 217 } 215 218 216 217 218 219 219 // -------------------------------------------------------------------------- 220 // 221 // Function 222 // Name: ExcludeList::Deserialize(Archive & rArchive) 223 // Purpose: Deserializes this object instance from a stream of bytes, using an Archive abstraction. 224 // 225 // Created: 2005/04/11 226 // 227 // -------------------------------------------------------------------------- 228 void ExcludeList::Deserialize(Archive & rArchive) 229 { 230 // 231 // 232 // 233 mDefinite.clear(); 234 235 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 236 // free regex memory 237 while(mRegex.size() > 0) 238 { 239 regex_t *pregex = mRegex.back(); 240 mRegex.pop_back(); 241 // Free regex storage, and the structure itself 242 ::regfree(pregex); 243 delete pregex; 244 } 245 246 mRegexStr.clear(); 247 #endif 248 249 // Clean up exceptions list 250 if(mpAlwaysInclude != 0) 251 { 252 delete mpAlwaysInclude; 253 mpAlwaysInclude = 0; 254 } 255 256 // 257 // 258 // 259 int64_t iCount = 0; 260 rArchive.Read(iCount); 261 262 if (iCount > 0) 263 { 264 for (int v = 0; v < iCount; v++) 265 { 266 // load each one 267 std::string strItem; 268 rArchive.Read(strItem); 269 mDefinite.insert(strItem); 270 } 271 } 272 273 // 274 // 275 // 276 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 277 rArchive.Read(iCount); 278 279 if (iCount > 0) 280 { 281 for (int v = 0; v < iCount; v++) 282 { 283 std::string strItem; 284 rArchive.Read(strItem); 285 286 // Allocate memory 287 regex_t* pregex = new regex_t; 288 289 try 290 { 291 // Compile 292 if(::regcomp(pregex, strItem.c_str(), 293 REG_EXTENDED | REG_NOSUB) != 0) 294 { 295 THROW_EXCEPTION(CommonException, 296 BadRegularExpression) 297 } 298 299 // Store in list of regular expressions 300 mRegex.push_back(pregex); 301 302 // Store in list of regular expression strings 303 // for Serialize 304 mRegexStr.push_back(strItem); 305 } 306 catch(...) 307 { 308 delete pregex; 309 throw; 310 } 311 } 312 } 313 #endif // PLATFORM_REGEX_NOT_SUPPORTED 314 315 // 316 // 317 // 318 int64_t aMagicMarker = 0; 319 rArchive.Read(aMagicMarker); 320 321 if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP) 322 { 323 // NOOP 324 } 325 else if (aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE) 326 { 327 mpAlwaysInclude = new ExcludeList; 328 if (!mpAlwaysInclude) 329 { 330 throw std::bad_alloc(); 331 } 332 333 mpAlwaysInclude->Deserialize(rArchive); 334 } 335 else 336 { 337 // there is something going on here 338 THROW_EXCEPTION(CommonException, Internal) 339 } 340 } 341 342 // -------------------------------------------------------------------------- 343 // 344 // Function 345 // Name: ExcludeList::Serialize(Archive & rArchive) 346 // Purpose: Serializes this object instance into a stream of bytes, using an Archive abstraction. 347 // 348 // Created: 2005/04/11 349 // 350 // -------------------------------------------------------------------------- 351 void ExcludeList::Serialize(Archive & rArchive) const 352 { 353 // 354 // 355 // 356 int64_t iCount = mDefinite.size(); 357 rArchive.Write(iCount); 358 359 for (std::set<std::string>::const_iterator i = mDefinite.begin(); 360 i != mDefinite.end(); i++) 361 { 362 rArchive.Write(*i); 363 } 364 365 // 366 // 367 // 368 #ifndef PLATFORM_REGEX_NOT_SUPPORTED 369 // don't even try to save compiled regular expressions, 370 // use string copies instead. 371 ASSERT(mRegex.size() == mRegexStr.size()); 372 373 iCount = mRegexStr.size(); 374 rArchive.Write(iCount); 375 376 for (std::vector<std::string>::const_iterator i = mRegexStr.begin(); 377 i != mRegexStr.end(); i++) 378 { 379 rArchive.Write(*i); 380 } 381 #endif // PLATFORM_REGEX_NOT_SUPPORTED 382 383 // 384 // 385 // 386 if (!mpAlwaysInclude) 387 { 388 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP; 389 rArchive.Write(aMagicMarker); 390 } 391 else 392 { 393 int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows 394 rArchive.Write(aMagicMarker); 395 396 mpAlwaysInclude->Serialize(rArchive); 397 } 398 }
Note: See TracChangeset
for help on using the changeset viewer.
