Ejemplo n.º 1
0
void live_widgets::PianoKey::mIn(const live::Event *data, live::ObjectChain*p) {
    p->push_back(this);
    if (m_enabled) {
        mOut(data,p);
    }
    p->pop_back();
}
Ejemplo n.º 2
0
// Test vectors from RFC 6070.  (See file header, above.)
bool PBKDF2_TEST()
{  
   MemBuf mDig(100);
   MemBuf mOut(100);   
   
   CvtHex( "0c60c80f961f0e71f3a9b524af6012062fe037a6", mDig );
   if (0 != memcmp( mDig, PBKDF2("password", "salt", 1, 20, mOut), 20 )) { return false; }

   CvtHex( "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957", mDig );
   if (0 != memcmp( mDig, PBKDF2("password", "salt", 2, 20, mOut), 20 )) { return false; }

   CvtHex( "4b007901b765489abead49d926f721d065a429c1", mDig );
   if (0 != memcmp( mDig, PBKDF2("password", "salt", 4096, 20, mOut), 20)) { return false; }

   // This one is rather time consuming.
   //CvtHex( "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984", mDig );
   //if (0 != memcmp( mDig, PBKDF2("password", "salt", 16777216, 20, mOut), 20)) { return false; }

   CvtHex( "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038", mDig );
   if (0 != memcmp( mDig, PBKDF2("passwordPASSWORDpassword", "saltSALTsaltSALTsaltSALTsaltSALTsalt", 4096, 25, mOut), 25)) { return false; }

   CvtHex( "56fa6aa75548099dcc37d7f03425e0c3", mDig );
   BYTE text[] = { 'p', 'a', 's', 's', 0, 'w', 'o', 'r', 'd' } ;
   BYTE salt[] = { 's', 'a', 0, 'l', 't' } ;   
   if (0 != memcmp( mDig, PBKDF2( MemBuf(text,NELEM(text)), MemBuf(salt,NELEM(salt)), 4096, 16, mOut), 16)) { return false; }

   return true;
}
Ejemplo n.º 3
0
	DiMat4 DiFocusedShadowPolicy::transformToUnitCube(const DiMat4& m, 
		const PointListBody& body) const
	{
		// map the transformed body AAB points to the unit cube (-1/-1/-1) / (+1/+1/+1) corners
		DiAABB aab_trans;

		for (size_t i = 0; i < body.getPointCount(); ++i)
		{
			aab_trans.Merge(m * body.getPoint(i));
		}

		DiVec3 vMin, vMax;

		vMin = aab_trans.GetMinimum();
		vMax = aab_trans.GetMaximum();

		const DiVec3 trans(-(vMax.x + vMin.x) / (vMax.x - vMin.x),
			-(vMax.y + vMin.y) / (vMax.y - vMin.y),
			-(vMax.z + vMin.z) / (vMax.z - vMin.z));

		const DiVec3 scale(2 / (vMax.x - vMin.x),
			2 / (vMax.y - vMin.y),
			2 / (vMax.z - vMin.z));

		DiMat4 mOut(DiMat4::IDENTITY);
		mOut.setTrans(trans);
		mOut.setScale(scale);

		return mOut;
	}
Ejemplo n.º 4
0
	//-----------------------------------------------------------------------
	Matrix4 FocusedShadowCameraSetup::transformToUnitCube(const Matrix4& m, 
		const PointListBody& body) const
	{
		// map the transformed body AAB points to the unit cube (-1/-1/-1) / (+1/+1/+1) corners
		AxisAlignedBox aab_trans;

		for (size_t i = 0; i < body.getPointCount(); ++i)
		{
			aab_trans.merge(m * body.getPoint(i));
		}

		Vector3 vMin, vMax;

		vMin = aab_trans.getMinimum();
		vMax = aab_trans.getMaximum();

		const Vector3 trans(-(vMax.x + vMin.x) / (vMax.x - vMin.x),
			-(vMax.y + vMin.y) / (vMax.y - vMin.y),
			-(vMax.z + vMin.z) / (vMax.z - vMin.z));

		const Vector3 scale(2 / (vMax.x - vMin.x),
			2 / (vMax.y - vMin.y),
			2 / (vMax.z - vMin.z));

		Matrix4 mOut(Matrix4::IDENTITY);
		mOut.setTrans(trans);
		mOut.setScale(scale);

		return mOut;
	}
