Changeset 11487 for trunk/Mars
- Timestamp:
- 07/20/11 17:58:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mbase/MFits.h
r11461 r11487 294 294 Table fTable; 295 295 296 map<void*, Table::Column> fAddresses; 296 typedef pair<void*, Table::Column> Address; 297 typedef vector<Address> Addresses; 298 //map<void*, Table::Column> fAddresses; 299 Addresses fAddresses; 297 300 298 301 vector<char> fBufferRow; … … 419 422 } 420 423 424 template<size_t N> 425 void revcpy(char *dest, const char *src, int num) 426 { 427 const char *end = src + num*N; 428 for (const char *ptr = src; ptr<end; ptr+=N, dest+=N) 429 reverse_copy(ptr, ptr+N, dest); 430 } 431 421 432 bool GetRow(size_t row) 422 433 { … … 425 436 return good(); 426 437 427 for (map<void*,Table::Column>::const_iterator it=fAddresses.begin(); 428 it!=fAddresses.end(); it++) 438 for (Addresses::const_iterator it=fAddresses.begin(); it!=fAddresses.end(); it++) 429 439 { 430 440 const Table::Column &c = it->second; 431 441 432 442 const char *src = fBufferRow.data() + c.offset; 433 const char *end = src + c.num*c.size;434 435 443 char *dest = reinterpret_cast<char*>(it->first); 436 for (const char *ptr = src; ptr<end; ptr+=c.size, dest+=c.size) 437 reverse_copy(ptr, ptr+c.size, dest); 444 445 // Let the compiler do some optimization by 446 // knowing the we only have 1, 2, 4 and 8 447 switch (c.size) 448 { 449 case 1: memcpy (dest, src, c.num*c.size); break; 450 case 2: revcpy<2>(dest, src, c.num); break; 451 case 4: revcpy<4>(dest, src, c.num); break; 452 case 8: revcpy<8>(dest, src, c.num); break; 453 } 438 454 } 439 455 … … 452 468 } 453 469 470 static bool Compare(const Address &p1, const Address &p2) 471 { 472 return p1.first>p2.first; 473 } 474 454 475 template<typename T> 455 476 bool SetPtrAddress(const string &name, T *ptr, size_t cnt) … … 480 501 // gLog << warn << "SetPtrAddress('" << name << "') - Pointer " << ptr << " already assigned." << endl; 481 502 482 fAddresses[ptr] = fTable.cols[name]; 483 503 //fAddresses[ptr] = fTable.cols[name]; 504 fAddresses.push_back(make_pair(ptr, fTable.cols[name])); 505 sort(fAddresses.begin(), fAddresses.end(), Compare); 484 506 return true; 485 507 } … … 514 536 // gLog << warn << "SetPtrAddress('" << name << "') - Pointer " << ptr << " already assigned." << endl; 515 537 516 fAddresses[ptr] = fTable.cols[name]; 517 538 //fAddresses[ptr] = fTable.cols[name]; 539 fAddresses.push_back(make_pair(ptr, fTable.cols[name])); 540 sort(fAddresses.begin(), fAddresses.end(), Compare); 518 541 return true; 519 542 } 520 543 544 bool HasKey(const string &key) const { return fTable.HasKey(key); } 521 545 int64_t GetInt(const string &key) const { return fTable.Get<int64_t>(key); } 522 546 uint64_t GetUInt(const string &key) const { return fTable.Get<uint64_t>(key); }
Note:
See TracChangeset
for help on using the changeset viewer.