cwidget  0.5.18
fragment_cache.h
1 // fragment_cache.h -*-c++-*-
2 //
3 // Copyright (C) 2005 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19 //
20 // A special fragment class that caches its contents.
21 
22 #ifndef FRAGMENT_CACHE_H
23 #define FRAGMENT_CACHE_H
24 
25 #include "fragment.h"
26 
27 namespace cwidget
28 {
34  class fragment_cache:public fragment
35  {
36  fragment *contents;
37 
39  mutable fragment_contents cached_lines;
40 
42  mutable style cached_lines_style;
43 
47  mutable size_t cached_lines_first_width, cached_lines_rest_width;
48 
50  mutable size_t cached_max_width;
51 
53  mutable size_t cached_max_width_first_indent, cached_max_width_rest_indent;
54 
56  mutable size_t cached_trailing_width;
57 
59  mutable size_t cached_trailing_width_first_indent, cached_trailing_width_rest_indent;
60 
62  mutable bool cached_final_nl:1;
63 
65  mutable bool cached_lines_valid:1, cached_max_width_valid:1;
67  mutable bool cached_trailing_width_valid:1, cached_final_nl_valid:1;
68  public:
69  fragment_cache(fragment *_contents);
70  ~fragment_cache();
71 
72  void invalidate();
73 
74  fragment_contents layout(size_t firstw, size_t restw,
75  const style &st);
76 
77  void set_attr(int attr);
78 
79  size_t max_width(size_t first_indent, size_t rest_indent) const;
80  size_t trailing_width(size_t first_indent, size_t rest_indent) const;
81 
82  bool final_newline() const;
83  };
84 }
85 
86 #endif
cwidget::fragment::layout
virtual fragment_contents layout(size_t firstw, size_t w, const style &st)=0
Return all the lines of this fragment, given the "shape" of the fragment.
cwidget::fragment::max_width
virtual size_t max_width(size_t first_indent, size_t rest_indent) const =0
cwidget::fragment_cache::final_newline
bool final_newline() const
Definition: fragment_cache.cc:90
cwidget::fragment_cache
A fragment that caches its contents; a cached result is used if the same width is passed to the layou...
Definition: fragment_cache.h:34
cwidget::fragment::trailing_width
virtual size_t trailing_width(size_t first_indent, size_t rest_indent) const =0
cwidget::fragment::final_newline
virtual bool final_newline() const =0
cwidget::style
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
cwidget::fragment
A fragment represents a logical unit of text.
Definition: fragment.h:37
cwidget::fragment_contents
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:30
cwidget::fragment_cache::trailing_width
size_t trailing_width(size_t first_indent, size_t rest_indent) const
Definition: fragment_cache.cc:75
cwidget
The namespace containing everything defined by cwidget.
Definition: columnify.cc:27
cwidget::fragment_cache::layout
fragment_contents layout(size_t firstw, size_t restw, const style &st)
Return all the lines of this fragment, given the "shape" of the fragment.
Definition: fragment_cache.cc:42
cwidget::fragment_cache::max_width
size_t max_width(size_t first_indent, size_t rest_indent) const
Definition: fragment_cache.cc:60