Guest User

Untitled

a guest
Aug 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. cgicc: multi-levels of same element
  2. <ul>
  3. <li>
  4. <a href="#" ><span>Main 1</span></a>
  5. <ul>
  6. <li><a href="ref1-1" ><span>Sub 1</span></a></li>
  7. <li><a href="ref1-2" ><span>Sub 2</span></a></li>
  8. <li><a href="ref1-3" ><span>Sub 3</span></a></li>
  9. </ul>
  10. </li>
  11. <li>
  12. <a href="#" ><span>Main 2</span></a>
  13. <ul>
  14. <li><a href="ref2-1" ><span>Sub 1</span></a></li>
  15. <li><a href="ref2-2" ><span>Sub 2</span></a></li>
  16. <li><a href="ref2-3" ><span>Sub 3</span></a></li>
  17. </ul>
  18. </li>
  19. </ul>
  20.  
  21. cout << ul() << endl;
  22. cout << li() << endl;
  23. cout << a("Main 1").set("href", "#") << endl;
  24. cout << ul() << endl; // <-- must fail here!
  25. cout << li(a("Sub 1").set("href", "ref1-1")) << endl;
  26. cout << li(a("Sub 2").set("href", "ref1-2")) << endl;
  27. cout << li(a("Sub 3").set("href", "ref1-3")) << endl;
  28. cout << ul() << endl;
  29. cout << li() << endl;
  30. cout << li() << endl;
  31. cout << a("Main 2").set("href", "#") << endl;
  32. cout << ul() << endl;
  33. cout << li(a("Sub 1").set("href", "ref2-1")) << endl;
  34. cout << li(a("Sub 2").set("href", "ref2-2")) << endl;
  35. cout << li(a("Sub 3").set("href", "ref2-3")) << endl;
  36. cout << ul() << endl;
  37. cout << li() << endl;
  38. cout << ul() << endl;
  39.  
  40. #include <cgicc/HTMLElement.h>
  41. #include <cgicc/HTMLAttributeList.h>
  42.  
  43. template<class Tag>
  44. class HTMLSimpleElement : public cgicc::HTMLElement
  45. {
  46. public:
  47. HTMLSimpleElement() : HTMLElement(0, 0, 0, EElementType(-1))
  48. {}
  49.  
  50. HTMLSimpleElement(const cgicc::HTMLAttributeList& attributes) : HTMLElement(&attributes, 0, 0, EElementType(-1))
  51. {}
  52.  
  53. virtual ~HTMLSimpleElement() {}
  54.  
  55. virtual inline HTMLElement* clone() const
  56. { return new HTMLSimpleElement<Tag>(*this); }
  57.  
  58. virtual inline const char* getName() const
  59. { return Tag::getName(); }
  60.  
  61. virtual void render(std::ostream& out) const
  62. {
  63. const cgicc::HTMLAttributeList* attributes = getAttributes();
  64.  
  65. out << '<' << getName();
  66.  
  67. if (attributes != NULL)
  68. {
  69. out << ' ';
  70. attributes->render(out);
  71. }
  72.  
  73. out << ">";
  74. }
  75. };
  76.  
  77. #define TAG(name, tag)
  78. class name##Tag
  79. { public: inline static const char* getName() { return tag; } }
  80.  
  81. #define SIMPLE_ELEMENT(name, tag)
  82. TAG(name, tag); typedef HTMLSimpleElement<name##Tag> name
  83.  
  84. SIMPLE_ELEMENT (divB, "div");
  85. SIMPLE_ELEMENT (divE, "/div");
  86.  
  87. // and so on...
Add Comment
Please, Sign In to add comment