Add many new template functions for enums & bitfields.

An incompatible change: ENUM_KEY_STR returns std::string now.
The old behavior is available via enum_item_key_str function.
develop
Alexander Gavrilov 2012-03-17 12:52:22 +04:00
parent 14d6a62e1d
commit 58eb199036
14 changed files with 326 additions and 92 deletions

@ -164,57 +164,92 @@ void virtual_identity::Init(Core *core)
*/
}
std::string DFHack::bitfieldToString(const void *p, int size, const bitfield_item_info *items)
bool DFHack::findBitfieldField(unsigned *idx, const std::string &name,
unsigned size, const bitfield_item_info *items)
{
std::string res;
const char *data = (const char*)p;
for (unsigned i = 0; i < size; i++) {
if (items[i].name && items[i].name == name)
{
*idx = i;
return true;
}
}
for (int i = 0; i < size; i++) {
unsigned v;
return false;
}
void DFHack::setBitfieldField(void *p, unsigned idx, unsigned size, int value)
{
uint8_t *data = ((uint8_t*)p) + (idx/8);
unsigned shift = idx%8;
uint32_t mask = ((1<<size)-1) << shift;
uint32_t vmask = ((value << shift) & mask);
#define ACCESS(type) *(type*)data = type((*(type*)data & ~mask) | vmask)
if (!(mask & ~0xFFU)) ACCESS(uint8_t);
else if (!(mask & ~0xFFFFU)) ACCESS(uint16_t);
else ACCESS(uint32_t);
#undef ACCESS
}
int DFHack::getBitfieldField(const void *p, unsigned idx, unsigned size)
{
const uint8_t *data = ((const uint8_t*)p) + (idx/8);
unsigned shift = idx%8;
uint32_t mask = ((1<<size)-1) << shift;
if (items[i].size > 1) {
unsigned pdv = *(unsigned*)&data[i/8];
v = (pdv >> (i%8)) & ((1 << items[i].size)-1);
} else {
v = (data[i/8]>>(i%8)) & 1;
#define ACCESS(type) return int((*(type*)data & mask) >> shift)
if (!(mask & ~0xFFU)) ACCESS(uint8_t);
else if (!(mask & ~0xFFFFU)) ACCESS(uint16_t);
else ACCESS(uint32_t);
#undef ACCESS
}
if (v) {
if (!res.empty())
res += ' ';
void DFHack::bitfieldToString(std::vector<std::string> *pvec, const void *p,
unsigned size, const bitfield_item_info *items)
{
for (unsigned i = 0; i < size; i++) {
int value = getBitfieldField(p, i, std::min(1,items[i].size));
if (items[i].name)
res += items[i].name;
else
res += stl_sprintf("UNK_%d", i);
if (value) {
std::string name = format_key(items[i].name, i);
if (items[i].size > 1)
res += stl_sprintf("=%u", v);
name += stl_sprintf("=%u", value);
pvec->push_back(name);
}
if (items[i].size > 1)
i += items[i].size-1;
}
return res;
}
int DFHack::findBitfieldField_(const std::string &name, int size, const bitfield_item_info *items)
int DFHack::findEnumItem(const std::string &name, int size, const char *const *items)
{
for (int i = 0; i < size; i++) {
if (items[i].name && items[i].name == name)
if (items[i] && items[i] == name)
return i;
}
return -1;
}
int DFHack::findEnumItem_(const std::string &name, int size, const char *const *items)
void DFHack::flagarrayToString(std::vector<std::string> *pvec, const void *p,
int bytes, int base, int size, const char *const *items)
{
for (int i = 0; i < size; i++) {
if (items[i] && items[i] == name)
return i;
}
for (unsigned i = 0; i < bytes*8; i++) {
int value = getBitfieldField(p, i, 1);
return -1;
if (value)
{
int ridx = int(i) - base;
const char *name = (ridx >= 0 && ridx < size) ? items[ridx] : NULL;
pvec->push_back(format_key(name, i));
}
}
}

@ -36,6 +36,8 @@ distribution.
#include <ctype.h>
#include <stdarg.h>
#include <sstream>
std::string stl_sprintf(const char *fmt, ...) {
va_list lst;
va_start(lst, fmt);
@ -82,6 +84,20 @@ bool split_string(std::vector<std::string> *out,
return out->size() > 1;
}
std::string join_strings(const std::string &separator, const std::vector<std::string> &items)
{
std::stringstream ss;
for (size_t i = 0; i < items.size(); i++)
{
if (i)
ss << separator;
ss << items[i];
}
return ss.str();
}
std::string toUpper(const std::string &str)
{
std::string rv(str.size(),' ');

@ -61,6 +61,13 @@ using dfproto::CoreTextNotification;
using dfproto::CoreTextFragment;
using google::protobuf::MessageLite;
void DFHack::strVectorToRepeatedField(RepeatedPtrField<std::string> *pf,
const std::vector<std::string> &vec)
{
for (size_t i = 0; i < vec.size(); ++i)
*pf->Add() = vec[i];
}
CoreService::CoreService() {
suspend_depth = 0;

@ -25,6 +25,7 @@ distribution.
#pragma once
#include <string>
#include <sstream>
#include <vector>
#include <map>
@ -36,6 +37,10 @@ distribution.
#undef interface
#endif
/*
* Definitions of DFHack namespace structs used by generated headers.
*/
namespace DFHack
{
class virtual_class {};
@ -153,6 +158,10 @@ inline int linear_index(const DFHack::enum_list_attr<const char*> &lst, const st
return -1;
}
/*
* Definitions of df namespace structs used by generated headers.
*/
namespace df
{
using DFHack::virtual_ptr;
@ -213,8 +222,20 @@ namespace df
namespace enums {}
}
/*
* Templates for access to enum and bitfield traits.
*/
DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector<std::string> &items);
namespace DFHack {
// Enums
/*
* Enum trait tools.
*/
/**
* Return the next item in the enum, wrapping to the first one at the end.
*/
template<class T>
inline typename df::enum_traits<T>::enum_type next_enum_item(T v) {
typedef df::enum_traits<T> traits;
@ -223,55 +244,185 @@ namespace DFHack {
return (iv < traits::last_item_value) ? T(iv+1) : traits::first_item;
}
/**
* Check if the value is valid for its enum type.
*/
template<class T>
inline bool is_valid_enum_item(T v) {
return df::enum_traits<T>::is_valid(v);
}
/**
* Return the enum item key string pointer, or NULL if none.
*/
template<class T>
inline const char *enum_item_raw_key(T val) {
typedef df::enum_traits<T> traits;
return traits::is_valid(val) ? traits::key_table[val - traits::first_item_value] : NULL;
}
/**
* Return the enum item key string pointer, or "?" if none.
*/
template<class T>
inline const char *enum_item_key_str(T val) {
return ifnull(enum_item_raw_key(val), "?");
}
DFHACK_EXPORT int findEnumItem_(const std::string &name, int size, const char *const *items);
template<class BaseType>
std::string format_key(const char *keyname, BaseType val) {
if (keyname) return std::string(keyname);
std::stringstream ss; ss << "?" << val << "?"; return ss.str();
}
/**
* Return the enum item key string, or ?123? (using the numeric value) if unknown.
*/
template<class T>
inline std::string enum_item_key(T val) {
typedef typename df::enum_traits<T>::base_type base_type;
return format_key<base_type>(enum_item_raw_key(val), base_type(val));
}
DFHACK_EXPORT int findEnumItem(const std::string &name, int size, const char *const *items);
/**
* Find an enum item by key string. Returns success code.
*/
template<class T>
inline bool find_enum_item(T *var, const std::string &name) {
typedef df::enum_traits<T> traits;
int size = traits::last_item_value-traits::first_item_value+1;
int idx = findEnumItem_(name, size, traits::key_table);
int idx = findEnumItem(name, size, traits::key_table);
if (idx < 0) return false;
*var = T(traits::first_item_value+idx);
return true;
}
DFHACK_EXPORT int findBitfieldField_(const std::string &name, int size, const bitfield_item_info *items);
/*
* Bitfield tools.
*/
DFHACK_EXPORT bool findBitfieldField(unsigned *idx, const std::string &name,
unsigned size, const bitfield_item_info *items);
DFHACK_EXPORT void setBitfieldField(void *p, unsigned idx, unsigned size, int value);
DFHACK_EXPORT int getBitfieldField(const void *p, unsigned idx, unsigned size);
/**
* Find a bitfield item by key string. Returns success code.
*/
template<class T>
inline int findBitfieldField(const std::string &name) {
inline bool find_bitfield_field(unsigned *idx, const std::string &name, const T* = NULL) {
typedef df::bitfield_traits<T> traits;
return findBitfieldField_(name, traits::bit_count, traits::bits);
return findBitfieldField(&idx, name, traits::bit_count, traits::bits);
}
DFHACK_EXPORT std::string bitfieldToString(const void *p, int size, const bitfield_item_info *items);
/**
* Find a bitfield item by key and set its value. Returns success code.
*/
template<class T>
inline bool set_bitfield_field(T *bitfield, const std::string &name, int value)
{
typedef df::bitfield_traits<T> traits;
unsigned idx;
if (!findBitfieldField(&idx, name, traits::bit_count, traits::bits)) return false;
setBitfieldField(&bitfield->whole, idx, traits::bits[idx].size, value);
return true;
}
/**
* Find a bitfield item by key and retrieve its value. Returns success code.
*/
template<class T>
inline std::string bitfieldToString(const T &val) {
inline bool get_bitfield_field(int *value, const T &bitfield, const std::string &name)
{
typedef df::bitfield_traits<T> traits;
return bitfieldToString(&val.whole, traits::bit_count, traits::bits);
unsigned idx;
if (!findBitfieldField(&idx, name, traits::bit_count, traits::bits)) return false;
*value = getBitfieldField(&bitfield.whole, idx, traits::bits[idx].size);
return true;
}
DFHACK_EXPORT void bitfieldToString(std::vector<std::string> *pvec, const void *p,
unsigned size, const bitfield_item_info *items);
/**
* Represent bitfield bits as strings in a vector.
*/
template<class T>
inline void bitfield_to_string(std::vector<std::string> *pvec, const T &val) {
typedef df::bitfield_traits<T> traits;
bitfieldToString(pvec, &val.whole, traits::bit_count, traits::bits);
}
/**
* Represent bitfield bits as a string, using sep as join separator.
*/
template<class T>
inline std::string bitfield_to_string(const T &val, const std::string &sep = " ") {
std::vector<std::string> tmp;
bitfield_to_string<T>(&tmp, val);
return join_strings(sep, tmp);
}
/*
* BitArray tools
*/
/**
* Find a flag array item by key string. Returns success code.
*/
template<class T>
inline bool find_bitfield_field(unsigned *idx, const std::string &name, const BitArray<T>*) {
T tmp;
if (!find_enum_item(&tmp, name) || tmp < 0) return false;
*idx = unsigned(tmp);
return true;
}
/**
* Find a flag array item by key and set its value. Returns success code.
*/
template<class T>
inline bool set_bitfield_field(BitArray<T> *bitfield, const std::string &name, int value)
{
T tmp;
if (!find_enum_item(&tmp, name) || tmp < 0) return false;
bitfield->set(tmp, value!=0);
return true;
}
/**
* Find a flag array item by key and retrieve its value. Returns success code.
*/
template<class T>
inline bool get_bitfield_field(int *value, const BitArray<T> &bitfield, const std::string &name)
{
T tmp;
if (!find_enum_item(&tmp, name) || tmp < 0) return false;
*value = (bitfield->is_set(tmp) ? 1 : 0);
return true;
}
DFHACK_EXPORT void flagarrayToString(std::vector<std::string> *pvec, const void *p,
int bytes, int base, int size, const char *const *items);
/**
* Represent flag array bits as strings in a vector.
*/
template<class T>
inline void bitfield_to_string(std::vector<std::string> *pvec, const BitArray<T> &val) {
typedef df::enum_traits<T> traits;
int size = traits::last_item_value-traits::first_item_value+1;
flagarrayToString(pvec, val.bits, val.size,
(int)traits::first_item_value, size, traits::key_table);
}
}
#define ENUM_ATTR(enum,attr,val) (df::enum_traits<df::enum>::attrs(val).attr)
#define ENUM_ATTR_STR(enum,attr,val) DFHack::ifnull(ENUM_ATTR(enum,attr,val),"?")
#define ENUM_KEY_STR(enum,val) (DFHack::enum_item_key_str<df::enum>(val))
#define ENUM_KEY_STR(enum,val) (DFHack::enum_item_key<df::enum>(val))
#define ENUM_FIRST_ITEM(enum) (df::enum_traits<df::enum>::first_item)
#define ENUM_LAST_ITEM(enum) (df::enum_traits<df::enum>::last_item)
@ -280,6 +431,10 @@ namespace DFHack {
#define FOR_ENUM_ITEMS(enum,iter) \
for(df::enum iter = ENUM_FIRST_ITEM(enum); iter <= ENUM_LAST_ITEM(enum); iter = df::enum(1+int(iter)))
/*
* Include mandatory generated headers.
*/
// Global object pointers
#include "df/global_objects.h"

@ -253,6 +253,7 @@ Link *linked_list_insert_after(Link *pos, Link *link)
DFHACK_EXPORT bool split_string(std::vector<std::string> *out,
const std::string &str, const std::string &separator,
bool squash_empty = false);
DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector<std::string> &items);
DFHACK_EXPORT std::string toUpper(const std::string &str);
DFHACK_EXPORT std::string toLower(const std::string &str);

@ -27,8 +27,26 @@ distribution.
#include "Export.h"
#include "RemoteServer.h"
#include "DataDefs.h"
namespace DFHack
{
using google::protobuf::RepeatedPtrField;
DFHACK_EXPORT void strVectorToRepeatedField(RepeatedPtrField<std::string> *pf,
const std::vector<std::string> &vec);
/**
* Represent bitfield bits as a repeated string field.
*/
template<class T>
inline void bitfield_to_string(RepeatedPtrField<std::string> *pf, const T &val) {
std::vector<std::string> tmp;
bitfield_to_string<T>(&tmp, val);
strVectorToRepeatedField(pf, tmp);
}
class CoreService : public RPCService {
int suspend_depth;
public:

@ -159,11 +159,11 @@ static void print_job_item_details(color_ostream &out, df::job *job, unsigned id
}
if (item->flags1.whole)
out << " flags1: " << bitfieldToString(item->flags1) << endl;
out << " flags1: " << bitfield_to_string(item->flags1) << endl;
if (item->flags2.whole)
out << " flags2: " << bitfieldToString(item->flags2) << endl;
out << " flags2: " << bitfield_to_string(item->flags2) << endl;
if (item->flags3.whole)
out << " flags3: " << bitfieldToString(item->flags3) << endl;
out << " flags3: " << bitfield_to_string(item->flags3) << endl;
if (!item->reaction_class.empty())
out << " reaction class: " << item->reaction_class << endl;
@ -178,7 +178,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job)
out.color(job->flags.bits.suspend ? Console::COLOR_DARKGREY : Console::COLOR_GREY);
out << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_type);
if (job->flags.whole)
out << " (" << bitfieldToString(job->flags) << ")";
out << " (" << bitfield_to_string(job->flags) << ")";
out << endl;
out.reset_color();
@ -192,7 +192,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job)
{
out << " material: " << mat.toString();
if (job->material_category.whole)
out << " (" << bitfieldToString(job->material_category) << ")";
out << " (" << bitfield_to_string(job->material_category) << ")";
out << endl;
}
@ -201,7 +201,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job)
ItemTypeInfo iinfo(itype, job->item_subtype);
out << " item: " << iinfo.toString()
<< " (" << bitfieldToString(job->item_category) << ")" << endl;
<< " (" << bitfield_to_string(job->item_category) << ")" << endl;
}
if (job->hist_figure_id >= 0)

@ -505,11 +505,8 @@ bool DFHack::parseJobMaterialCategory(df::job_material_category *cat, const std:
for (size_t i = 0; i < items.size(); i++)
{
int id = findBitfieldField<df::job_material_category>(items[i]);
if (id < 0)
if (!set_bitfield_field(cat, items[i], 1))
return false;
cat->whole |= (1 << id);
}
return true;
@ -524,11 +521,8 @@ bool DFHack::parseJobMaterialCategory(df::dfhack_material_category *cat, const s
for (size_t i = 0; i < items.size(); i++)
{
int id = findBitfieldField<df::dfhack_material_category>(items[i]);
if (id < 0)
if (!set_bitfield_field(cat, items[i], 1))
return false;
cat->whole |= (1 << id);
}
return true;

@ -245,13 +245,13 @@ command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
FOR_ENUM_ITEMS(material_flags, i)
{
if (mat->flags.is_set(i))
out.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i));
out.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i).c_str());
}
if (mat->extract_storage != item_type::BARREL)
out.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage));
out.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage).c_str());
if (mat->butcher_special_type != item_type::NONE || mat->butcher_special_subtype != -1)
out.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type), (mat->butcher_special_subtype == -1) ? "NONE" : "?");
out.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type).c_str(), (mat->butcher_special_subtype == -1) ? "NONE" : "?");
if (mat->meat_name[0].size() || mat->meat_name[1].size() || mat->meat_name[2].size())
out.print("\t[MEAT_NAME:%s:%s:%s]\n", mat->meat_name[0].c_str(), mat->meat_name[1].c_str(), mat->meat_name[2].c_str());
if (mat->block_name[0].size() || mat->block_name[1].size())

