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.

168 lines
3.4 KiB

  1. // Class to read csv files
  2. // Copyright (c) 2001 Microsoft Corporation
  3. // Jun 2001 lucios
  4. #ifndef CSVDSREADER_HPP
  5. #define CSVDSREADER_HPP
  6. #include <comdef.h>
  7. #include <set>
  8. #include <map>
  9. #include <list>
  10. using namespace std;
  11. typedef set <
  12. pair<String,long>,
  13. less< pair<String,long> > ,
  14. Burnslib::Heap::Allocator< pair<String,long> >
  15. > setOfObjects;
  16. typedef map
  17. <
  18. long,
  19. LARGE_INTEGER,
  20. less<long>,
  21. Burnslib::Heap::Allocator<LARGE_INTEGER>
  22. > mapOfOffsets;
  23. typedef map
  24. <
  25. String,
  26. long,
  27. less<String>,
  28. Burnslib::Heap::Allocator<long>
  29. > mapOfPositions;
  30. typedef map
  31. <
  32. String, // Property
  33. StringList, // Values
  34. less<String>,
  35. Burnslib::Heap::Allocator<StringList>
  36. > mapOfProperties;
  37. class CSVDSReader
  38. {
  39. private:
  40. mapOfOffsets localeOffsets; // locale x offsets
  41. mapOfPositions propertyPositions; // properties x position
  42. String fileName;
  43. HANDLE file; // csv file
  44. HRESULT parseProperties();
  45. HRESULT parseLocales(const long *locales);
  46. HRESULT
  47. getObjectLine(
  48. const long locale,
  49. const wchar_t *object,
  50. String &csvLine) const;
  51. HRESULT
  52. writeHeader(HANDLE fileOut) const;
  53. LARGE_INTEGER startPosition; // keeps position after first line
  54. // extract from line the value of all properties
  55. HRESULT
  56. getPropertyValues
  57. (
  58. const String &line,
  59. mapOfProperties &properties
  60. ) const;
  61. bool mutable canCallGetNext;
  62. public:
  63. CSVDSReader();
  64. // Sets the file pointer at the begining so that the next call to
  65. // getNextObject will retrieve the first object.
  66. HRESULT
  67. initializeGetNext() const;
  68. // Get first object in the csv file returning it's name, locale
  69. // and values for the properties in properties
  70. // Returns S_FALSE for no more objects
  71. HRESULT
  72. getNextObject
  73. (
  74. long &locale,
  75. String &object,
  76. mapOfProperties &properties
  77. ) const;
  78. // return all values for a property in a given locale/object
  79. HRESULT
  80. getCsvValues
  81. (
  82. const long locale,
  83. const wchar_t *object,
  84. const wchar_t *property,
  85. StringList &values
  86. ) const;
  87. // gets the csv value starting with inValue to outValue
  88. // returns S_FALSE if no value is found
  89. HRESULT
  90. getCsvValue
  91. (
  92. const long locale,
  93. const wchar_t *object,
  94. const wchar_t *property,
  95. const String &inValue,
  96. String &outValue
  97. ) const;
  98. HRESULT
  99. makeLocalesCsv(
  100. HANDLE fileOut,
  101. const long *locales) const;
  102. HRESULT
  103. makeObjectsCsv(
  104. HANDLE fileOut,
  105. const setOfObjects &objects) const;
  106. virtual ~CSVDSReader()
  107. {
  108. if (file!=INVALID_HANDLE_VALUE) CloseHandle(file);
  109. }
  110. HRESULT
  111. read(
  112. const wchar_t *fileName,
  113. const long *locales);
  114. const mapOfPositions& getProperties() const {return propertyPositions;};
  115. const String& getFileName() const {return fileName;}
  116. };
  117. #endif