本文整理汇总了C++中BitField类的典型用法代码示例。如果您正苦于以下问题:C++ BitField类的具体用法?C++ BitField怎么用?C++ BitField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isInMaxTrap
bool StateConstraints::isInMaxTrap(const PetriNet& net,
size_t place,
const BitField& places,
const MarkVal* resultMarking) const{
if(!places.test(place))
return false;
/*
0 if M(p_i) = 1
0 if there is (p_i , t) ∈ F such that x_j = 0
for every p_j ∈ t•
1 otherwise
*/
if(resultMarking[place] > 0)
return false;
for(unsigned int t = 0; t < net.numberOfTransitions(); t++){
if(net.inArc(place, t) > 0){
bool exclude = true;
for(unsigned int j = 0; j < net.numberOfPlaces(); j++){
if(net.outArc(t, j) > 0){
exclude &= !places.test(j);
}
}
if(exclude)
return false;
}
}
return true;
}
示例2: updateActive
bool BTMonsterEditor::updateActive(ObjectSerializer &serial, BitField &active, int modField)
{
BTFactory<BTMonster> &monsterList = BTCore::getCore()->getMonsterList();
bool refresh = false;
unsigned int newXp = monsterList[current].calcXp();
if (newXp != prevXp)
{
XMLAction *xpField = serial.find("xp", NULL);
unsigned int *xp = (reinterpret_cast<unsigned int*>(xpField->object));
*xp += newXp;
*xp -= prevXp;
prevXp = newXp;
refresh = true;
}
if (modField == MONSTERLOC_RANGEDTYPE)
{
BitField old = active;
XMLAction *curField = serial.find("rangedType", NULL);
int type = *(reinterpret_cast<int*>(curField->object));
if (type == BTRANGEDTYPE_MAGIC)
{
if (!active.isSet(MONSTERLOC_RANGEDSPELL))
{
active.set(MONSTERLOC_RANGEDSPELL);
XMLAction *extraField = serial.find("rangedSpell", NULL);
*(reinterpret_cast<int*>(extraField->object)) = 0;
}
}
else
active.clear(MONSTERLOC_RANGEDSPELL);
return (refresh || (!(active == old)));
}
return refresh;
}
示例3:
void
TestBitField3D<T>::testDefaultConstructor()
{
DEFINE_TYPEDEFS;
BitField bf;
CPPUNIT_ASSERT(bf.size() == 0);
CPPUNIT_ASSERT(bf.capacity() == 0);
CPPUNIT_ASSERT(bf.toString() == "");
}
示例4: DecreaseHave
void PieceManager::DecreaseHave(const BitField &remote_bitf)
{
for(size_t i = 0; i < remote_bitf.NBits(); ++i)
{
if(remote_bitf.IsSet(i))
{
DecreaseHave(i);
}
}
}
示例5: next
BitField StateConstraints::maxTrap(const PetriNet& net,
BitField places,
const MarkVal* resultMarking) const{
BitField next(places.size());
BitField prev(places);
do{
prev = places;
for(size_t i = 0; i < places.size(); i++)
next.set(i, isInMaxTrap(net, i, places, resultMarking));
places = next;
}while(prev != next);
return places;
}
示例6: setup
int BTSerializedEditor::setup(ObjectSerializer &serial, BitField &active, std::vector<BTDisplay::selectItem> &items)
{
size_t current = 0;
for (int i = 0; i < entries; ++i)
{
if (!active.isSet(i))
continue;
XMLAction *curField = serial.find(field[i], NULL);
if (current >= entries)
items.push_back(BTDisplay::selectItem());
if (curField->getType() == XMLTYPE_OBJECT)
{
XMLObject *obj = reinterpret_cast<XMLObject*>(curField->object);
items[current].name = std::string(description[i]) + ": " + obj->createString();
items[current].value = i;
++current;
}
else if (curField->getType() == XMLTYPE_CREATE)
{
XMLArray *obj = reinterpret_cast<XMLArray*>(curField->object);
for (size_t k = 0; k < obj->size(); k++)
{
if (current >= items.size())
items.push_back(BTDisplay::selectItem());
items[current].name = std::string(description[i]) + ": " + obj->get(k)->createString();
items[current].value = i;
++current;
}
if (current >= items.size())
items.push_back(BTDisplay::selectItem());
items[current].name = std::string(description[i]) + ": <New>";
items[current].value = i;
++current;
}
else if (curField->getType() == XMLTYPE_VECTORSTRING)
{
std::vector<std::string> *obj = reinterpret_cast<std::vector<std::string>*>(curField->object);
for (size_t k = 0; k < obj->size(); k++)
{
if (current >= items.size())
items.push_back(BTDisplay::selectItem());
items[current].name = std::string(description[i]) + ": " + (*obj)[k];
items[current].value = i;
++current;
}
if (current >= items.size())
items.push_back(BTDisplay::selectItem());
items[current].name = std::string(description[i]) + ": <New>";
items[current].value = i;
++current;
}
else
{
items[current].name = std::string(description[i]) + ": " + curField->createString();
items[current].value = i;
++current;
}
}
return current;
}
示例7: IncreaseHave
void PieceManager::IncreaseHave(const BitField &remote_bitf)
{
if(remote_bitf.NBits() != m_bitfield.NBits())
{
assert(0);
return;
}
for(size_t i = 0; i < remote_bitf.NBits(); ++i)
{
if(remote_bitf.IsSet(i))
{
IncreaseHave(i);
}
}
}
示例8: assert
PieceManager::PieceManager(const BitField &bit_field, const TorrentFile &tf, Storage &storage)
:m_bitfield(bit_field)
, m_torrent_file(tf)
, m_storage(storage)
, m_is_endgame(false)
{
assert(m_storage.IsOpen());
assert(bit_field.NBits() == tf.GetPieceCount());
}
示例9: FuseComboBox
QWidget *FuseDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option,
const QModelIndex & index) const
{
BitField field = index.model()->data(index, Qt::UserRole).value<BitField>();
if (field.isEnum()) {
FuseComboBox *editor = new FuseComboBox(parent);
connect(editor, SIGNAL(activated(int)), this, SLOT(commitSlot()));
editor->setAutoFillBackground(true);
int current = 0;
QMapIterator<int, QString> i(field.enumValues);
while (i.hasNext()) {
i.next();
editor->addItem(i.value(), i.key());
if (field.value() == i.key())
current = i.key();
}
editor->setCurrentIndex(current);
return editor;
} else {
示例10: initActive
void BTMonsterEditor::initActive(ObjectSerializer &serial, BitField &active)
{
BTFactory<BTMonster> &monsterList = BTCore::getCore()->getMonsterList();
prevXp = monsterList[current].calcXp();
XMLAction *curField = serial.find("rangedType", NULL);
int type = *(reinterpret_cast<int*>(curField->object));
for (int i = 0; i < entries; ++i)
{
switch (i)
{
case MONSTERLOC_RANGEDSPELL:
{
if (type == BTRANGEDTYPE_MAGIC)
active.set(i);
else
active.clear(i);
break;
}
default:
active.set(i);
}
}
}
示例11: usedWords
//------------------------------------------------------------------------------
bool BitField::operator== (BitField const& bf) {
// Sizes must agree.
if (bits() != bf.bits())
return false;
// All bits in used words must agree.
unsigned words = usedWords();
for (unsigned i=0; i<words; ++i)
if (_data[i] != bf._data[i])
return false;
// If we've made it this far they're the same.
return true;
}
示例12: useAutoCombatSkill
void BTPc::useAutoCombatSkill(bool melee, BitField &special)
{
BTGame *game = BTGame::getGame();
BTSkillList &skillList = game->getSkillList();
for (int i = 0; i < skillList.size(); ++i)
{
if ((skillList[i]->use == BTSKILLUSE_AUTOCOMBAT) ||
((melee) && (skillList[i]->use == BTSKILLUSE_AUTOCOMBATMELEE)) ||
((!melee) && (skillList[i]->use == BTSKILLUSE_AUTOCOMBATRANGED)))
{
if (((-1 == skillList[i]->after) || (combat.skillUsed == skillList[i]->after)) && (useSkill(i)))
{
special.set(skillList[i]->effect);
}
}
}
}
示例13: get_req_piece_rarely
bool PieceManager::get_req_piece_rarely(t_uint32 &piece_idx, const BitField &remote_own_pieces)
{
for(size_t i = 1; i < m_interests.size(); ++i)
{
for(size_t j = 0; j < m_interests[i].size(); ++j)
{
t_uint32 pidx = m_interests[i][j];
if(remote_own_pieces.IsSet(pidx) && m_pieces_info[pidx].state == P_FREE)
{
piece_idx = pidx;
return true;
}
}
}
return false;
}
示例14: get_req_in_downloading
bool PieceManager::get_req_in_downloading(SliceInfo &slice_info, const BitField &remote_own_pieces)
{
t_uint32 best_pidx = NONE_PIECE_INDEX;
t_uint32 best_num = 0;
DownloadingPiece *pdown = 0;
for(StartedPiecesMap::iterator it = m_started_pieces.begin(); it != m_started_pieces.end(); ++it)
{
t_uint32 pidx = it->second->GetPieceIdx();
assert(pidx < m_bitfield.NBits());
assert(m_pieces_info[pidx].state == P_DOWNLOADING);
if(remote_own_pieces.IsSet(pidx) && it->second->HasFreeSlice())
{
if(m_pieces_info[pidx].have > best_num)
{
best_pidx = pidx;
best_num = m_pieces_info[pidx].have;
pdown = it->second;
}
}
}
if(pdown != 0)
{
assert(best_num > 0);
bool res = pdown->GetRequest(slice_info);
assert(res);
return true;
} else
{
return false;
}
}
示例15: start
void BTEditor::editSpecial(BTDisplay &d, BTSpecial *special)
{
if (NULL == special)
{
special = new BTSpecial;
levelMap->addSpecial(special);
}
BTDisplayConfig *oldConfig = d.getConfig();
BTDisplayConfig config;
XMLSerializer parser;
config.serialize(&parser);
parser.parse(BTDisplay::applyDisplayDir("data/specialedit.xml").c_str(), true);
d.setConfig(&config);
int start(0);
int current(0);
BTSpecialBody *body = special->getBody();
std::vector<operationList> ops;
std::vector<BTDisplay::selectItem> list(2);
list[0].name = std::string("Name: ") + special->getName();
list[1].name = "Flags: " + special->printFlags(false);
buildOperationList(d, body, list, ops);
d.addSelection(list.data(), list.size(), start, current);
int key;
char extra[6] = {BTKEY_INS, BTKEY_DEL, BTKEY_CTRL_C, BTKEY_CTRL_V, BTKEY_CTRL_X, 0};
while (27 != (key = d.process(extra)))
{
d.clearText();
if (current == 0)
{
std::string name = special->getName();
d.addReadString("Name: ", 25, name);
key = d.process();
if ('\r' == key)
special->setName(name);
d.clearText();
list[0].name = std::string("Name: ") + special->getName();
}
else if (current == 1)
{
BTSpecialFlagList &lookup = getSpecialFlagList();
BitField bits = special->getFlag();
BTDisplay::selectItem lookupItem[lookup.size()];
for (size_t i = 0; i < lookup.size(); ++i)
{
lookupItem[i].name = lookup.getName(i);
if (bits.isSet(i))
lookupItem[i].first = '*';
}
int lookupStart(0);
int lookupCurrent(0);
d.addSelection(lookupItem, lookup.size(), lookupStart, lookupCurrent);
int key;
while (27 != (key = d.process()))
{
if (bits.toggle(lookupCurrent))
lookupItem[lookupCurrent].first = '*';
else
lookupItem[lookupCurrent].first = 0;
}
special->setFlag(bits);
d.clearText();
list[1].name = "Flags: " + special->printFlags(false);
}
else
{
if (BTKEY_INS == key)
{
if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
{
ops[list[current].value].parent->insertOperation(ops[list[current].value].op, new BTSpecialCommand(BTSPECIALCOMMAND_NOTHING));
}
}
else if (BTKEY_DEL == key)
{
if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
{
ops[list[current].value].parent->eraseOperation(ops[list[current].value].op);
}
}
else if (BTKEY_CTRL_X == key)
{
if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
{
if (clipboard)
delete clipboard;
clipboard = ops[list[current].value].op->clone();
ops[list[current].value].parent->eraseOperation(ops[list[current].value].op);
}
}
else if (BTKEY_CTRL_C == key)
{
if ((ops[list[current].value].op != NULL) && (ops[list[current].value].parent != NULL))
{
if (clipboard)
delete clipboard;
clipboard = ops[list[current].value].op->clone();
}
}
else if (BTKEY_CTRL_V == key)
{
//.........这里部分代码省略.........