Exemple #1
0
HFSVolume::HFSVolume(std::shared_ptr<Reader> reader)
: m_reader(reader), m_embeddedReader(nullptr), m_overflowExtents(nullptr), m_attributes(nullptr),
  m_fileZone(6400), m_btreeZone(6400)
{
	static_assert(sizeof(HFSPlusVolumeHeader) >= sizeof(HFSMasterDirectoryBlock), "Bad read is about to happen");
	
	if (m_reader->read(&m_header, sizeof(m_header), 1024) != sizeof(m_header))
		throw std::runtime_error("Cannot read volume header");
	
	if (be(m_header.signature) == HFS_SIGNATURE)
	{
		HFSMasterDirectoryBlock* block = reinterpret_cast<HFSMasterDirectoryBlock*>(&m_header);
		processEmbeddedHFSPlus(block);
	}
	
	if (be(m_header.signature) != HFSP_SIGNATURE && be(m_header.signature) != HFSX_SIGNATURE)
		throw std::runtime_error("Invalid HFS+/HFSX signature");

	std::shared_ptr<HFSFork> fork (new HFSFork(this, m_header.extentsFile));
	m_overflowExtents = new HFSExtentsOverflowBTree(fork, &m_btreeZone);
	
	if (m_header.attributesFile.logicalSize != 0)
	{
		fork.reset(new HFSFork(this, m_header.attributesFile, kHFSAttributesFileID));
		m_attributes = new HFSAttributeBTree(fork, &m_btreeZone);
	}
}
BOMBTree::CompareResult BOMFilesBTree::keyComparator(const BOMPathKey* k1, const BOMPathKey* k2)
{
	if (be(k2->parentItemID) > be(k2->parentItemID))
		return Greater;
	else if (be(k2->parentItemID) < be(k2->parentItemID))
		return Smaller;
	else
		return (BOMBTree::CompareResult) strcmp(k1->name, k2->name);
}
int HFSAttributeBTree::cnidComparator(const Key* indexKey, const Key* desiredKey)
{
	const HFSPlusAttributeKey* indexAttributeKey = reinterpret_cast<const HFSPlusAttributeKey*>(indexKey);
	const HFSPlusAttributeKey* desiredAttributeKey = reinterpret_cast<const HFSPlusAttributeKey*>(desiredKey);

	if (be(indexAttributeKey->fileID) > be(desiredAttributeKey->fileID))
		return 1;
	else if (be(indexAttributeKey->fileID) < be(desiredAttributeKey->fileID))
		return -1;
	else
		return 0;
}
Exemple #4
0
HFSBTreeNode HFSBTree::traverseTree(int nodeIndex, const Key* indexKey, KeyComparator comp, bool wildcard)
{
	//std::cout << "Examining node " << nodeIndex << std::endl;
	HFSBTreeNode node(m_reader, nodeIndex, be(m_header.nodeSize));

	switch (node.kind())
	{
		case NodeKind::kBTIndexNode:
		{
			int position;
			uint32_t* childIndex;

			if (wildcard)
			{
				auto it = std::lower_bound(node.begin<Key>(), node.end<Key>(), indexKey, [=](const Key* keyA, const Key* keyB) {
					return comp(keyA, keyB) < 0;
				});

				position = it.index() - 1;
			}
			else
			{
				auto it = std::upper_bound(node.begin<Key>(), node.end<Key>(), indexKey, [=](const Key* keyA, const Key* keyB) {
					return comp(keyA, keyB) < 0;
				});

				position = it.index() - 1;
			}
			
			if (position < 0)
				position = 0;
			
			// recurse down
			childIndex = node.getRecordData<uint32_t>(position);
			
			return traverseTree(be(*childIndex), indexKey, comp, wildcard);
		}
		case NodeKind::kBTLeafNode:
		{
			return node;
		}
		case NodeKind::kBTHeaderNode:
		case NodeKind::kBTMapNode:
			break;
		default:
			std::cerr << "Invalid node kind! Kind: " << int(node.kind()) << std::endl;
			
	}

	return HFSBTreeNode();
}
Exemple #5
0
bool HFSVolume::isHFSPlus(std::shared_ptr<Reader> reader)
{
	HFSPlusVolumeHeader header;
	if (reader->read(&header, sizeof(header), 1024) != sizeof(header))
		return false;
	
	if (be(header.signature) == HFS_SIGNATURE)
	{
		HFSMasterDirectoryBlock* block = reinterpret_cast<HFSMasterDirectoryBlock*>(&header);
		return be(block->drEmbedSigWord) == HFSP_SIGNATURE || be(block->drEmbedSigWord) == HFSX_SIGNATURE;
	}
	
	return be(header.signature) == HFSP_SIGNATURE || be(header.signature) == HFSX_SIGNATURE;
}
void THierarchicalCluster::permute(const TIntList &neworder)
{
  if ((!branches && neworder.size()) || (branches->size() != neworder.size()))
    raiseError("the number of clusters does not match the lenght of the permutation vector");

  int *temp = new int [last - first], *t = temp;
  TIntList::const_iterator pi = neworder.begin();
  THierarchicalClusterList::iterator bi(branches->begin()), be(branches->end());
  THierarchicalClusterList newBranches;

  for(; bi != be; bi++, pi++) {
    PHierarchicalCluster branch = branches->at(*pi);
    newBranches.push_back(branch);
    TIntList::const_iterator bei(mapping->begin() + branch->first), bee(mapping->begin() + branch->last);
    const int offset = (t - temp) - (branch->first - first);
    for(; bei != bee; *t++ = *bei++);
    if (offset)
      branch->recursiveMove(offset);
  }

  TIntList::iterator bei(mapping->begin() + first), bee(mapping->begin() + last);
  for(t = temp; bei!=bee; *bei++ = *t++);

  bi = branches->begin();
  THierarchicalClusterList::const_iterator nbi(newBranches.begin());
  for(; bi != be; *bi++ = *nbi++);
}
Exemple #7
0
struct ping *ping_packet(struct mac mac, struct ip_address ip)
{
    struct ping *packet = (struct ping *)malloc(sizeof(struct ping));
    construct_eth_header(&packet->eth, mac, TYPE_IP);
    construct_ip_header(&packet->ip, 0x01, my_ip, ip);
    packet->data.type = 8;
    packet->data.code = 0;
    packet->data.checksum = 0;
    packet->data.identifier = 0x0883;
    packet->data.sequence = 0;
    packet->ip.length = be(sizeof(struct ip_header) + sizeof(struct ping_data));
    packet->ip.dsp_ecn = 0;
    packet->ip.identification = 0x0800;
    packet->ip.checksum = 0;
    packet->ip.checksum = checksum((unsigned char *)(&packet->ip), 20);
    unsigned char data[40] = {
        0x2a, 0x7f, 0x0a, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
        0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
        0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
        0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
        0x1e, 0x1f
    };
    int i;
    for (i = 0; i < 40; i++)
        packet->data.data[i] = data[i];
    packet->data.checksum = checksum((unsigned char *)(&packet->data), 56);
    return packet;
}
Exemple #8
0
void Bond::Edit(Render2D *r)
{
    int db1 = 0;

    qDebug() << "edit bond";
    BondEditDialog be( r, start, end, PreviewWidget::BOND, order, dashed, thick, 0, color );

    if ( auto_wside == 0 )
        db1 = wside;
    be.setDoubleBond( db1 );
    if ( !be.exec() )
        return;
    qDebug() << "change";
    color = be.Color();
    order = be.Order();
    dashed = be.Dash();
    thick = be.Thick();
    db1 = be.DoubleBond();
    if ( db1 == 0 ) {
        auto_wside = 1;
    } else {
        auto_wside = 0;
        wside = db1;
    }
}
Exemple #9
0
int main(int argc, char **argv) {
   KApplication a(argc, argv, "kwalletbackendtest");

   KWallet::Backend be("ktestwallet");
   printf("KWalletBackend constructed\n");

   QByteArray apass, bpass, cpass;

   apass.duplicate("apassword", 9);
   bpass.duplicate("bpassword", 9);
   cpass.duplicate("cpassword", 9);

   printf("Passwords initialised.\n");
   int rc = be.close(apass);

   printf("be.close(apass) returned %d  (should be -255)\n", rc);

   rc = be.open(bpass);

   printf("be.open(bpass) returned %d  (should be 0 or 1)\n", rc);

   rc = be.close(bpass);

   printf("be.close(bpass) returned %d  (should be 0)\n", rc);

   rc = be.open(apass);

   printf("be.open(apass) returned %d  (should be negative)\n", rc);

   rc = be.open(bpass);

   printf("be.open(bpass) returned %d  (should be 0)\n", rc);

   return 0;
}
std::unique_ptr<ska::Task> StateFightLoading::load() {
	return std::make_unique<ska::Task>([&](ska::Task&) {
		/* Ajout InputComponent au Pokémon,
		Ajout d'un IAMovementComponent au dresseur (m_player),
		Ajout d'un composant de combat au Pokémon
		Ajout d'une HP Bar */

		m_entityManager.addComponent<BattleComponent>(m_pokemonId, BattleComponent());
		m_entityManager.addComponent<BattleComponent>(m_opponentId, BattleComponent());

		ska::IARandomMovementComponent iarmc;
		iarmc.emitter = m_pokemonId;
		iarmc.delay = 300;
		iarmc.type = ska::RandomMovementType::CIRCLE_AROUND;

		m_entityManager.addComponent<ska::IARandomMovementComponent>(m_trainerId, std::move(iarmc));
		m_entityManager.addComponent<ska::InputComponent>(m_pokemonId, std::move(**m_ic));
		*m_ic = nullptr;

		auto& hc = m_entityManager.getComponent<ska::HitboxComponent>(m_pokemonId);
		auto& pc = m_entityManager.getComponent<ska::PositionComponent>(m_pokeball);
		m_pokeball = 0;
		ska::Rectangle hitbox{ pc.x + hc.xOffset, pc.y + hc.yOffset, static_cast<int>(hc.width), static_cast<int>(hc.height) };

		const auto targetBlock = m_worldState.getWorld().getCollisionProfile().placeOnNearestPracticableBlock(1, hitbox, 1);
		pc.x = targetBlock.x - hc.xOffset;
		pc.y = targetBlock.y - hc.yOffset;
		m_entityManager.addComponent<ska::PositionComponent>(m_pokemonId, std::move(pc));

		BattleEvent be(BATTLE_START, **m_cameraSystem, m_pokemonId, m_opponentId, m_entityManager);
		m_eventDispatcher.ska::Observable<BattleEvent>::notifyObservers(be);

		return false;
	});
}
// TODO: najdi pametno mesto za naslednji dve funkciji
// compute waldZ statistic from beta and beta_se
PAttributedFloatList TLogRegLearner::computeWaldZ(PAttributedFloatList &beta, PAttributedFloatList &beta_se) 
{
  PAttributedFloatList waldZ=PAttributedFloatList(mlnew TAttributedFloatList(beta->attributes));
  TAttributedFloatList::const_iterator b(beta->begin()), be(beta->end());
  TAttributedFloatList::const_iterator s(beta_se->begin()), se(beta_se->end());
  for (; (b!=be) && (s!=se); b++, s++) 
    waldZ->push_back((*b)/(*s));
   return waldZ;
}
Exemple #12
0
void goto_symext::process_array_expr_rec(
  exprt &expr,
  const typet &type) const
{
  if(expr.id()==ID_if)
  {
    if_exprt &if_expr=to_if_expr(expr);
    process_array_expr_rec(if_expr.true_case(), type);
    process_array_expr_rec(if_expr.false_case(), type);
  }
  else if(expr.id()==ID_index)
  {
    // strip index
    index_exprt &index_expr=to_index_expr(expr);
    exprt tmp=index_expr.array();
    expr.swap(tmp);
  }
  else if(expr.id()==ID_typecast)
  {
    // strip
    exprt tmp=to_typecast_expr(expr).op0();
    expr.swap(tmp);
    process_array_expr_rec(expr, type);
  }
  else if(expr.id()==ID_address_of)
  {
    // strip
    exprt tmp=to_address_of_expr(expr).op0();
    expr.swap(tmp);
    process_array_expr_rec(expr, type);
  }
  else if(expr.id()==ID_symbol &&
          expr.get_bool(ID_C_SSA_symbol) &&
          to_ssa_expr(expr).get_original_expr().id()==ID_index)
  {
    const ssa_exprt &ssa=to_ssa_expr(expr);
    const index_exprt &index_expr=to_index_expr(ssa.get_original_expr());
    exprt tmp=index_expr.array();
    expr.swap(tmp);
  }
  else
    Forall_operands(it, expr)
      process_array_expr_rec(*it, it->type());

  if(!base_type_eq(expr.type(), type, ns))
  {
    byte_extract_exprt be(byte_extract_id());
    be.type()=type;
    be.op()=expr;
    be.offset()=gen_zero(index_type());

    expr.swap(be);
  }
}
void BOMFilesBTree::listDirectory(uint32_t parentID, std::map<uint32_t, BOMPathElement>& contents)
{
	std::vector<BOMBTreeNode> leaves;
	BOMPathKey key;
	
	contents.clear();
	
	key.parentItemID = htobe32(parentID);
	key.name[0] = 0;
	
	leaves = findLeafNodes(&key, BOMFilesBTree::KeyComparator(keyComparator));
	
	for (BOMBTreeNode& leaf : leaves)
	{
		BOMBTreeNode::RecordIterator<BOMPathKey> it;
		
		it = std::lower_bound(leaf.begin<BOMPathKey>(), leaf.end<BOMPathKey>(), key.parentItemID,
			[](const BOMPathKey* k, uint32_t v) {
				return be(k->parentItemID) < be(v);
		});
		
		while (it != leaf.end<BOMPathKey>())
		{
			BOMPathKey* lkey;
			BOMLeafDescriptor* ldesc;
			BOMPathRecord* ldata;
			
			lkey = *it;
			
			if (lkey->parentItemID != key.parentItemID)
				break;
			
			ldesc = leaf.getRecordData<BOMLeafDescriptor>(it.index());
			ldata = m_store->getBlockData<BOMPathRecord>(be(ldesc->recordID));
			
			// TODO: size64
			contents[be(ldesc->itemID)] = BOMPathElement(lkey->name, ldata, 0);
			++it;
		}
	}
}
Exemple #14
0
void Arrow::Edit( Render2D* r )
{
    qDebug() << "edit arrow";
    BondEditDialog be( r, start, end, PreviewWidget::ARROW, 0, 0, thick, style, color );

    if ( !be.exec() )
        return;
    qDebug() << "change";
    style = be.Style();
    color = be.Color();
    thick = be.Thick();
}
int32_t DMGPartition::readRun(void* buf, int32_t runIndex, uint64_t offsetInSector, int32_t count)
{
	BLKXRun* run = &m_table->runs[runIndex];
	RunType runType = RunType(be(run->type));
	
	count = std::min<uint64_t>(count, uint64_t(be(run->sectorCount))*512 - offsetInSector);
	
#ifdef DEBUG
	std::cout << "readRun(): runIndex = " << runIndex << ", offsetInSector = " << offsetInSector << ", count = " << count << std::endl;
#endif
	
	switch (runType)
	{
		case RunType::Unknown: // My guess is that this value indicates a hole in the file (sparse file)
		case RunType::ZeroFill:
			//std::cout << "ZeroFill\n";
			memset(buf, 0, count);
			return count;
		case RunType::Raw:
			//std::cout << "Raw\n";
			return m_disk->read(buf, count, be(run->compOffset) + be(m_table->dataStart) + offsetInSector);
		case RunType::LZFSE:
#ifndef COMPILE_WITH_LZFSE
			throw function_not_implemented_error("LZFSE is not yet supported");
#endif
		case RunType::Zlib:
		case RunType::Bzip2:
		case RunType::ADC:
		{
			std::unique_ptr<DMGDecompressor> decompressor;
			std::shared_ptr<Reader> subReader;
			
			subReader.reset(new SubReader(m_disk, be(run->compOffset) + be(m_table->dataStart), be(run->compLength)));
			decompressor.reset(DMGDecompressor::create(runType, subReader));
			
			if (!decompressor)
				throw std::logic_error("DMGDecompressor::create() returned nullptr!");

			unsigned long long int compLength = be(run->sectorCount)*512;
			if ( offsetInSector > compLength )
				return 0;
			if ( offsetInSector + count > compLength )
				count = compLength - offsetInSector;

			int32_t dec = decompressor->decompress((uint8_t*)buf, count, offsetInSector);
			if (dec < count)
				throw io_error("Error decompressing stream");
			return count;
		}
		default:
			return 0;
	}
}
std::map<std::string, std::vector<uint8_t>> HFSAttributeBTree::getattr(HFSCatalogNodeID cnid)
{
	HFSPlusAttributeKey key;
	std::vector<HFSBTreeNode> leaves;
	std::map<std::string, std::vector<uint8_t>> rv;

	memset(&key, 0, sizeof(key));
	key.fileID = htobe32(cnid);

	leaves = findLeafNodes((Key*) &key, cnidComparator);
	
	for (const HFSBTreeNode& leaf : leaves)
	{
		for (int i = 0; i < leaf.recordCount(); i++)
		{
			HFSPlusAttributeKey* recordKey = leaf.getRecordKey<HFSPlusAttributeKey>(i);
			HFSPlusAttributeDataInline* data;
			std::vector<uint8_t> vecData;
			std::string name;

			if (be(recordKey->fileID) != cnid)
				continue;

			data = leaf.getRecordData<HFSPlusAttributeDataInline>(i);

			// process data
			if (be(data->recordType) != kHFSPlusAttrInlineData)
				continue;
			
			vecData = std::vector<uint8_t>(data->attrData, &data->attrData[be(data->attrSize)]);
			name = UnicharToString(be(recordKey->attrNameLength), recordKey->attrName);
			
			rv[name] = vecData;
		}
	}
	
	return rv;
}
bool HFSAttributeBTree::getattr(HFSCatalogNodeID cnid, const std::string& attrName, std::vector<uint8_t>& dataOut)
{
	HFSPlusAttributeKey key;
	HFSBTreeNode leafNode;
	UnicodeString ucAttrName = UnicodeString::fromUTF8(attrName);
	
	memset(&key, 0, sizeof(key));
	key.fileID = htobe32(cnid);
	
	key.attrNameLength = StringToUnichar(attrName, key.attrName, sizeof(key.attrName));
	key.attrNameLength = htobe16(key.attrNameLength);
	
	leafNode = findLeafNode((Key*) &key, cnidAttrComparator);
	if (leafNode.isInvalid())
		return false;
	
	for (int i = 0; i < leafNode.recordCount(); i++)
	{
		HFSPlusAttributeKey* recordKey = leafNode.getRecordKey<HFSPlusAttributeKey>(i);
		HFSPlusAttributeDataInline* data;
		
		UnicodeString recAttrName((char*)recordKey->attrName, be(recordKey->attrNameLength)*2, "UTF-16BE");

		if (be(recordKey->fileID) == cnid && recAttrName == ucAttrName)
		{
			data = leafNode.getRecordData<HFSPlusAttributeDataInline>(i);

			// process data
			if (be(data->recordType) != kHFSPlusAttrInlineData)
				continue;
		
			dataOut = std::vector<uint8_t>(data->attrData, &data->attrData[be(data->attrSize)]);
			return true;
		}
	}
	
	return false;
}
SS DFStatement::buildSS(
 const StringList &inVarNameList,  const DoubleList &inCoefList,
 const StringList &outVarNameList, const DoubleList &outCoefList
) {
	//
	// FIRST, BUILD THE FILTER EQUATION
	//
	StringList::const_iterator inVarNameItr  = inVarNameList.begin();
	DoubleList::const_iterator inCoefItr     = inCoefList.begin();
	StringList::const_iterator outVarNameItr = outVarNameList.begin();
	DoubleList::const_iterator outCoefItr    = outCoefList.begin();

	BE be(  0, "+", BE( *inCoefItr, "*", *inVarNameItr )  );
	while( ++inVarNameItr != inVarNameList.end() ) {
		(void)++inCoefItr;
		be = BE(  be, "+", BE( *inCoefItr, "*", *inVarNameItr )  );
	}
	while( ++outVarNameItr != outVarNameList.end() ) {
		(void)++outCoefItr;
		be = BE(  be, "-", BE( *outCoefItr, "*", *outVarNameItr )  );
	}

	be = BE( be, "/", outCoefList.front() );
	be = BE( outVarNameList.front(), "=", be );

	//
	// SHIFT THE VARIABLES
	//
	SS ss(  IE( 1 ), be  );

	(void)--inVarNameItr;
	while( inVarNameItr != inVarNameList.begin() ) {
		StringList::const_iterator nxtInVarNameItr = inVarNameItr;
		(void)--nxtInVarNameItr;

		ss = SS(  ss, BE( *inVarNameItr, "=", *nxtInVarNameItr )  );
		inVarNameItr = nxtInVarNameItr;
	}

	(void)--outVarNameItr;
	while( outVarNameItr != outVarNameList.begin() ) {
		StringList::const_iterator nxtOutVarNameItr = outVarNameItr;
		(void)--nxtOutVarNameItr;

		ss = SS(  ss, BE( *outVarNameItr, "=", *nxtOutVarNameItr )  );
		outVarNameItr = nxtOutVarNameItr;
	}

	return ss;
}
Exemple #19
0
void defile(vector<string> &options)
{ bool changed;
  do {
    changed=false;
    vector<string> reoptions=options;
    options.clear();
    ITERATE(vector<string>, oi, reoptions) {
      if ((*oi)[0]=='@') {
        string::iterator be((*oi).end());
        do --be; while ((*be!=':') && (*be!='@'));
        if (*be=='@') {
          ifstream pstr(string(be+1, (*oi).end()).c_str());
          if (!pstr.is_open() || pstr.fail() || pstr.eof())
            raiseError("invalid parameter file");
          while (!pstr.fail() && !pstr.eof()) {
            string nl=getSLine(pstr);
            if (nl.length()) options.push_back(string(nl.begin(), nl.end()));
          }
        }
        else {
          string filename((*oi).begin()+1, be), lineNos(be+1, (*oi).end());
          int lineNo=atoi(lineNos.c_str());
          if (!lineNo)
            raiseError("Invalid line number (%s) for parameter file %s.", lineNos.c_str(), filename.c_str());
          ifstream pstr(filename.c_str());
          if (!pstr.is_open() || pstr.fail() || pstr.eof())
            raiseError("Invalid parameter file (%s).", (*oi).c_str());
          while(--lineNo) {
            getSLine(pstr);
            if (pstr.fail() || pstr.eof())
              raiseError("can't read parameter file %s to line %s", filename.c_str(), lineNos.c_str());
          }
          string nl=getSLine(pstr);
          if (nl[0]=='=') options.push_back(string(nl.begin()+1, nl.end()));
          else {
            vector<string> ns;
            string2atoms(nl, ns);
            ITERATE(vector<string>, ni, ns) options.push_back(*ni);
          }
        }
        changed=true;
      }
      else options.push_back(*oi);
    }
  } while (changed);
}
std::unique_ptr<ska::Task> StateFightLoading::unload() {
	return std::make_unique<ska::Task>([&](ska::Task&) {
		*m_ic = &m_entityManager.getComponent<ska::InputComponent>(m_pokemonId);
		m_entityManager.removeComponent<ska::InputComponent>(m_pokemonId);

		BattleEvent be(BATTLE_END, **m_cameraSystem, m_pokemonId, m_opponentId, m_entityManager);
		m_eventDispatcher.ska::Observable<BattleEvent>::notifyObservers(be);

		m_entityManager.removeComponent<BattleComponent>(m_pokemonId);
		m_entityManager.removeComponent<BattleComponent>(m_opponentId);

		if (m_entityManager.hasComponent<ska::AnimationComponent>(m_trainerId)) {
			auto& dac = m_entityManager.getComponent<ska::AnimationComponent>(m_trainerId);
			/*dac.type = ska::AnimationComponent::MOVEMENT;
			dac.looked = 0;*/
		}
		return false;
	});
}
Mesh2::Mesh2(const char * filename)
{ // read the mesh  

  int nt,nv,nbe;
  int ok=load(filename);
  if(ok)
    {
      ifstream f(filename);
      if(!f) {cerr << "Mesh2::Mesh2 Erreur openning " << filename<<endl;exit(1);}
      if(verbosity)
      cout << " Read On file \"" <<filename<<"\""<<  endl;
      f >> nv >> nt >> nbe ;
      this->set(nv,nt,nbe);
      if(verbosity)
      cout << "  -- Nb of Vertex " << nv << " " << " Nb of Triangles " << nt 
	   << " , Nb of border edges " << nbe <<  endl;
      assert(f.good() && nt && nv) ;
      for (int i=0;i<nv;i++)    
	{
	  f >> this->vertices[i];
	  assert(f.good());
	}
      mes=0;
      for (int i=0;i<nt;i++) 
	{ 
	  this->t(i).Read1(f,this->vertices,nv);
	  mes += t(i).mesure();
	}
      mesb=0.;
      for (int i=0;i<nbe;i++) 
	{ 
	  this->be(i).Read1(f,this->vertices,nv);
	  mesb += be(i).mesure();
	}
    }
  BuildBound();
  BuildAdj();
  Buildbnormalv();  
  BuildjElementConteningVertex();  

  if(verbosity)  
  cout << "   - mesh mesure = " << mes << " border mesure: " << mesb << endl;  
}
  void setUp() {
    emptyUbs = new UpperBoundSet();

    simpleUbs = new UpperBoundSet();
    MOLP simpleMOLP;
    std::vector<double> xVect;
    BVect bv1(1, 2, xVect);
    BVect bv2(2, 1, xVect);
    BEdge be(bv1, bv2);
    simpleMOLP.push_back(be);
    simpleUbs->merge(simpleMOLP);

    bigUbs = new UpperBoundSet();
    MOLP m1;
    BVect bv1m1(2, 17, xVect);
    BVect bv2m1(3, 15, xVect);
    BVect bv3m1(5, 14, xVect);
    BEdge be1m1(bv1m1, bv2m1);
    BEdge be2m1(bv2m1, bv3m1);
    m1.push_back(be1m1);
    m1.push_back(be2m1);
    MOLP m2;
    BVect bv1m2(8, 11, xVect);
    BVect bv2m2(9, 9, xVect);
    BVect bv3m2(11, 8, xVect);
    BEdge be1m2(bv1m2, bv2m2);
    BEdge be2m2(bv2m2, bv3m2);
    m2.push_back(be1m2);
    m2.push_back(be2m2);
    MOLP m3;
    BVect bv1m3(14, 5, xVect);
    BVect bv2m3(15, 3, xVect);
    BVect bv3m3(17, 2, xVect);
    BEdge be1m3(bv1m3, bv2m3);
    BEdge be2m3(bv2m3, bv3m3);
    m3.push_back(be1m3);
    m3.push_back(be2m3);
    bigUbs->merge(m1);
    bigUbs->merge(m2);
    bigUbs->merge(m3);
  }