Ejemplo n.º 5
0
TEST( MultidimTest, coreArrayByArray)
{
    MultidimArray<double> m1(2,2);
    MultidimArray<double> m2(2,2);
    MultidimArray<double> mOut(2,2);
    MultidimArray<double> mref(2,2);

    A2D_ELEM(m1,0,0) = 1.;
    A2D_ELEM(m1,1,0) = 2.;
    A2D_ELEM(m1,0,1) = 3.;
    A2D_ELEM(m1,1,1) = 4.;

    A2D_ELEM(m2,0,0) = 11.;
    A2D_ELEM(m2,1,0) = 22.;
    A2D_ELEM(m2,0,1) = 33.;
    A2D_ELEM(m2,1,1) = 44.;

    coreArrayByArray(m1, m2, mOut, '+');

    A2D_ELEM(mref,0,0) = 12.;
    A2D_ELEM(mref,1,0) = 24.;
    A2D_ELEM(mref,0,1) = 36.;
    A2D_ELEM(mref,1,1) = 48.;

    EXPECT_EQ(mOut,mref);
}
Ejemplo n.º 6
0
void VstEffectApp::mIn(const Event *data, ObjectChain*p)
{
    p->push_back(this);
    if(s_internal)
    {
       m_internal->mIn(data,p);
    }
    mOut(data,p);
    p->pop_back();
}
Ejemplo n.º 7
0
void ChordApp::mIn(const Event *data, ObjectChain*p)
{
    QList<Event> _x = value(*data);
    if(!_x.size())
    {
        p->push_back(this);
        mOut(data,p);
        p->pop_back();
    }
    else
    {
        for(int i=0; i<_x.size(); i++)
        {
            p->push_back(this);
            mOut(&_x[i],p);
            p->pop_back();
        }
    }
}
Ejemplo n.º 8
0
void live_widgets::PianoKey::mouseReleaseEvent( QGraphicsSceneMouseEvent* ) {
    if ( m_virtual ) {
        live::Event* ev = new live::Event;
        ev->setChan(0);
        ev->setNote(m_id);
        ev->setVelocity(0); //off

        live::ObjectChain p;
        p.push_back(this);
        mOut(ev, &p);
        return;
    }
}
Ejemplo n.º 9
0
bool WPAPSK_TEST() {

   MemBuf mDig(32);
   MemBuf mOut(32);   
   
   CvtHex( "f42c6fc52df0ebef9ebb4b90b38a5f902e83fe1b135a70e23aed762e9710a12e", mDig );
   if (0 != memcmp( mDig, WPAPSK("password", "IEEE",  mOut), 32 )) { 
      return false; 
   }   
   
   CvtHex( "0dc0d6eb90555ed6419756b9a15ec3e3209b63df707dd508d14581f8982721af", mDig );
   if (0 != memcmp( mDig, WPAPSK("ThisIsAPassword", "ThisIsASSID",  mOut), 32 )) { return false; }      
   
   CvtHex( "becb93866bb8c3832cb777c2f559807c8c59afcb6eae734885001300a981cc62", mDig );   
   if (0 != memcmp( mDig, WPAPSK("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",  mOut), 32 )) { return false; }      

   return true;   
}
Ejemplo n.º 10
0
	size_t Sites::readSites(DigestStream& inStream) {
		// prepare to read from the stream
		size_t bytesReadOffset = inStream.getBytesRead();
		char scratch[1 << 10];			// scratch read buffer
		uint16_t nameLength = 0;		// length of tile type name
		SiteCount siteCount;			// number of sites
		SiteTypeIndex siteTypeIndex;	// site type index
		TileIndex tileIndex;			// site tile index
		SiteFlags flags;				// site flags
		uint16_t pinMap = 0;			// site pin map

		// read the section header
		string sectionName;
		inStream.readSectionHeader(sectionName);
		/// \todo Throw a proper exception.
		if(sectionName != ">>>>  Sites >>>>") throw -1;

		// initialize the site array
		inStream.read(siteCount);
		mSites.setSize(siteCount);
		mOut() << "\tReading " << siteCount << " sites..." << std::endl;
		// loop through each site
		for(SiteIndex i; i < siteCount; i++) {
			// read the site name
			inStream.read(nameLength);
			/// \todo Throw a proper exception.
			if(nameLength > sizeof(scratch)) throw -1;
			inStream.read(scratch, nameLength);
			scratch[nameLength] = 0;
			// read the site type index, tile index, flags, and pin map
			inStream.read(siteTypeIndex);
			inStream.read(tileIndex);
			inStream.read(flags);
			inStream.read(pinMap);
			// look up a reference for the site, and discard the const trait
			Site& site = const_cast<Site&>(mSites[i]);
			site = Site(scratch, mSiteTypes[siteTypeIndex], tileIndex, flags, 
				mPrimitivePinMaps[pinMap]);
			mSiteNameToSiteIndex[scratch] = i;
		}

		// return the number of bytes read
		return inStream.getBytesRead() - bytesReadOffset;
	}
