1313 Class : template (T context, D datas)
1414 Extensions :
1515 Aliases :
16- Friends ->
17- <-
16+ Friends -> CompressedStack
17+ <- Data, Signature
1818==============================================================================*/
19+ template <class T , class D > class CompressedStack ; // Required for the friendship
1920template <class T , class D >
2021class Component {
21- public:
22- Component<T,D>(int space, int depth);
22+ friend class CompressedStack <T,D>;
2323
24- // Getters
25- Signature<T> getSign ();
26- std::shared_ptr<Signature<T>> getSignPtr ();
27- int getLastSign ();
28- ExplicitPointer<D> getExplicit ();
24+ private:
25+ Component<T,D>(int space, int depth);
2926
3027 // Setters
31- void setSignature (std::shared_ptr<Signature<T>> sign);
32- void setLastSign (int index);
33- void setExplicit (ExplicitPointer<D> xplicit);
3428 void clearExplicit (int space);
3529
3630 // Push and pop
37- void pushExplicit (std::shared_ptr<Data<D>> elt);
38- void push (Signature<T> sign, int lvl);
39- Data<D> top ();
40- Signature<T> top (int lvl);
41- int topIndex (int lvl);
42- int topIndex ();
31+ void pushExplicit (std::shared_ptr<Data<T,D>> elt);
32+ void push (Signature<T,D> sign, int lvl);
33+ Data<T,D> top ();
34+ Signature<T,D> top (int lvl);
35+ int topIndex (int lvl = 0 );
4336
4437 // IO
4538 std::string toString ();
46- void print ();
47- void println ();
4839
4940 // State
5041 bool isempty ();
5142 bool isempty (int lvl);
5243 bool isExplicitEmpty ();
5344
54- private:
55- Levels<T> mPartial ;
56- ExplicitPointer<D> mExplicit ;
57- std::shared_ptr<Signature<T>> mSign ;
45+ Levels<T,D> mPartial ;
46+ ExplicitPointer<T,D> mExplicit ;
47+ std::shared_ptr<Signature<T,D>> mSign ;
5848};
5949
6050/* ==============================================================================
6151 Constructors
6252==============================================================================*/
6353template <class T , class D >
6454Component<T,D>::Component(int space, int depth){
65- mSign = std::shared_ptr<Signature<T>> (nullptr );
55+ mSign = std::shared_ptr<Signature<T,D >> (nullptr );
6656
67- Levels<T> partial = initLevels<T>(space, depth);
57+ Levels<T,D > partial = initLevels<T,D >(space, depth);
6858 mPartial = partial;
6959
70- ExplicitPointer<D> xplicit = initExplicitPointer<D>();
60+ ExplicitPointer<T, D> xplicit = initExplicitPointer<T, D>();
7161 xplicit.reserve (space);
7262 mExplicit = xplicit;
7363}
7464
7565/* ==============================================================================
76- IO
66+ IO : levelsToStringInComponent, toString
7767==============================================================================*/
78- template <class T >
79- std::string levelsToStringInComponent (Levels<T> levels){
68+ template <class T , class D >
69+ std::string levelsToString (Levels<T,D > levels){
8070 std::string str;
8171 str = " " ;
8272 int index = 0 ;
83- for (typename Levels<T>::iterator it = levels.begin () ; it != levels.end (); ++it)
73+ for (typename Levels<T,D >::iterator it = levels.begin () ; it != levels.end (); ++it)
8474 {
8575 index++;
8676 str += " \t\t\t Level" + std::to_string (index) + " ->\n " ;
@@ -92,15 +82,17 @@ std::string levelsToStringInComponent(Levels<T> levels){
9282template <class T , class D >
9383std::string Component<T,D>::toString(){
9484 std::string str;
95- str = levelsToStringInComponent (mPartial );
85+ str = levelsToString (mPartial );
9686 str += " \t\t\t Explicit->\n " ;
9787 str += explicitPointerToString (mExplicit );
9888 str += " \t\t\t Signature->\n " ;
9989 // str += (&mSign).toString() + "\n";
10090 return str;
10191}
10292
103- /* State of the component */
93+ /* ==============================================================================
94+ Stack Functions: push, pop, top, topIndex, isempty, isExplicitEmpty
95+ ==============================================================================*/
10496template <class T , class D >
10597bool Component<T,D>::isempty(){
10698 bool b = bool (mSign );
@@ -123,85 +115,40 @@ bool Component<T,D>::isExplicitEmpty(){
123115 return (mExplicit .empty ());
124116}
125117
126- /* ==============================================================================
127- Stack Functions: push, pop, top, topIndex
128- ==============================================================================*/
129118template <class T , class D >
130- void Component<T,D>::pushExplicit(std::shared_ptr<Data<D>> elt){
119+ void Component<T,D>::pushExplicit(std::shared_ptr<Data<T, D>> elt){
131120 mExplicit .push_back (elt);
132121}
133122template <class T , class D >
134- void Component<T,D>::push(Signature<T> sign, int lvl){
123+ void Component<T,D>::push(Signature<T,D > sign, int lvl){
135124 mPartial [lvl].push_back (sign);
136125}
137126
138127template <class T , class D >
139- Data<D> Component<T,D>::top(){
128+ Data<T, D> Component<T,D>::top(){
140129 return *(mExplicit .back ());
141130}
142131template <class T , class D >
143- Signature<T> Component<T,D>::top(int lvl){
132+ Signature<T,D > Component<T,D>::top(int lvl){
144133 return mPartial [lvl].back ();
145134}
146135
147- template <class T , class D >
148- int Component<T,D>::topIndex(){
149- Data<D> elt = top ();
150- int index = elt.getIndex ();
151- return index;
152- }
153136template <class T , class D >
154137int Component<T,D>::topIndex(int lvl){
155- Signature<T> sign = top (lvl);
156- int index = sign.getLast ();
157- return index;
138+ if (lvl == 0 ) {
139+ return top ().mIndex ;
140+ } else {
141+ return top (lvl).mLast ;
142+ }
158143}
159144
160145/* ==============================================================================
161146 Setters
162147==============================================================================*/
163- template <class T , class D >
164- void Component<T,D>::setSignature(std::shared_ptr<Signature<T>> sign){
165- mSign = sign;
166- }
167-
168- template <class T , class D >
169- void Component<T,D>::setLastSign(int index){
170- mSign ->setLast (index);
171- }
172-
173- template <class T , class D >
174- void Component<T,D>::setExplicit(ExplicitPointer<D> xplicit){
175- mExplicit = xplicit;
176- }
177-
178148template <class T , class D >
179149void Component<T,D>::clearExplicit(int space){
180150 mExplicit .clear ();
181151 mExplicit .reserve (space);
182152}
183153
184- /* ==============================================================================
185- Getters
186- ==============================================================================*/
187- template <class T , class D >
188- Signature<T> Component<T,D>::getSign(){
189- return *mSign ;
190- }
191-
192- template <class T , class D >
193- std::shared_ptr<Signature<T>> Component<T,D>::getSignPtr(){
194- return mSign ;
195- }
196-
197- template <class T , class D >
198- int Component<T,D>::getLastSign(){
199- return mSign ->getLast ();
200- }
201-
202- template <class T , class D >
203- ExplicitPointer<D> Component<T,D>::getExplicit(){
204- return mExplicit ;
205- }
206-
207154#endif /* COMPONENT */
0 commit comments