Exemple #23
0
/*-----------------------------------------------------------------------------*/
bool Notation::MergeMove(const MoveKif& move)
{

	MoveBranchEnumerator be(this->current_moves_, this->move_current_);

	const MoveKif* next_move;

	while ((next_move = be.Next()) != nullptr)
	{
		if (move.Equals(*next_move))
		{
			// 同じ場合
			this->move_current_->setCurrentBranchNumber(be.current_no()); // カレントを変更して
			this->Next(1); // 1手すすめる

			return true;
		}
	}

	// 無かったら追加
	return this->AddMove(move);
}
void DMGPartition::adviseOptimalBlock(uint64_t offset, uint64_t& blockStart, uint64_t& blockEnd)
{
	std::map<uint64_t, uint32_t>::iterator itRun = m_sectors.upper_bound(offset / SECTOR_SIZE);

	if (itRun == m_sectors.begin())
		throw io_error("Invalid run sector data");

	if (itRun == m_sectors.end())
		blockEnd = length();
	else
		blockEnd = itRun->first * SECTOR_SIZE;

	itRun--;

	blockStart = itRun->first * SECTOR_SIZE;
	
	// Issue #22: empty areas may be larger than 2**31 (causing bugs in callers).
	// Moreover, there is no such thing as "optimal block" in zero-filled areas.
	RunType runType = RunType(be(m_table->runs[itRun->second].type));
	if (runType == RunType::ZeroFill || runType == RunType::Unknown || runType == RunType::Raw)
		Reader::adviseOptimalBlock(offset, blockStart, blockEnd);
}
Exemple #25
0
TEST(VoidElement, CopyElement)
{
    tawara::StringElement se(0x80, "12345");

    std::streamsize se_size(se.size());
    tawara::VoidElement ve1(se);
    EXPECT_EQ(se_size, ve1.size());
    EXPECT_FALSE(ve1.fill());

    tawara::VoidElement ve2(se, true);
    EXPECT_EQ(se_size, ve2.size());
    EXPECT_TRUE(ve2.fill());

    // Test elements with a size right on the border of two encoded sizes for
    // the body size
    for (int ii(0); ii < 10; ++ii)
    {
        tawara::BinaryElement be(0x81, std::vector<char>(0x3FFB + ii, 0xC0));
        tawara::VoidElement ve3(be);
        EXPECT_EQ(be.size(), ve3.size());
    }
}
  bool
  operator== (const Navigation& x, const Navigation& y)
  {
    {
      ::xsd::cxx::tree::comparison_map< char >& cm (
        ::xsd::cxx::tree::comparison_map_instance< 0, char > ());

      Navigation::EventSequence a (x.event ()), b (y.event ());

      if (a.size () != b.size ())
        return false;

      for (Navigation::EventConstIterator
           ai (a.begin ()), bi (b.begin ()), ae (a.end ()), be (b.end ());
           ai != ae; ++ai, ++bi)
      {
        if (!cm.compare (*ai, *bi))
          return false;
      }
    }

    return true;
  }
