Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

  1. // stream i/o function header
  2. #ifndef _STREAMIO_H_
  3. #define _STREAMIO_H_
  4. #include <vector>
  5. typedef std::basic_string<BYTE> byte_string;
  6. typedef std::vector<tstring> string_vector;
  7. //
  8. // declare by-value stream operators
  9. //
  10. #define DeclareStreamOperators(type) \
  11. IStream& operator>> (IStream& stm, type& t); \
  12. IStream& operator<< (IStream& stm, type t);
  13. DeclareStreamOperators ( bool);
  14. DeclareStreamOperators ( char);
  15. DeclareStreamOperators (unsigned char);
  16. DeclareStreamOperators ( short);
  17. DeclareStreamOperators (unsigned short);
  18. DeclareStreamOperators ( int);
  19. DeclareStreamOperators (unsigned int);
  20. DeclareStreamOperators ( long);
  21. DeclareStreamOperators (unsigned long);
  22. //
  23. // declare by-ref stream operators
  24. //
  25. #define DeclareStreamOperatorsByRef(type) \
  26. IStream& operator>> (IStream& stm, type& t); \
  27. IStream& operator<< (IStream& stm, const type& t);
  28. DeclareStreamOperatorsByRef (CLSID);
  29. DeclareStreamOperatorsByRef (FILETIME);
  30. DeclareStreamOperatorsByRef (byte_string);
  31. DeclareStreamOperatorsByRef (tstring);
  32. //
  33. // operators for vector of objects
  34. //
  35. template <class T>
  36. IStream& operator<< (IStream& stm, std::vector<T>& vT)
  37. {
  38. stm << static_cast<long>(vT.size());
  39. std::vector<T>::iterator it = vT.begin();
  40. while (it != vT.end())
  41. {
  42. stm << *it;
  43. ++it;
  44. }
  45. return stm;
  46. }
  47. template <class T>
  48. IStream& operator>> (IStream& stm, std::vector<T>& vT)
  49. {
  50. long nItems;
  51. stm >> nItems;
  52. vT.reserve(nItems);
  53. for (long lItem = 0; lItem < nItems; lItem++)
  54. {
  55. T* pt = new T();
  56. if( pt )
  57. {
  58. vT.push_back(*pt);
  59. }
  60. T& rt = vT.back();
  61. stm >> rt;
  62. }
  63. return stm;
  64. }
  65. #endif //_STREAMIO_H_