HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StringPager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_StringPager.h ( Utility Library, C++ )
7  *
8  * COMMENTS:
9  * A fixed-width pager, in the sense of less or more, that lets
10  * one dump text to it and then retrieve in a word-wrapped manner.
11  */
12 
13 #ifndef __UT_StringPager_h__
14 #define __UT_StringPager_h__
15 
16 #include "UT_API.h"
17 
18 #include "UT_Assert.h"
19 #include "UT_StringHolder.h"
20 #include "UT_StringArray.h"
21 #include "UT_WorkBuffer.h"
22 
23 #include <SYS/SYS_Inline.h>
24 #include <SYS/SYS_String.h>
25 #include <SYS/SYS_Types.h>
26 
28 {
29 public:
30  UT_StringPager(int width = 80, int leftmargin = 0, int rightmargin = 3)
31  : myWidth(width)
32  , myLeftMargin(leftmargin)
33  , myRightMargin(rightmargin)
34  {}
35 
36  int getLeftMargin() const { return myLeftMargin; }
37  int getRightMargin() const { return myRightMargin; }
38  int getWidth() const { return myWidth; }
39 
40  // This only affects future appended text, not the existing paged data.
41  void setLeftMargin(int leftmargin) { myLeftMargin = leftmargin; }
42  void setRightMargin(int rightmargin) { myRightMargin = rightmargin; }
43  void setWidth(int width) { myWidth = width; }
44 
45  UT_StringHolder getLine(exint line) const;
46  exint numLines() const { return myLines.entries()+1; }
47  void clear();
48 
49  // Returns all the lines joined with \n
50  // No \n on final line. (so empty -> empty)
51  UT_StringHolder buildText() const;
52 
53  // Explicitly append provided text
54  void appendText(const char *text);
55 
56  // Appends a new line
57  void newLine();
58 
59 private:
60  // Formatting options
61  int myWidth;
62  int myLeftMargin, myRightMargin;
63 
64  // Current text buffer, myCurLine is always the last line.
65  UT_StringArray myLines;
66  UT_WorkBuffer myCurLine;
67 };
68 
69 #endif
int64 exint
Definition: SYS_Types.h:125
#define UT_API
Definition: UT_API.h:14
exint numLines() const
void setRightMargin(int rightmargin)
int getWidth() const
void setLeftMargin(int leftmargin)
int getRightMargin() const
GLint GLsizei width
Definition: glcorearb.h:103
UT_StringPager(int width=80, int leftmargin=0, int rightmargin=3)
void setWidth(int width)
int getLeftMargin() const