bitunion.hh (12625:c0cf272e0456) | bitunion.hh (12631:d48fc4cce6eb) |
---|---|
1/* 2 * Copyright (c) 2007-2008 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 405 unchanged lines hidden (view full) --- 414 return hash<BitUnionBaseType<T> >::operator()(val); 415 } 416 }; 417} 418 419 420namespace BitfieldBackend 421{ | 1/* 2 * Copyright (c) 2007-2008 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 405 unchanged lines hidden (view full) --- 414 return hash<BitUnionBaseType<T> >::operator()(val); 415 } 416 }; 417} 418 419 420namespace BitfieldBackend 421{ |
422namespace 423{ | 422 |
424 template<typename T> | 423 template<typename T> |
425 std::ostream & | 424 static inline std::ostream & |
426 bitfieldBackendPrinter(std::ostream &os, const T &t) 427 { 428 os << t; 429 return os; 430 } 431 432 //Since BitUnions are generally numerical values and not character codes, 433 //these specializations attempt to ensure that they get cast to integers 434 //of the appropriate type before printing. 435 template <> | 425 bitfieldBackendPrinter(std::ostream &os, const T &t) 426 { 427 os << t; 428 return os; 429 } 430 431 //Since BitUnions are generally numerical values and not character codes, 432 //these specializations attempt to ensure that they get cast to integers 433 //of the appropriate type before printing. 434 template <> |
436 std::ostream & | 435 inline std::ostream & |
437 bitfieldBackendPrinter(std::ostream &os, const char &t) 438 { 439 os << (const int)t; 440 return os; 441 } 442 443 template <> | 436 bitfieldBackendPrinter(std::ostream &os, const char &t) 437 { 438 os << (const int)t; 439 return os; 440 } 441 442 template <> |
444 std::ostream & | 443 inline std::ostream & |
445 bitfieldBackendPrinter(std::ostream &os, const unsigned char &t) 446 { 447 os << (const unsigned int)t; 448 return os; 449 } 450} | 444 bitfieldBackendPrinter(std::ostream &os, const unsigned char &t) 445 { 446 os << (const unsigned int)t; 447 return os; 448 } 449} |
451} | |
452 453//A default << operator which casts a bitunion to its underlying type and 454//passes it to BitfieldBackend::bitfieldBackendPrinter. 455template <typename T> 456std::ostream & 457operator << (std::ostream &os, const BitUnionType<T> &bu) 458{ 459 return BitfieldBackend::bitfieldBackendPrinter( 460 os, (BitUnionBaseType<T>)bu); 461} 462 463#endif // __BASE_BITUNION_HH__ | 450 451//A default << operator which casts a bitunion to its underlying type and 452//passes it to BitfieldBackend::bitfieldBackendPrinter. 453template <typename T> 454std::ostream & 455operator << (std::ostream &os, const BitUnionType<T> &bu) 456{ 457 return BitfieldBackend::bitfieldBackendPrinter( 458 os, (BitUnionBaseType<T>)bu); 459} 460 461#endif // __BASE_BITUNION_HH__ |