@ -38,7 +38,9 @@ static command_result feature(color_ostream &out, vector <string> &parameters)
df::feature_init *feature_init = world->cur_savegame.map_features[i];
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is %s\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()), feature_init->flags.is_set(feature_init_flags::Discovered) ? "discovered" : "hidden");
out.print("Feature #%i (\"%s\", type %s) is %s\n",
i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str(),
feature_init->flags.is_set(feature_init_flags::Discovered) ? "discovered" : "hidden");
}
}
else if(cmd == "show")
@ -60,7 +62,8 @@ static command_result feature(color_ostream &out, vector <string> &parameters)
feature_init->flags.set(feature_init_flags::Discovered);
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is now discovered\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()));
out.print("Feature #%i (\"%s\", type %s) is now discovered\n",
i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str());
}
else if(cmd == "hide")
{
@ -81,7 +84,8 @@ static command_result feature(color_ostream &out, vector <string> &parameters)
feature_init->flags.clear(feature_init_flags::Discovered);
string name;
feature_init->getName(&name);
out.print("Feature #%i (\"%s\", type %s) is now hidden\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()));
out.print("Feature #%i (\"%s\", type %s) is now hidden\n",
i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str());
}
else return CR_WRONG_USAGE;

@ -146,7 +146,7 @@ static command_result job_material_in_job(color_ostream &out, MaterialInfo &new_
if (new_mat.getCraftClass() != old_class)
{
out.printerr("New material %s does not satisfy requirement: %s\n",
new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class));
new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class).c_str());
return CR_FAILURE;
}
@ -277,7 +277,7 @@ static command_result job_duplicate(color_ostream &out, vector <string> & parame
job->job_type != job_type::CollectSand &&
job->job_type != job_type::CollectClay))
{
out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type));
out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type).c_str());
return CR_FAILURE;
}

