libyui  3.12.1
YItem.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YItem.cc
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #define MAX_DEBUG_LABEL_LEN 32
26 
27 
28 #include <iostream>
29 #include "YItem.h"
30 
31 using std::string;
32 
33 
34 /**
35  * Static children collection that is always empty so the children
36  * iterators of this base class have something valid to return.
37  *
38  * No item will ever be added to this collection.
39  **/
40 YItemCollection YItem::_noChildren;
41 
42 
43 string
45 {
46  return limitLength( _label, MAX_DEBUG_LABEL_LEN );
47 }
48 
49 
50 string
51 YItem::limitLength( const string & origText, int limit ) const
52 {
53  string text = origText;
54 
55  if ( text.size() > MAX_DEBUG_LABEL_LEN )
56  {
57  text.resize( MAX_DEBUG_LABEL_LEN );
58  text.append( "..." );
59  }
60 
61  return text;
62 }
63 
64 
65 std::ostream & operator<<( std::ostream & stream, const YItem * item )
66 {
67  if ( item )
68  stream << "<" << item->itemClass() << " " << item->debugLabel() << ">";
69  else
70  stream << "<NULL YItem>";
71 
72  return stream;
73 }
YItemCollection
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Definition: YItem.h:39
YItem::debugLabel
virtual std::string debugLabel() const
Return a descriptive label of this item instance for debugging.
Definition: YItem.cc:44
YItem::limitLength
std::string limitLength(const std::string &text, int limit) const
Return a string of maximum 'limit' characters.
Definition: YItem.cc:51
YItem.h
YItem::itemClass
virtual const char * itemClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YItem.h:91
YItem
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
Definition: YItem.h:56