[Aptitude-svn-commit] r3270 - in branches/aptitude-0.3/aptitude: . src/vscreen/config

Daniel Burrows dburrows@costa.debian.org
Sun, 08 May 2005 12:52:48 +0000


Author: dburrows
Date: Sun May  8 12:52:45 2005
New Revision: 3270

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc
   branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
Log:
Throw an exception if a style can't be found.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun May  8 12:52:45 2005
@@ -1,5 +1,10 @@
 2005-05-08  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/config/style.cc, src/vscreen/config/style.h:
+
+	Throw an exception if a style is missing, rather than just
+	silently creating a new style.
+
 	* src/vscreen/config/style.h:
 
 	Add factory routines to make it easy to generate canned styles.

Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.cc	Sun May  8 12:52:45 2005
@@ -28,7 +28,12 @@
 
 const style &get_style(const std::string &name)
 {
-  return styles[name];
+  map<string, style>::const_iterator found=styles.find(name);
+
+  if(found == styles.end())
+    throw NoSuchStyle(name);
+  else
+    return found->second;
 }
 
 void set_style(const std::string &name, const style &style)

Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/style.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.h	Sun May  8 12:52:45 2005
@@ -24,6 +24,16 @@
 
 #include <string>
 
+/** Exception thrown if a style lookup fails. */
+class NoSuchStyle
+{
+  std::string name;
+public:
+  NoSuchStyle(const std::string &_name):name(_name) {}
+
+  std::string get_name() {return name;}
+};
+
 /** A "style" is a setting to be applied to a display element (widget,
  *  text, etc).  This means color (foreground and background) and
  *  attributes.  A style may contain settings for any or all of these;
@@ -190,12 +200,9 @@
   return rval;
 }
 
-/** Look up a style in the global registry.  If there is no style
- *  registered by this name, returns the empty style.
+/** Look up a style in the global registry.
  *
- *  WARNING: the current implementation will allocate entries in the
- *  style table if you pass an unregistered name.  You probably don't
- *  want to do this unless you intend to eventually register it!
+ *  \throws NoSuchStyle if the style does not exist.
  */
 const style &get_style(const std::string &name);