Ejemplo n.º 11
0
void live_widgets::PianoKey::mousePressEvent ( QGraphicsSceneMouseEvent * event ) {
    QGraphicsItem::mousePressEvent(event);

    if ( m_virtual ) {
        live::Event* ev = new live::Event;
        ev->setChan(0);
        ev->setNote(m_id);
        ev->setVelocity(127);

        live::ObjectChain p;
        p.push_back(this);
        mOut(ev,&p);
        return;
    }

    if ( this->isSelected() && ( event->button() == Qt::LeftButton) ) {
        this->setSelected( 0 );

        emit updated();

        if ( ( event->modifiers() == Qt::ShiftModifier ) && (m_shiftTwinID!=-1) ) {
            int minId=m_shiftTwinID<m_id?m_shiftTwinID:m_id, maxId=m_shiftTwinID<m_id?m_id:m_shiftTwinID;
            for (int i=minId; i<=maxId; i++) {
                m_universe[i]->enableKey(1);
            }
        } else enableKey(1);

    } else if (event->button() == Qt::RightButton ) {
        if ( ( event->modifiers() == Qt::ShiftModifier ) && m_shiftTwinID!=-1) {
            int minId=m_shiftTwinID<m_id?m_shiftTwinID:m_id, maxId=m_shiftTwinID<m_id?m_id:m_shiftTwinID;
            for (int i=minId; i<=maxId; i++) {
                m_universe[i]->enableKey(0);
            }
        } else enableKey(0);
        this->setSelected( 0 );
    }

    m_shiftTwinID = m_id;
}
Ejemplo n.º 12
0
	size_t Sites::readPrimitivePinMaps(DigestStream& inStream) {
		// prepare to read from the stream
		size_t bytesReadOffset = inStream.getBytesRead();
		uint16_t primitivePinMapCount = 0;	// number of pin maps
		PinCount pinCount;				// number of pins
		WireIndex wireIndex;			// pin index

		// read the section header
		string sectionName;
		inStream.readSectionHeader(sectionName);
		/// \todo Throw a proper exception.
		if(sectionName != ">>>>Pin Maps>>>>") throw -1;

		// initialize the site pin map array
		inStream.read(primitivePinMapCount);
		mPrimitivePinMaps.setSize(primitivePinMapCount);
		mOut() << "\tReading " << primitivePinMapCount << " primitive pin maps..." << std::endl;
		// loop through each pin map
		for(uint16_t i = 0; i < primitivePinMapCount; i++) {
			// read the pin count
			inStream.read(pinCount);
			mPrimitivePinMaps[i].setSize(pinCount);
			// get a reference to this map's pin array
			Array<const WireIndex>& pins = mPrimitivePinMaps[i];
			// loop through each pin
			for(PinCount j; j < pinCount; j++) {
				// look up a reference to the pin and discard the const trait
				WireIndex& pin = const_cast<WireIndex&>(pins[j]);
				// read the pin
				inStream.read(wireIndex);
				pin = wireIndex;
			}
		}

		// return the number of bytes read
		return inStream.getBytesRead() - bytesReadOffset;
	}