@ -175,13 +175,13 @@ command_result df_probe (color_ostream &out, vector <string> & parameters)
df::tiletype_special special = tileSpecial(tiletype);
df::tiletype_variant variant = tileVariant(tiletype);
out.print("%-10s: %4d %s\n","Class" ,shape,
ENUM_KEY_STR(tiletype_shape, shape));
ENUM_KEY_STR(tiletype_shape, shape).c_str());
out.print("%-10s: %4d %s\n","Material" ,
material, ENUM_KEY_STR(tiletype_material, material));
material, ENUM_KEY_STR(tiletype_material, material).c_str());
out.print("%-10s: %4d %s\n","Special" ,
special, ENUM_KEY_STR(tiletype_special, special));
special, ENUM_KEY_STR(tiletype_special, special).c_str());
out.print("%-10s: %4d %s\n" ,"Variant" ,
variant, ENUM_KEY_STR(tiletype_variant, variant));
variant, ENUM_KEY_STR(tiletype_variant, variant).c_str());
out.print("%-10s: %s\n" ,"Direction",
tileDirection(tiletype).getStr());
out.print("\n");
@ -300,34 +300,38 @@ command_result df_bprobe (color_ostream &out, vector <string> & parameters)
continue;
string name;
building.origin->getName(&name);
out.print("Building %i - \"%s\" - type %s", building.origin->id, name.c_str(), ENUM_KEY_STR(building_type, building.type));
out.print("Building %i - \"%s\" - type %s",
building.origin->id, name.c_str(),
ENUM_KEY_STR(building_type, building.type).c_str());
switch (building.type)
{
case building_type::Civzone:
out.print(", subtype %s", ENUM_KEY_STR(civzone_type, building.civzone_type));
out.print(", subtype %s", ENUM_KEY_STR(civzone_type, building.civzone_type).c_str());
break;
case building_type::Furnace:
out.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type));
out.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type).c_str());
if (building.furnace_type == furnace_type::Custom)
out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
out.print(", custom type %i (%s)", building.custom_type,
world->raws.buildings.all[building.custom_type]->code.c_str());
break;
case building_type::Workshop:
out.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type));
out.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type).c_str());
if (building.workshop_type == workshop_type::Custom)
out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
out.print(", custom type %i (%s)", building.custom_type,
world->raws.buildings.all[building.custom_type]->code.c_str());
break;
case building_type::Construction:
out.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type));
out.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type).c_str());
break;
case building_type::Shop:
out.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type));
out.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type).c_str());
break;
case building_type::SiegeEngine:
out.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type));
out.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type).c_str());
break;
case building_type::Trap:
out.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type));
out.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type).c_str());
break;
default:
if (building.subtype != -1)