DMGPartition::DMGPartition(std::shared_ptr<Reader> disk, BLKXTable* table)
: m_disk(disk), m_table(table)
{
	for (uint32_t i = 0; i < be(m_table->blocksRunCount); i++)
	{
		RunType type = RunType(be(m_table->runs[i].type));
		if (type == RunType::Comment || type == RunType::Terminator)
			continue;
		
		m_sectors[be(m_table->runs[i].sectorStart)] = i;
		
#ifdef DEBUG
		std::cout << "Sector " << i << " has type 0x" << std::hex << uint32_t(type) << std::dec << ", starts at byte "
			<< be(m_table->runs[i].sectorStart)*512l << ", compressed length: "
			<< be(m_table->runs[i].compLength) << ", compressed offset: " << be(m_table->runs[i].compOffset) + be(m_table->dataStart) << std::endl;
#endif
	}
}
Exemple #28
0
void HFSVolume::processEmbeddedHFSPlus(HFSMasterDirectoryBlock* block)
{
	uint32_t blockSize = be(block->drAlBlkSiz);
	uint64_t offset, length;

	if (be(block->drEmbedSigWord) != HFSP_SIGNATURE && be(block->drEmbedSigWord) != HFSX_SIGNATURE)
		throw std::runtime_error("Original HFS is not supported");

	offset = blockSize * be(block->drEmbedExtent.startBlock) + 512 * be(block->drAlBlSt);
	length = blockSize * be(block->drEmbedExtent.blockCount);
	
	std::cout << "HFS+ partition is embedded at offset: " << offset << ", length: " << length << std::endl;
	
	m_embeddedReader.reset(new SubReader(m_reader, offset, length));
	m_reader = m_embeddedReader;
	
	m_reader->read(&m_header, sizeof(m_header), 1024);
}
int HFSAttributeBTree::cnidAttrComparator(const Key* indexKey, const Key* desiredKey)
{
	const HFSPlusAttributeKey* indexAttributeKey = reinterpret_cast<const HFSPlusAttributeKey*>(indexKey);
	const HFSPlusAttributeKey* desiredAttributeKey = reinterpret_cast<const HFSPlusAttributeKey*>(desiredKey);
	
	//std::cout << "Attr search: index cnid: " << be(indexAttributeKey->fileID) << " desired cnid: " << be(desiredAttributeKey->fileID) << std::endl;

	if (be(indexAttributeKey->fileID) > be(desiredAttributeKey->fileID))
		return 1;
	else if (be(indexAttributeKey->fileID) < be(desiredAttributeKey->fileID))
		return -1;
	else
	{
		UnicodeString desiredName, indexName;
		
		desiredName = UnicodeString((char*)desiredAttributeKey->attrName, be(desiredAttributeKey->attrNameLength)*2, "UTF-16BE");
		indexName = UnicodeString((char*)indexAttributeKey->attrName, be(indexAttributeKey->attrNameLength)*2, "UTF-16BE");
		
		return indexName.compare(desiredName);
	}
}
uint64_t DMGPartition::length()
{
	return be(m_table->sectorCount) * SECTOR_SIZE;
}