HtmlBuilder.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef HTML_BUILDER_H
  21. #define HTML_BUILDER_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include <sstream>
  26. namespace HTML
  27. {
  28. class TAG
  29. {
  30. public:
  31. TAG( const std::string& tag, std::ostream& stream )
  32. : m_tag( tag ), m_stream( stream )
  33. {
  34. m_stream << "<" << m_tag;
  35. }
  36. virtual ~TAG()
  37. {
  38. m_stream << m_value.str();
  39. m_stream << "</" << m_tag << ">";
  40. }
  41. TAG& text()
  42. { m_stream << ">"; return *this; }
  43. TAG& text( const std::string& value )
  44. { m_value << value; text(); return *this; }
  45. TAG& text( int value )
  46. { m_value << value; text(); return *this; }
  47. private:
  48. std::string m_tag;
  49. std::stringstream m_value;
  50. protected:
  51. std::ostream& m_stream;
  52. };
  53. class SPECIAL
  54. {
  55. public:
  56. SPECIAL( const std::string& value, std::ostream& stream )
  57. {
  58. stream << "&" << value << ";";
  59. }
  60. };
  61. class A : public TAG
  62. {
  63. public:
  64. A( std::ostream& stream )
  65. : TAG( "A", stream ) {}
  66. A& href( const std::string& value )
  67. { m_stream << " href='" << value << "'"; return *this; }
  68. };
  69. class BODY : public TAG
  70. {
  71. public:
  72. BODY( std::ostream& stream )
  73. : TAG( "BODY", stream ) {}
  74. };
  75. class BR : public TAG
  76. {
  77. public:
  78. BR( std::ostream& stream )
  79. : TAG( "BR", stream ) {}
  80. };
  81. class CAPTION : public TAG
  82. {
  83. public:
  84. CAPTION( std::ostream& stream )
  85. : TAG( "CAPTION", stream ) {}
  86. };
  87. class CENTER : public TAG
  88. {
  89. public:
  90. CENTER( std::ostream& stream )
  91. : TAG( "CENTER", stream ) {}
  92. };
  93. class EM : public TAG
  94. {
  95. public:
  96. EM( std::ostream& stream )
  97. : TAG( "EM", stream ) {}
  98. };
  99. class H1 : public TAG
  100. {
  101. public:
  102. H1( std::ostream& stream )
  103. : TAG( "H1", stream ) {}
  104. };
  105. class H2 : public TAG
  106. {
  107. public:
  108. H2( std::ostream& stream )
  109. : TAG( "H2", stream ) {}
  110. };
  111. class HEAD : public TAG
  112. {
  113. public:
  114. HEAD( std::ostream& stream )
  115. : TAG( "HEAD", stream ) {}
  116. };
  117. class HR : public TAG
  118. {
  119. public:
  120. HR( std::ostream& stream )
  121. : TAG( "HR", stream ) {}
  122. };
  123. const char* NBSP = "&nbsp;";
  124. class TABLE : public TAG
  125. {
  126. public:
  127. TABLE( std::ostream& stream )
  128. : TAG( "TABLE", stream ) {}
  129. TABLE& border( int value )
  130. { m_stream << " border='" << value << "'"; return *this; }
  131. TABLE& cellspacing( int value )
  132. { m_stream << " cellspacing='" << value << "'"; return *this; }
  133. TABLE& width( int value )
  134. { m_stream << " width='" << value << "%'"; return *this; }
  135. };
  136. class TD : public TAG
  137. {
  138. public:
  139. TD( std::ostream& stream )
  140. : TAG( "TD", stream ) {}
  141. TD& align( const std::string& value )
  142. { m_stream << " align='" << value << "'"; return *this; }
  143. };
  144. class TITLE : public TAG
  145. {
  146. public:
  147. TITLE( std::ostream& stream )
  148. : TAG( "TITLE", stream ) {}
  149. };
  150. class TR : public TAG
  151. {
  152. public:
  153. TR( std::ostream& stream )
  154. : TAG( "TR", stream ) {}
  155. };
  156. }
  157. #endif