Ejemplo n.º 13
0
TEST( MultidimTest, selfCoreArrayByArrayMask)
{
    MultidimArray<double> m1(2,2);
    MultidimArray<double> m2(2,2);
    MultidimArray<double> mOut(2,2);
    MultidimArray<double> mref(2,2);
    MultidimArray<double> mask(2,2);

    A2D_ELEM(m1,0,0) = 1.;
    A2D_ELEM(m1,1,0) = 2.;
    A2D_ELEM(m1,0,1) = 3.;
    A2D_ELEM(m1,1,1) = 4.;

    A2D_ELEM(m2,0,0) = 11.;
    A2D_ELEM(m2,1,0) = 22.;
    A2D_ELEM(m2,0,1) = 33.;
    A2D_ELEM(m2,1,1) = 44.;

    A2D_ELEM(mask,0,0) = 0.;
    A2D_ELEM(mask,1,0) = 1.;
    A2D_ELEM(mask,0,1) = 1.;
    A2D_ELEM(mask,1,1) = 1.;

    A2D_ELEM(mOut,0,0) = 0.;
    A2D_ELEM(mOut,1,0) = 0.;
    A2D_ELEM(mOut,0,1) = 0.;
    A2D_ELEM(mOut,1,1) = 1.;

    selfCoreArrayByArrayMask(m1, m2, mOut, '+', &mask);

    A2D_ELEM(mref,0,0) = 1.;
    A2D_ELEM(mref,1,0) = 22.;
    A2D_ELEM(mref,0,1) = 33.;
    A2D_ELEM(mref,1,1) = 45.;

    EXPECT_EQ(mOut,mref);
}
Ejemplo n.º 14
0
		/// \brief Returns the database console output stream.
		ostream& getConsoleOut(void) { return mOut(); }