@ -235,16 +235,16 @@ command_result df_showmood (color_ostream &out, vector <string> & parameters)
else
out.print("%s unknown body parts (%s:%s:%s)",
mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
bitfield_to_string(item->flags1).c_str(),
bitfield_to_string(item->flags2).c_str(),
bitfield_to_string(item->flags3).c_str());
}
else
out.print("indeterminate %s item (%s:%s:%s)",
mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
bitfield_to_string(item->flags1).c_str(),
bitfield_to_string(item->flags2).c_str(),
bitfield_to_string(item->flags3).c_str());
break;
default:
{
@ -252,9 +252,9 @@ command_result df_showmood (color_ostream &out, vector <string> & parameters)
out.print("item %s material %s flags (%s:%s:%s)",
itinfo.toString().c_str(), mat_name.c_str(),
bitfieldToString(item->flags1).c_str(),
bitfieldToString(item->flags2).c_str(),
bitfieldToString(item->flags3).c_str());
bitfield_to_string(item->flags1).c_str(),
bitfield_to_string(item->flags2).c_str(),
bitfield_to_string(item->flags3).c_str());
break;
}
}

@ -502,7 +502,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj)
if (!pj->holder)
{
out.printerr("Forgetting job %d (%s): holder building lost.",
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type));
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str());
forget_job(out, pj);
return true;
}
@ -511,7 +511,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj)
if (pj->holder->jobs.size() >= 10)
{
out.printerr("Forgetting job %d (%s): holder building has too many jobs.",
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type));
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str());
forget_job(out, pj);
return true;
}
@ -534,7 +534,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj)
deleteJobStruct(recovered);
out.printerr("Inconsistency: job %d (%s) already in list.",
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type));
pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str());
return true;
}
@ -1283,7 +1283,7 @@ static void update_jobs_by_constraints(color_ostream &out)
if (ct->material.isValid())
info = ct->material.toString() + " " + info;
else if (ct->mat_mask.whole)
info = bitfieldToString(ct->mat_mask) + " " + info;
info = bitfield_to_string(ct->mat_mask) + " " + info;
if (is_running != ct->is_active)
{
@ -1337,7 +1337,7 @@ static std::string shortJobDescription(df::job *job)
if (mat.isValid())
rv += " [" + mat.toString() + "]";
else if (mat_mask.whole)
rv += " [" + bitfieldToString(mat_mask) + "]";
rv += " [" + bitfield_to_string(mat_mask) + "]";
return rv;
}