Changed many uses of "unsigned long" to std::size_t.

This commit is contained in:
John Wiegley 2009-02-01 18:33:46 -04:00
parent 9f579902fb
commit 59a080cdb6
16 changed files with 39 additions and 35 deletions

View file

@ -64,7 +64,7 @@ typedef std::map<const string, account_t *> accounts_map;
class account_t : public scope_t class account_t : public scope_t
{ {
public: public:
typedef unsigned long ident_t; typedef std::size_t ident_t;
account_t * parent; account_t * parent;
string name; string name;

View file

@ -159,7 +159,7 @@ void write_string(std::ostream& out, const string& str)
{ {
write_guard(out, 0x3001); write_guard(out, 0x3001);
unsigned long len = str.length(); std::size_t len = str.length();
if (len > 255) { if (len > 255) {
assert(len < 65536); assert(len < 65536);
write_number_nocheck<unsigned char>(out, 0xff); write_number_nocheck<unsigned char>(out, 0xff);

View file

@ -72,6 +72,7 @@ void read_xact(const char *& data, xact_t * xact)
xact->add_flags(XACT_BULK_ALLOC); xact->add_flags(XACT_BULK_ALLOC);
read_string(data, xact->note); read_string(data, xact->note);
// jww (2009-02-01): Use istream_pos_type
xact->beg_pos = read_long<unsigned long>(data); xact->beg_pos = read_long<unsigned long>(data);
read_long(data, xact->beg_line); read_long(data, xact->beg_line);
xact->end_pos = read_long<unsigned long>(data); xact->end_pos = read_long<unsigned long>(data);
@ -249,7 +250,7 @@ commodity_t::base_t * read_commodity_base(const char *& data)
commodity->note = str; commodity->note = str;
read_number(data, commodity->precision); read_number(data, commodity->precision);
unsigned long flags; commodity_t::base_t::flags_t flags;
read_number(data, flags); read_number(data, flags);
commodity->set_flags(flags); commodity->set_flags(flags);
@ -320,9 +321,9 @@ void write_commodity_base_extra(std::ostream& out,
#endif #endif
if (! commodity->history) { if (! commodity->history) {
write_long<unsigned long>(out, 0); write_long<std::size_t>(out, 0);
} else { } else {
write_long<unsigned long>(out, commodity->history->prices.size()); write_long<std::size_t>(out, commodity->history->prices.size());
foreach (commodity_t::history_map::value_type& pair, foreach (commodity_t::history_map::value_type& pair,
commodity->history->prices) { commodity->history->prices) {
write_number(out, pair.first); write_number(out, pair.first);

View file

@ -43,7 +43,7 @@ void format_emacs_xacts::write_entry(entry_t& entry)
break; break;
} }
out << (static_cast<unsigned long>(entry.beg_line) + 1) << " "; out << (static_cast<std::size_t>(entry.beg_line) + 1) << " ";
tm when = gregorian::to_tm(*entry.date()); tm when = gregorian::to_tm(*entry.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local? std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
@ -79,7 +79,7 @@ void format_emacs_xacts::operator()(xact_t& xact)
out << "\n"; out << "\n";
} }
out << " (" << (static_cast<unsigned long>(xact.beg_line) + 1) << " "; out << " (" << (static_cast<std::size_t>(xact.beg_line) + 1) << " ";
out << "\"" << xact.reported_account()->fullname() << "\" \"" out << "\"" << xact.reported_account()->fullname() << "\" \""
<< xact.amount << "\""; << xact.amount << "\"";

View file

@ -783,16 +783,15 @@ class budget_xacts : public generate_xacts
#define BUDGET_BUDGETED 0x01 #define BUDGET_BUDGETED 0x01
#define BUDGET_UNBUDGETED 0x02 #define BUDGET_UNBUDGETED 0x02
unsigned short flags; uint_least8_t flags;
budget_xacts(); budget_xacts();
public: public:
budget_xacts(xact_handler_ptr handler, budget_xacts(xact_handler_ptr handler,
unsigned long _flags = BUDGET_BUDGETED) uint_least8_t _flags = BUDGET_BUDGETED)
: generate_xacts(handler), flags(_flags) { : generate_xacts(handler), flags(_flags) {
TRACE_CTOR(budget_xacts, TRACE_CTOR(budget_xacts, "xact_handler_ptr, uint_least8_t");
"xact_handler_ptr, unsigned long");
} }
virtual ~budget_xacts() throw() { virtual ~budget_xacts() throw() {
TRACE_DTOR(budget_xacts); TRACE_DTOR(budget_xacts);

View file

@ -64,7 +64,7 @@ static XML_Parser parser;
static path pathname; static path pathname;
static std::size_t src_idx; static std::size_t src_idx;
static istream_pos_type beg_pos; static istream_pos_type beg_pos;
static unsigned long beg_line; static std::size_t beg_line;
static xact_t::state_t curr_state; static xact_t::state_t curr_state;
@ -425,14 +425,14 @@ std::size_t gnucash_parser_t::parse(std::istream& in,
in.getline(buf, BUFSIZ - 1); in.getline(buf, BUFSIZ - 1);
std::strcat(buf, "\n"); std::strcat(buf, "\n");
if (! XML_Parse(parser, buf, std::strlen(buf), in.eof())) { if (! XML_Parse(parser, buf, std::strlen(buf), in.eof())) {
//unsigned long line = XML_GetCurrentLineNumber(parser) - offset++; //std::size_t line = XML_GetCurrentLineNumber(parser) - offset++;
const char * msg = XML_ErrorString(XML_GetErrorCode(parser)); const char * msg = XML_ErrorString(XML_GetErrorCode(parser));
XML_ParserFree(parser); XML_ParserFree(parser);
throw parse_error(msg); throw parse_error(msg);
} }
if (! have_error.empty()) { if (! have_error.empty()) {
//unsigned long line = XML_GetCurrentLineNumber(parser) - offset++; //std::size_t line = XML_GetCurrentLineNumber(parser) - offset++;
parse_error err(have_error); parse_error err(have_error);
std::cerr << "Error: " << err.what() << std::endl; std::cerr << "Error: " << err.what() << std::endl;
have_error = ""; have_error = "";

View file

@ -73,10 +73,14 @@ public:
optional<string> note; optional<string> note;
unsigned short src_idx; unsigned short src_idx;
istream_pos_type full_beg_pos;
std::size_t full_beg_line;
istream_pos_type beg_pos; istream_pos_type beg_pos;
unsigned long beg_line; std::size_t beg_line;
istream_pos_type end_pos; istream_pos_type end_pos;
unsigned long end_line; std::size_t end_line;
istream_pos_type full_end_pos;
std::size_t full_end_line;
static bool use_effective_date; static bool use_effective_date;

View file

@ -90,7 +90,7 @@ std::size_t qif_parser_t::parse(std::istream& in,
linenum = 1; linenum = 1;
istream_pos_type beg_pos = 0; istream_pos_type beg_pos = 0;
unsigned long beg_line = 0; std::size_t beg_line = 0;
#define SET_BEG_POS_AND_LINE() \ #define SET_BEG_POS_AND_LINE() \
if (! beg_line) { \ if (! beg_line) { \

View file

@ -58,19 +58,19 @@ namespace ledger {
*/ */
class quotes_by_script : public noncopyable, public commodity_t::base_t::updater_t class quotes_by_script : public noncopyable, public commodity_t::base_t::updater_t
{ {
string price_db; string price_db;
unsigned long pricing_leeway; std::size_t pricing_leeway;
bool& cache_dirty; bool& cache_dirty;
quotes_by_script(); quotes_by_script();
public: public:
quotes_by_script(path _price_db, quotes_by_script(path _price_db,
unsigned long _pricing_leeway, std::size_t _pricing_leeway,
bool& _cache_dirty) bool& _cache_dirty)
: price_db(_price_db), pricing_leeway(_pricing_leeway), : price_db(_price_db), pricing_leeway(_pricing_leeway),
cache_dirty(_cache_dirty) { cache_dirty(_cache_dirty) {
TRACE_CTOR(quotes_by_script, "path, unsigned long, bool&"); TRACE_CTOR(quotes_by_script, "path, std::size_t, bool&");
} }
~quotes_by_script() throw() { ~quotes_by_script() throw() {
TRACE_DTOR(quotes_by_script); TRACE_DTOR(quotes_by_script);

View file

@ -125,7 +125,7 @@ public:
expr_t total_expr; expr_t total_expr;
expr_t display_total; expr_t display_total;
unsigned long budget_flags; uint_least8_t budget_flags;
long head_entries; long head_entries;
long tail_entries; long tail_entries;

View file

@ -94,7 +94,7 @@ public:
string prices_format; string prices_format;
string pricesdb_format; string pricesdb_format;
unsigned long pricing_leeway; std::size_t pricing_leeway;
bool download_quotes; bool download_quotes;
bool use_cache; bool use_cache;

View file

@ -95,8 +95,8 @@ namespace std {
} }
} }
typedef unsigned long istream_pos_type; typedef std::size_t istream_pos_type;
typedef unsigned long ostream_pos_type; typedef std::size_t ostream_pos_type;
#else // ! (defined(__GNUG__) && __GNUG__ < 3) #else // ! (defined(__GNUG__) && __GNUG__ < 3)

View file

@ -1068,7 +1068,7 @@ entry_t * textual_parser_t::instance_t::parse_entry(std::istream& in,
TRACE_START(entry_details, 1, "Time spent parsing entry details:"); TRACE_START(entry_details, 1, "Time spent parsing entry details:");
istream_pos_type end_pos; istream_pos_type end_pos;
unsigned long beg_line = linenum; std::size_t beg_line = linenum;
while (! in.eof() && (in.peek() == ' ' || in.peek() == '\t')) { while (! in.eof() && (in.peek() == ' ' || in.peek() == '\t')) {
istream_pos_type beg_pos = in.tellg(); istream_pos_type beg_pos = in.tellg();
@ -1127,8 +1127,8 @@ void write_textual_journal(journal_t& journal,
const string& write_hdr_format, const string& write_hdr_format,
std::ostream& out) std::ostream& out)
{ {
unsigned long index = 0; std::size_t index = 0;
path found; path found;
// jww (2009-01-29): This function currently doesn't work // jww (2009-01-29): This function currently doesn't work

View file

@ -96,8 +96,8 @@ protected:
std::size_t linenum; std::size_t linenum;
std::size_t src_idx; std::size_t src_idx;
istream_pos_type beg_pos; istream_pos_type beg_pos;
std::size_t beg_line;
istream_pos_type end_pos; istream_pos_type end_pos;
unsigned long beg_line;
std::size_t count; std::size_t count;
std::size_t errors; std::size_t errors;

View file

@ -45,7 +45,7 @@ DECLARE_EXCEPTION(assertion_failed, std::logic_error);
void debug_assert(const string& reason, void debug_assert(const string& reason,
const string& func, const string& func,
const string& file, const string& file,
unsigned long line) std::size_t line)
{ {
std::ostringstream buf; std::ostringstream buf;
buf << "Assertion failed in \"" << file << "\", line " << line buf << "Assertion failed in \"" << file << "\", line " << line
@ -458,7 +458,7 @@ static ptime logger_start;
bool logger_func(log_level_t level) bool logger_func(log_level_t level)
{ {
unsigned long appender = 0; std::size_t appender = 0;
if (! logger_has_run) { if (! logger_has_run) {
logger_has_run = true; logger_has_run = true;

View file

@ -118,7 +118,7 @@ namespace ledger {
namespace ledger { namespace ledger {
void debug_assert(const string& reason, const string& func, void debug_assert(const string& reason, const string& func,
const string& file, unsigned long line); const string& file, std::size_t line);
} }
#define assert(x) \ #define assert(x) \