fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct lit {
  5. const char *str;
  6. lit(const char *str) : str(str) {}
  7. };
  8. std::istream& operator>>(std::istream& in, lit l)
  9. {
  10. char c; in >> c;
  11. while (in && *l.str) {
  12. if (*l.str != c) in.setstate(std::ios_base::failbit);
  13. if (isspace(*++l.str))
  14. in >> c, l.str++;
  15. else
  16. c = in.get();
  17. }
  18. return in;
  19. }
  20.  
  21. struct HkmHeader {
  22. std::string version;
  23. int numNodes;
  24. int numLeaves;
  25. };
  26.  
  27. struct HkmParams {
  28. int branchFactor;
  29. int maxTreeDepth;
  30. int desiredNumSamplesPerCluster;
  31. int numClusteringRuns;
  32. int standardization;
  33. int meanSubtraction;
  34. int noInternalLeafStats;
  35. int termCritMaxCount;
  36. float termCritEpsilon;
  37. int termCritType;
  38. };
  39.  
  40. struct HkmFile {
  41. HkmHeader header;
  42. HkmParams params;
  43. };
  44.  
  45. std::istream& operator>>(std::istream& in, HkmHeader& f)
  46. {
  47. return in >> lit("class HkmTree Format:") >> f.version
  48. >> lit("#nodes:") >> f.numNodes
  49. >> lit("#leaves:") >> f.numLeaves;
  50. }
  51.  
  52. std::istream& operator>>(std::istream& in, HkmParams& f)
  53. {
  54. int dummy;
  55. return in >> lit("<HkmParams")
  56. >> lit("branchFactor:") >> f.branchFactor
  57. >> lit("maxTreeDepth:") >> f.maxTreeDepth
  58. >> lit("desiredNumSamplesPerCluster:") >> f.desiredNumSamplesPerCluster
  59. >> lit("minNumSamplesPerCluster:") >> dummy
  60. >> lit("numClusteringRuns:") >> f.numClusteringRuns
  61. >> lit("standardization:") >> f.standardization
  62. >> lit("meanSubtraction:") >> f.meanSubtraction
  63. >> lit("noInternalLeafStats:") >> f.noInternalLeafStats
  64. >> lit("termCrit.maxCount:") >> f.termCritMaxCount
  65. >> lit("termCrit.epsilon:") >> f.termCritEpsilon
  66. >> lit("termCrit.type:") >> f.termCritType
  67. >> lit(">");
  68. }
  69.  
  70. std::istream& operator>>(std::istream& in, HkmFile& f)
  71. {
  72. return in >> f.header >> f.params;
  73. }
  74.  
  75.  
  76. std::ostream& operator<<(std::ostream& os, HkmParams const& f)
  77. {
  78. return os << "<HkmParams"
  79. << "\n branchFactor: " << f.branchFactor
  80. << "\n maxTreeDepth: " << f.maxTreeDepth
  81. << "\n desiredNumSamplesPerCluster: " << f.desiredNumSamplesPerCluster
  82. << "\n minNumSamplesPerCluster: " << "-1" // ?
  83. << "\n numClusteringRuns: " << f.numClusteringRuns
  84. << "\n standardization: " << f.standardization
  85. << "\n meanSubtraction: " << f.meanSubtraction
  86. << "\n noInternalLeafStats: " << f.noInternalLeafStats
  87. << "\n termCrit.maxCount: " << f.termCritMaxCount
  88. << "\n termCrit.epsilon: " << f.termCritEpsilon
  89. << "\n termCrit.type: " << f.termCritType
  90. << "\n>";
  91. }
  92. std::ostream& operator<<(std::ostream& os, HkmHeader const& p)
  93. {
  94. return os << "version: " << p.version
  95. << "\n#numNodes: " << p.numNodes
  96. << "\n#numLeaves: " << p.numLeaves;
  97. }
  98. std::ostream& operator<<(std::ostream& os, HkmFile const& f)
  99. {
  100. return os << f.header << "\n\n" << f.params;
  101. }
  102.  
  103. int main()
  104. {
  105. HkmFile f;
  106. if (std::cin >> f)
  107. std::cout << f;
  108. }
  109.  
Success #stdin #stdout 0s 2856KB
stdin
lass HkmTree Format: v2.1 
#nodes:  9 
#leaves: 8 
  
<HkmParams 
    branchFactor:                8 
    maxTreeDepth:                1 
    desiredNumSamplesPerCluster: 15000000 
    minNumSamplesPerCluster:     15000000 
    numClusteringRuns:           1 
    standardization:             0 
    meanSubtraction:             0 
    noInternalLeafStats:         0 
    termCrit.maxCount:           1000 
    termCrit.epsilon:            1e-006 
    termCrit.type:               3 
>	
stdout
Standard output is empty