Ejemplo n.º 15
0
	size_t Sites::readPrimitiveTypes(DigestStream& inStream) {
		// prepare to read from the stream
		size_t bytesReadOffset = inStream.getBytesRead();
		char scratch[1 << 10];			// scratch read buffer
		uint16_t nameLength = 0;		// length of site type name
		SiteTypeCount siteTypeCount;	// number of site types
		uint32_t elementCount;			// number of site elements
		PinCount pinCount;				// number of pins
		PinFlags pinFlags;				// pin attribute flags
		uint32_t elementIndex;			// connection element index
		uint32_t pinIndex;				// connection pin index

		// read the section header
		string sectionName;
		inStream.readSectionHeader(sectionName);
		/// \todo Throw a proper exception.
		if(sectionName != ">>>>PrimDefs>>>>") throw -1;

		// initialize the tile type array
		inStream.read(siteTypeCount);
		mSiteTypes.setSize(siteTypeCount);
		mOut() << "\tReading " << siteTypeCount << " site types..." << std::endl;
		// loop through each site type
		for(SiteTypeIndex i; i < siteTypeCount; i++) {
			// look up the current site definition
			PrimitiveDef& primitiveDef = const_cast<PrimitiveDef&>(mSiteTypes[i]);
			// read the site type name
			inStream.read(nameLength);
			/// \todo Throw a proper exception.
			if(nameLength > sizeof(scratch)) throw -1;
			inStream.read(scratch, nameLength);
			scratch[nameLength] = 0;
//mOut() << "\t\t" << i << ": " << scratch << std::endl;
//mOut().flush();
			// read the pin count
			inStream.read(pinCount);
			// update the site definition
			primitiveDef.mName = scratch;
			primitiveDef.mPins.setSize(pinCount);
			// loop through each pin
			for(PinCount j; j < pinCount; j++) {
				// look up the current pin
				PrimitivePin& primitivePin = const_cast<PrimitivePin&>(primitiveDef.mPins[j]);
				// read the pin flags
				inStream.read(pinFlags);
				// read the pin name
				inStream.read(nameLength);
				/// \todo Throw a proper exception.
				if(nameLength > sizeof(scratch)) throw -1;
				inStream.read(scratch, nameLength);
				scratch[nameLength] = 0;
				// update the site pin
				primitivePin.mFlags = pinFlags;
				primitivePin.mName = scratch;
				primitiveDef.mPinNameToPinIndex[scratch] = xilinx::PinIndex(j);
			}
			// read the number of site elements
			inStream.read(elementCount);
			// update the site definition
			primitiveDef.mElements.setSize(elementCount);
			// loop through each element
			for(uint32_t j = 0; j < elementCount; j++) {
				// look up the current element
				PrimitiveElement& element 
					= const_cast<PrimitiveElement&>(primitiveDef.mElements[j]);
				// read the element name
				inStream.read(nameLength);
				/// \todo Throw a proper exception.
				if(nameLength > sizeof(scratch)) throw -1;
				inStream.read(scratch, nameLength);
				scratch[nameLength] = 0;
				// update the element name
				element.mName = scratch;
//mOut() << primitiveDef.getName() << " - " << element.getName() << ":" << std::endl;
//mOut() << "    ";
				// read the BEL flag
				uint16_t isBel;
				inStream.read(isBel);
				// read the pin count
				inStream.read(pinCount);
				// update the element
				element.mIsBel = isBel != 0;
				element.mPins.setSize(pinCount);
				// loop through each pin
				for(PinCount k; k < pinCount; k++) {
					// look up the current pin
					PrimitiveElementPin& elementPin = 
						const_cast<PrimitiveElementPin&>(element.mPins[k]);
					// read the pin flags
					inStream.read(pinFlags);
					// read the pin name
					inStream.read(nameLength);
					/// \todo Throw a proper exception.
					if(nameLength > sizeof(scratch)) throw -1;
					inStream.read(scratch, nameLength);
					scratch[nameLength] = 0;
					// update the site pin
					elementPin.mElementPtr = &element;
//mOut() << elementPin.mElementPtr->getName() << "." << scratch << " ";
//if(elementPin.mElementPtr == 0) {
//	mOut() << "Element pin " << scratch << " has NULL element" << std::endl;
//	mOut().flush();
//}
					elementPin.mFlags = pinFlags;
					elementPin.mName = scratch;
					element.mPinNameToPinIndex[scratch] = xilinx::PinIndex(k);
				}
//mOut() << std::endl;
				// read the config count
				uint32_t cfgCount;
				inStream.read(cfgCount);
				// loop through each cfg value
//bool debug = cfgCount > 0;
//if(debug) mOut() << "\t\t\t" << j << " \"" << scratch << "\": ";
				for(uint32_t k = 0; k < cfgCount; k++) {
					// read the cfg value
					inStream.read(nameLength);
					/// \todo Throw a proper exception.
					if(nameLength > sizeof(scratch)) throw -1;
					inStream.read(scratch, nameLength);
					scratch[nameLength] = 0;
//if(debug) mOut() << scratch << " ";
					// update the cfg values
					element.mCfgs.insert(scratch);
				}
//if(debug) mOut() << std::endl;
			}
			// read the conn count
			uint32_t connCount;
			inStream.read(connCount);
//mOut() << primitiveDef.mName << ": " << connCount << std::endl;
			// update the site definition
			primitiveDef.mConnections.setSize(connCount);
			// loop through each conn
			const PrimitiveElementArray& elements = primitiveDef.getElements();
			for(uint32_t j = 0; j < connCount; j++) {
				// look up the current connection
				PrimitiveConnSharedPtr& connectionPtr = primitiveDef.mConnections[j];
				connectionPtr = boost::shared_ptr<PrimitiveConn>(new PrimitiveConn());
				PrimitiveConn& connection = const_cast<PrimitiveConn&>(*connectionPtr);
				// read the source count
				uint16_t sourceCount;
				inStream.read(sourceCount);
				/// \todo Throw a proper exception
				if(sourceCount != 1) throw -1;
				// read the source element and pin
				inStream.read(elementIndex);
				inStream.read(pinIndex);
				const PrimitiveElement* elementPtr = elements.begin() + elementIndex;
				PrimitiveElement& element = const_cast<PrimitiveElement&>(*elementPtr);
				const PrimitiveElementPinArray& pins = element.getPins();
				PrimitiveElementPin& pin = const_cast<PrimitiveElementPin&>(pins[pinIndex]);
				connection.mSourcePtr = &pin;
				const_cast<PrimitiveConnSharedPtr&>(pin.mPrimitiveConn) = connectionPtr;
				// read the sink count
				uint16_t sinkCount;
				inStream.read(sinkCount);
				// loop through each sink
				for(uint32_t k = 0; k < sinkCount; k++) {
					// read the sink element and pin
					inStream.read(elementIndex);
					inStream.read(pinIndex);
					elementPtr = elements.begin() + elementIndex;
					PrimitiveElement& element = const_cast<PrimitiveElement&>(*elementPtr);
					const PrimitiveElementPinArray& pins = element.getPins();
					PrimitiveElementPin& pin = const_cast<PrimitiveElementPin&>(pins[pinIndex]);
					connection.mSinks.push_back(&pin);
					const_cast<PrimitiveConnSharedPtr&>(pin.mPrimitiveConn) = connectionPtr;
				}
			}
//mOut() << primitiveDef.getName() << " - " << element.getName() << ":" << std::endl;
		}

		// return the number of bytes read
		return inStream.getBytesRead() - bytesReadOffset;
	}
