• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef EXAMPLE1_H_
2 #define EXAMPLE1_H_
3 
4 #include "example2.h"
5 
6 #if defined(__cplusplus)
7 extern "C" {
8 #endif
9 
10 struct Hello {
11   int foo;
12   int bar;
13 };
14 
15 #if defined(__cplusplus)
16 }  // extern "C"
17 #endif
18 using namespace test2;
19 using namespace test3;
20 typedef float float_type;
21 typedef const float_type cfloat_type;
22 struct CPPHello : private HelloAgain, public ByeAgain<float_type> {
23   const int cpp_foo;
24   cfloat_type cpp_bar;
againCPPHello25   virtual int again() { return 0; }
CPPHelloCPPHello26   CPPHello() : cpp_foo(20), cpp_bar(1.234) { }
27 };
28 
29 template<typename T>
30 struct StackNode {
31 public:
32   T value_;
33   StackNode<T>* next_;
34 
35 public:
36   StackNode(T t, StackNode* next = nullptr)
value_StackNode37     : value_(static_cast<T&&>(t)),
38       next_(next) { }
39 };
40 
41 template<typename T>
42 class Stack {
43 private:
44   StackNode<T>* head_;
45 
46 public:
Stack()47   Stack() : head_(nullptr) { }
48 
push(T t)49   void push(T t) {
50     head_ = new StackNode<T>(static_cast<T&&>(t), head_);
51   }
52 
pop()53   T pop() {
54     StackNode<T>* cur = head_;
55     head_ = cur->next_;
56     T res = static_cast<T&&>(cur->value_);
57     delete cur;
58     return res;
59   }
60 };
61 
62 // Replicated from libsysutils.
63 template<typename T>
64 class List
65 {
66 protected:
67     /*
68      * One element in the list.
69      */
70     class _Node {
71     public:
_Node(const T & val)72         explicit _Node(const T& val) : mVal(val) {}
~_Node()73         ~_Node() {}
getRef()74         inline T& getRef() { return mVal; }
getRef()75         inline const T& getRef() const { return mVal; }
76     private:
77         friend class List;
78         friend class _ListIterator;
79         T           mVal;
80         _Node*      mpPrev;
81         _Node*      mpNext;
82     };
83     _Node *middle;
84 };
85 
86 typedef List<float> float_list;
87 float_list float_list_test;
88 
89 
90 typedef List<int> int_list;
91 int_list int_list_test;
92 
93 #endif  // EXAMPLE1_H_
94