示例#1
0
文件: RangeImpl.cpp 项目: mydw/mydw
/**
 * Utility method for traversing a text node that we know
 * a-priori to be on a left or right boundary of the range.
 * This method does not properly handle text nodes that contain
 * both the start and end points of the range.
 *
 */
DOM_Node RangeImpl::traverseTextNode( DOM_Node n, bool isLeft, int how )
{
    DOMString txtValue = n.getNodeValue();
    DOMString newNodeValue;
    DOMString oldNodeValue;

    if ( isLeft )
    {
        int offset = getStartOffset();
        newNodeValue = txtValue.substringData( offset , fStartContainer.getNodeValue().length()-offset);
        oldNodeValue = txtValue.substringData( 0, offset );
    }
    else
    {
        int offset = getEndOffset();
        newNodeValue = txtValue.substringData( 0, offset );
        oldNodeValue = txtValue.substringData( offset , fEndContainer.getNodeValue().length()-offset );
    }

    if ( how != CLONE_CONTENTS )
        n.setNodeValue( oldNodeValue );
    if ( how==DELETE_CONTENTS )
        return null;
    DOM_Node newNode = n.cloneNode( false );
    newNode.setNodeValue( newNodeValue );
    return newNode;
}
void
GfxFeatureMapRequestPacket::printPacket() const
{
   cout << "GfxFeatureMapRequestPacket::printPacket() for map " 
        <<  getMapID() << endl;
   cout << "Bounding box for the GfxFeatureMapRequestPacket:" << endl;
   MC2BoundingBox bbox;
   getMC2BoundingBox(&bbox);
   bbox.dump();
   uint16 x, y;
   getScreenSize(x, y);
   cout << "Screen size (x = " << x << ", y = " 
        << y << ")" << endl;
   cout << "max scaleLevel = " << getMaxScaleLevel() << endl;
   cout << "min scaleLevel = " << getMinScaleLevel() << endl;
   cout << "filt scaleLevel = " << getFiltScaleLevel() << endl;
   cout << "language = " << (int)getLanguage() << endl;
   cout << "nbrNodeIDs " << getNbrNodeIDs() << endl;
   cout << "  isStartAndEnd byte 0x" << hex 
        << int( readByte(isStartAndEnd_POS)) << dec << endl;
   cout << "IgnoreStartOffset " << BP(getIgnoreStartOffset()) << endl;
   cout << "  isStartAndEnd byte 0x" << hex 
        << int(readByte(isStartAndEnd_POS)) << dec << endl;
   cout << "IgnoreEndOffset " << BP(getIgnoreEndOffset()) << endl;
   cout << "StartOffset " << getStartOffset() << endl;
   cout << "EndOffset " << getEndOffset() << endl;
   cout << "NbrReqPackets " << int(getNbrReqPackets()) << endl;
   cout << "DrawOverviewContents " << BP(getDrawOverviewContents()) 
        << endl;
}
示例#3
0
/*@brief Traverse the whole File of the relation specified by fileName
* and add lndex for each record
* @param indexName The name of the created Index
* @param attribute The attribute where Index is created on
* @param  recordLength The Length of the entire record
* @param fileName The data file of the Relation
* @pre Indexname exists
* @return void
* @throw IndexNotExistException
* @post A index is created and store in .index file
*/
void IndexManager::createIndex(const string &indexName, Data &attribute, const int &recordLength, const string &fileName)
{/*storing index wait to be completed*/
	/*Calculate the fan-out of BPlusTree so that each leaf node's size is a block*/
	int bPlusFanOut;
	switch (attribute.getType())
	{
	case CHAR:bPlusFanOut = (BLOCKSIZE - 4) / (attribute.getLength() + sizeof(ADDRESS)); break;
	case INT:bPlusFanOut = (BLOCKSIZE - 4) / (1 + INT_STRING_SIZE + sizeof(ADDRESS)); break;
	case FLOAT:bPlusFanOut = (BLOCKSIZE - 4) / (1 + FLOAT_INTEGER_SIZE + FLOAT_DECIMAL_SIZE + 1 + sizeof(ADDRESS)); break;
	default:
		exception ex;
		throw ex;
		break;
	}

	/*Create an index B+ Tree and insert it to index library*/
	BPlusTreeIndex *newIndex = new BPlusTreeIndex(bPlusFanOut, attribute.getLength(), attribute.getOffset(), attribute.getType());
	indexLibrary[indexName] = newIndex;
	ADDRESS endOffset = getEndOffset(fileName);

	/*Get record from bufferManager and create index*/
	for (ADDRESS recordOffset = HEADER_BLOCK_OFFSET; recordOffset < endOffset; recordOffset += recordLength)
	{
		BYTE* recordData;
		if ((recordOffset / 4096 + 1) * 4096 - recordOffset < recordLength&&recordOffset % 4096 != 0)
			recordOffset = (recordOffset / 4096 + 1) * 4096;/*eliminate the tail of a block*/
		recordData = bufferManager->fetchARecord(fileName, recordOffset + attribute.getOffset());/*point to the start of the attribute*/
		string recordString = "";
		char* tmpRecordString = new char[attribute.getLength() + 1];
		int tmpRecordInt = 0;
		float tmpRecordFloat = 0;
		stringstream ss;
		switch (attribute.getType())
		{
		case CHAR:
			memcpy(tmpRecordString, recordData, attribute.getLength());
			tmpRecordString[attribute.getLength()] = 0;
			recordString = tmpRecordString;
			newIndex->addKey(recordOffset, recordString);
			break;
		case INT:
			memcpy(&tmpRecordInt, recordData, sizeof(int));
			ss << tmpRecordInt;
			ss >> recordString;
			newIndex->addKey(recordOffset, toAlignedInt(recordString));
			break;
		case FLOAT:
			memcpy(&tmpRecordFloat, recordData, sizeof(float));
			ss << tmpRecordFloat;
			ss >> recordString;
			newIndex->addKey(recordOffset, toAlignedFloat(recordString));
			break;
		default:
			break;
		}
	}
	saveIndexToFile(indexName, attribute.getType());
}