1 /***************************************************************************
2                           FMTNode.hpp  -  node for formatted io processing
3                              -------------------
4     begin                : July 22 2002
5     copyright            : (C) 2002 by Marc Schellens
6     email                : m_schellens@users.sf.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef FMTNode_hpp__
19 #define FMTNode_hpp__
20 
21 #include "typedefs.hpp"
22 
23 #include "FMTTokenTypes.hpp"
24 
25 #include <antlr/CommonAST.hpp>
26 
27 //ANTLR_USING_NAMESPACE(std)
28 //ANTLR_USING_NAMESPACE(antlr)
29 
30 class FMTNode;
31 typedef antlr::ASTRefCount<FMTNode> RefFMTNode;
32 
33 class FMTNode : public antlr::CommonAST {
34 
35 public:
36 
37   ~FMTNode();
38 
FMTNode()39   FMTNode(): CommonAST(), down(), right(), w(-1), d(-1), rep(1), code(0)
40   {
41   }
42 
FMTNode(antlr::RefToken t)43   FMTNode( antlr::RefToken t) :
44     CommonAST(t), down(), right(), w(-1), d(-1), rep(1), code(0)
45   {
46   }
47 
initialize(int t,const std::string & txt)48   void initialize(int t, const std::string& txt)
49   {
50     CommonAST::setType(t);
51     CommonAST::setText(txt);
52   }
53 
54   // used by FMTNodeFactory
55   void initialize( RefFMTNode t );
56 
57   // we deal only with RefFMTNode here
initialize(antlr::RefAST t)58   void initialize( antlr::RefAST t )
59   {
60     //    CommonAST::initialize(t);
61     initialize(static_cast<RefFMTNode>(t));
62   }
63 
initialize(antlr::RefToken t)64   void initialize( antlr::RefToken t )
65   {
66     CommonAST::initialize(t);
67   }
68 
setText(const std::string & txt)69   void setText(const std::string& txt)
70   {
71     CommonAST::setText(txt);
72   }
73 
setType(int type)74   void setType(int type)
75   {
76     CommonAST::setType(type);
77   }
78 
addChild(RefFMTNode c)79   void addChild( RefFMTNode c )
80   {
81     BaseAST::addChild( static_cast<antlr::RefAST>(c) );
82   }
83 
factory()84   static antlr::RefAST factory()
85   {
86     antlr::RefAST ret = static_cast<antlr::RefAST>(RefFMTNode(new FMTNode));
87     return ret;
88   }
89 
90 //   RefFMTNode getFirstChild() const
91 //   {
92 //     return static_cast<RefFMTNode>(BaseAST::getFirstChild());
93 //   }
94 
95 //   RefFMTNode getNextSibling() const
96 //   {
97 //     return static_cast<RefFMTNode>(BaseAST::getNextSibling());
98 //   }
99 
setW(const int w_)100   void setW( const int w_)
101   {
102     w=w_;
103   }
getW()104   int getW()
105   {
106     return w;
107   }
108 
setD(const int d_)109   void setD( const int d_)
110   {
111     d=d_;
112   }
getD()113   int getD()
114   {
115     return d;
116   }
117 
setRep(const int rep_)118   void setRep( const int rep_)
119   {
120     rep=rep_;
121   }
getRep()122   int getRep()
123   {
124     return rep;
125   }
126 
127   typedef enum codeFlags_
128   {
129     fmtALIGN_LEFT = 1
130    ,fmtSHOWPOS = 2
131    ,fmtPAD = 4
132    ,fmtUPPER = 8
133   } codeFlags;
134 
setALignLeft()135   void setALignLeft()
136   {
137    code |= fmtALIGN_LEFT;
138   }
139 
setShowSign()140   void setShowSign()
141   {
142    code |= fmtSHOWPOS;
143   }
144 
setUpper()145   void setUpper()
146   {
147    code |= fmtUPPER;
148   }
149 
setPadding()150   void setPadding()
151   {
152     code |= fmtPAD;
153   }
getCode()154    int getCode()
155    {
156     return code;
157    }
158 private:
159   RefFMTNode down;
160   RefFMTNode right;
161 
162   int w;
163   int d;
164 
165   int rep;
166   int code; // bitfield for alignment (bit 0 set: left-align unset: right-align) (bit 1 set: '+' code) (bit 2 set: use fill character)
167 
168 // private:
169 
170 //   // forbid usage of these
171 //   FMTNode& operator=( const FMTNode& r)
172 //   { return *this;} // make compiler shut up
173 //   FMTNode( const FMTNode& cp)
174 //   {}
175 };
176 
177 #endif
178 
179