Ejemplo n.º 16
0
	size_t Sites::readPackages(DigestStream& inStream) {
		// prepare to read from the stream
		size_t bytesReadOffset = inStream.getBytesRead();
		char scratch[1 << 10];			// scratch read buffer
		uint16_t nameLength = 0;		// length of tile type name
		PackageCount packageCount;		// number of packages
		PadCount padCount;				// number of pads
		SiteFlags siteFlags;			// site attribute flags
		SiteIndex siteIndex;			// pad site index

		// read the section header
		string sectionName;
		inStream.readSectionHeader(sectionName);
		/// \todo Throw a proper exception.
		if(sectionName != ">>>>Packages>>>>") throw -1;

		// initialize the package array
		inStream.read(packageCount);
		mPackages.setSize(packageCount);
		mOut() << "\tReading " << packageCount << " package" << (packageCount != 1 ? "s" : "") 
			<< " (";
		// loop through each package
		for(PackageIndex i; i < packageCount; i++) {
			// look up the current package
			Package& package = const_cast<Package&>(mPackages[i]);
			// read the package name
			inStream.read(nameLength);
			/// \todo Throw a proper exception.
			if(nameLength > sizeof(scratch)) throw -1;
			inStream.read(scratch, nameLength);
			scratch[nameLength] = 0;
			// update the package
			package.mName = scratch;
			mPackageNameToPackageIndex[scratch] = i;
			mOut() << scratch << (i + 1 < packageCount ? ", " : "");
			// read the pad count
			inStream.read(padCount);
			package.mPads.setSize(padCount);
			// loop through each pad
			for(PadCount j; j < padCount; j++) {
				// look up the current pad
				Pad& pad = const_cast<Pad&>(package.mPads[j]);
				// read the site index
				inStream.read(siteIndex);
				// read the site flags
				inStream.read(siteFlags);
				// read the pad name
				inStream.read(nameLength);
				/// \todo Throw a proper exception.
				if(nameLength > sizeof(scratch)) throw -1;
				inStream.read(scratch, nameLength);
				scratch[nameLength] = 0;
				// update the package pad
				pad.mSiteIndex = siteIndex;
				pad.mFlags = siteFlags;
				pad.mName = scratch;
				package.mPadNameToPadIndex[scratch] = xilinx::PadIndex(j);
			}
		}
		mOut() << ") ..." << std::endl;
 
		// return the number of bytes read
		return inStream.getBytesRead() - bytesReadOffset;
	}
