- Timestamp:
- 04/05/11 11:25:05 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Converter.cc
r10278 r10287 342 342 //! Size of the data block 343 343 //! 344 //! @param chunk 345 //! Size of the size of hex chunks seperted by a ':' in bytes 346 //! 344 347 //! @returns 345 348 //! The string 346 349 //! 347 string Converter::GetHex(const void *dat, int size)348 { 349 const char *ptr = reinterpret_cast<constchar *>(dat);350 string Converter::GetHex(const void *dat, size_t size, size_t chunk) 351 { 352 const unsigned char *ptr = reinterpret_cast<const unsigned char *>(dat); 350 353 351 354 ostringstream text; … … 353 356 text << hex; 354 357 355 for (int i=0; i<size; i++) 356 text << setw(2) << ptr[i] << " "; 358 for (size_t i=0; i<size; i++) 359 { 360 text << setw(2) << setfill('0') << (unsigned int)ptr[i]; 361 if ((i%chunk)==chunk-1) 362 text << ":"; 363 } 357 364 358 365 return text.str(); 359 366 } 367 360 368 361 369 // -------------------------------------------------------------------------- … … 493 501 494 502 // If the format is empty we are already done 495 if (empty()) 496 { 497 if (str.empty()) 498 { 499 wout << endl; 500 return vector<T>(); 501 } 502 503 if (empty() && str.empty()) 504 { 503 505 wout << endl; 504 wout << kRed << "Data string not empty as it ought to be!" << endl;505 506 return vector<T>(); 506 507 } … … 523 524 for (int j=0; j<i->second.first; j++) 524 525 { 525 cout << j << ": " << i->first.first->name() << endl;526 526 switch (i->first.first->name()[0]) 527 527 { … … 620 620 //! 621 621 template<class T> 622 T Converter::Get(const void *dat, int size) const622 T Converter::Get(const void *dat, size_t size) const 623 623 { 624 624 if (!valid()) … … 678 678 } 679 679 680 std::vector<boost::any> Converter::GetAny(const void *dat, int size) const680 std::vector<boost::any> Converter::GetAny(const void *dat, size_t size) const 681 681 { 682 682 return Get<vector<boost::any>>(dat, size); 683 683 } 684 684 685 std::vector<char> Converter::GetVector(const void *dat, int size) const685 std::vector<char> Converter::GetVector(const void *dat, size_t size) const 686 686 { 687 687 const string ref = GetString(dat, size); … … 694 694 } 695 695 696 string Converter::GetString(const void *dat, int size) const696 string Converter::GetString(const void *dat, size_t size) const 697 697 { 698 698 const string s = Get<string>(dat, size); -
trunk/FACT++/src/Converter.h
r10270 r10287 52 52 std::vector<T> Get(const std::string &str) const; 53 53 template <class T> 54 T Get(const void *d, int size) const;54 T Get(const void *d, size_t size) const; 55 55 56 56 … … 82 82 static FormatList Compile(const std::string &fmt, bool strict=false); 83 83 84 std::string GetString(const void *d, int size) const;85 std::vector<char> GetVector(const void *d, int size) const;86 std::vector<boost::any> GetAny(const void *d, int size) const;84 std::string GetString(const void *d, size_t size) const; 85 std::vector<char> GetVector(const void *d, size_t size) const; 86 std::vector<boost::any> GetAny(const void *d, size_t size) const; 87 87 88 88 std::vector<boost::any> GetAny(const std::string &str) const; 89 89 std::vector<char> GetVector(const std::string &str) const; 90 90 91 static std::string GetHex(const void *d, int size);91 static std::string GetHex(const void *d, size_t size, size_t chunk=1); 92 92 93 93 /*
Note:
See TracChangeset
for help on using the changeset viewer.