I18N - Record

- Localized Record object.
- Remove copy ctor, operator= from Duration - unnecessary.
This commit is contained in:
Paul Beckingham 2009-06-06 22:06:02 -04:00
parent 36d4ecab43
commit db52cf7327
5 changed files with 23 additions and 32 deletions

View file

@ -19,6 +19,9 @@
106 ID Range too large 106 ID Range too large
107 Not a sequence. 107 Not a sequence.
108 Interactive task is only available when built with ncurses support. 108 Interactive task is only available when built with ncurses support.
109 Empty record in input
110 Unrecognized characters at end of line
111 Record not recognized as format 4
# 2xx Commands # 2xx Commands
200 active 200 active

View file

@ -37,31 +37,12 @@ Duration::Duration ()
{ {
} }
////////////////////////////////////////////////////////////////////////////////
Duration::Duration (const Duration& other)
{
throw std::string ("unimplemented Duration::Duration");
mDays = other.mDays;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Duration::Duration (const std::string& input) Duration::Duration (const std::string& input)
{ {
parse (input); parse (input);
} }
////////////////////////////////////////////////////////////////////////////////
Duration& Duration::operator= (const Duration& other)
{
throw std::string ("unimplemented Duration::operator=");
if (this != &other)
{
mDays = other.mDays;
}
return *this;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Duration::operator int () Duration::operator int ()
{ {

View file

@ -34,9 +34,7 @@ class Duration
{ {
public: public:
Duration (); // Default constructor Duration (); // Default constructor
Duration (const Duration&); // Copy constructor
Duration (const std::string&); // Parse Duration (const std::string&); // Parse
Duration& operator= (const Duration&); // Assignment operator
bool operator< (const Duration&); bool operator< (const Duration&);
bool operator> (const Duration&); bool operator> (const Duration&);
~Duration (); // Destructor ~Duration (); // Destructor

View file

@ -30,8 +30,12 @@
#include <stdlib.h> #include <stdlib.h>
#include "util.h" #include "util.h"
#include "Nibbler.h" #include "Nibbler.h"
#include "Context.h"
#include "i18n.h"
#include "Record.h" #include "Record.h"
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Record::Record () Record::Record ()
{ {
@ -72,9 +76,9 @@ std::string Record::composeF4 ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// [ --> start --> name --> : --> " --> value --> " --> ] --> end // start --> [ --> Att --> ] --> end
// ^ | // ^ |
// +------------- \s <--------------+ // +-------+
// //
void Record::parse (const std::string& input) void Record::parse (const std::string& input)
{ {
@ -86,7 +90,8 @@ void Record::parse (const std::string& input)
n.depleted ()) n.depleted ())
{ {
if (line.length () == 0) if (line.length () == 0)
throw std::string ("Empty FF4 record"); throw context.stringtable.get (RECORD_EMPTY,
"Empty record in input");
Nibbler nl (line); Nibbler nl (line);
Att a; Att a;
@ -99,10 +104,12 @@ void Record::parse (const std::string& input)
std::string remainder; std::string remainder;
nl.getUntilEOS (remainder); nl.getUntilEOS (remainder);
if (remainder.length ()) if (remainder.length ())
throw std::string ("Unrecognized garbage at end of line"); throw context.stringtable.get (RECORD_EXTRA,
"Unrecognized characters at end of line");
} }
else else
throw std::string ("Record not recognized as FF4"); throw context.stringtable.get (RECORD_NOT_FF4,
"Record not recognized as format 4");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -151,11 +158,9 @@ void Record::set (const std::string& name, int value)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Record::remove (const std::string& name) void Record::remove (const std::string& name)
{ {
std::map <std::string, Att> copy = *this; Record::iterator it;
this->clear (); if ((it = this->find (name)) != this->end ())
foreach (i, copy) this->erase (it);
if (i->first != name)
(*this)[i->first] = i->second;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -42,6 +42,10 @@
#define INTERACTIVE_NO_NCURSES 108 #define INTERACTIVE_NO_NCURSES 108
#define RECORD_EMPTY 109
#define RECORD_EXTRA 110
#define RECORD_NOT_FF4 111
// 2xx Commands // 2xx Commands
#define CMD_ACTIVE 200 #define CMD_ACTIVE 200
#define CMD_ADD 201 #define CMD_ADD 201