Ejemplo n.º 17
0
int BFVirtualMachine::BFVirtualMachineRun(const char *code, int size)
{
    if ((code==NULL) || (size==0) || (mOut==NULL) || (mIn==NULL) || (mSize==0))
    {
        return -1;
    }

    pCur = mReg;
    VMMemset(mReg, 0, mSize);

    int pos = 0;
    int count = 0;

    while (pos < size)
    {
        switch (code[pos++])
        {
            case '>':
                pCur++;
                if (pCur >= (mReg+mSize))
                {
                    char *newBuf = (char *)VMMalloc(mSize+DEFAULT_REG_SIZE);
                    if (newBuf == NULL)
                        return -2;
                    VMMemset(newBuf, 0, mSize+DEFAULT_REG_SIZE);
                    VMMemcpy(newBuf, mReg, mSize);
                    VMFree(mReg);
                    mReg = newBuf;
                    pCur = mReg+mSize;
                    mSize += DEFAULT_REG_SIZE;
                }
                break;

            case '<':
                if (pCur <= mReg)
                    return -3;
                pCur--;
                break;

            case '+':
                (*pCur)++;
                break;

            case '-':
                (*pCur)--;
                break;

            case '.':
                mOut(*pCur);
                break;

            case ',':
                *pCur = mIn();
                break;

            case '[':
                if (*pCur == 0)
                {
                    count = 0;
                    while (pos < size)
                    {
                        const char ch = code[pos++];
                        if (ch == ']')
                        {
                            if (count == 0)
                                break;
                            else
                                count--;
                        }
                        else if (ch == '[')
                            count++;
                    }
                }
                break;

            case ']':
                if (*pCur != 0)
                {
                    count = 0;
                    pos--;
                    while (pos > 0)
                    {
                        const char ch = code[--pos];
                        if (ch == '[')
                        {
                            if (count == 0)
                                break;
                            else
                                count--;
                        }
                        else if (ch == ']')
                            count++;
                    }
                }
                break;

            default:
                break;
        }
    }

    return 0;
}
Ejemplo n.º 18
0
void main()
{
  //mOut("Testing XmlWriter");
  //mOut("=================");

  //mOut("creating XML writer object:"); 
  XmlWriter wtr;

  //mOut("adding XML declaration:");
  wtr.addDeclaration();
  //mOut(wtr.xml());

  //mOut("adding comment:");
  wtr.addComment("top level comment");
  //mOut(wtr.xml());

  //mOut("adding root element:");
  wtr.start("root");
  //mOut(wtr.xml());

  //mOut("adding attributes:");
  wtr.addAttribute("att1","val1");
  wtr.addAttribute("att2","val2");
  //mOut(wtr.xml());

  //mOut("adding comment:");
  wtr.addComment("comment in root's body");
  //mOut(wtr.xml());

  //mOut("Creating self-closing element:");
  XmlWriter sub1;
  sub1.start("child1 /");
 // mOut(sub1.xml());

  //mOut("adding attribute:");
  sub1.addAttribute("c1name","c1value");
  
  XmlWriter subsub1;
  subsub1.start("grand");
  subsub1.addBody("test grandchild");
  subsub1.end();
  sub1.addBody(subsub1.xml());


  //mOut(sub1.xml());
  
  //mOut("adding child to root's body:");
  wtr.addBody(sub1.xml());
  //mOut(wtr.xml());

  //mOut("adding another comment");
  wtr.addComment("another root's body comment");
  //mOut(wtr.xml());

  //mOut("adding string to root's body:"); 
  wtr.addBody("root's body");
  //mOut(wtr.xml());

  //mOut("closing root element:\n");
  wtr.end();
  mOut(wtr.xml());

  mOut("\n  writing XML to file \"Test.xml\":");
  std::ofstream out("test.xml");
  if(out.good())
  {
    out << wtr.xml().c_str();
    out.close();
  }
  std::cout << std::endl;

 /* mOut("creating composite element:");
  XmlWriter cwtr, bcwtr1, bcwtr2;
  std::string temp = 
    bcwtr1.element("child1","child1's body")
    .element("child2","child2's body").xml();
  std::cout << "\n  " << bcwtr1.xml();
  bcwtr1.clear();

  std::cout << "\n  " <<
    cwtr.start("parent")
    .addBody(bcwtr1.element("child1","child1's body").xml())
    .addBody(bcwtr2.element("child2","body2").xml())
    .end().xml();
  std::cout << "\n\n";*/
}