/**
	CSizeAccumulator::SizeLeft
	calculate the size of the attribute list.

	Foundation of the continuation handling. 
	It is used together	with StartAt.
	It walks through the list of records, each should contain
	a list of attributes. There are internal start offsets for
	both the record and attribute lists. These are set with StartAt.

	The method returns the size (in bytes) of the attributes, together with
	3 bytes for each attribute ID (1 byte header, 2 byte UInt) and the correct
	number of bytes for each DES header for the attributes of each record.

	It does NOT calculate the DES header for a list of records. So an extra
	DES must be created for Searvice Search Attribute.

	This allows the total length to be written before the rest of the response
	packet. It also allows the request handler to decide if it can fit the whole
	response in to the response packet with or without continuation.
	Return format is
 @verbatim
		Size left					TUint
 @endverbatim
**/
EXPORT_C TUint CSizeAccumulator::SizeLeft()
	{
	TUint totalSize=0;
	TInt handleCount = HandleCount();	// for testing
	for (TInt i = iFirstRec; i < handleCount; i++)
		{
		TUint recordSize = 0;
		TInt attrCount = AttrCount(i); // for testing
		for (TInt j = iFirstAtt; j < attrCount; j++)
			{
			CAttrSizeItem* attr = AttributeOf(i,j);
			recordSize += attr->Size();
			recordSize +=3;		// the size of a attribute ID in the list
			}
		if (iFirstAtt == 0)
			{ // are we sizing the whole record ?
			TUint recRecSize = iHandleList->At(i)->CHandleItem::iRecordSize; // for testing
			if (recordSize != recRecSize) DbPanic(ESdpDbBadSearchPattern);
			}
		if (recordSize)
			{ // only add the header if there is any data
			TUint desSize;
			desSize = (recordSize > 0xff) ? 3 : 2;
			desSize = (recordSize > 0xffff) ? 5 : desSize;
			totalSize += recordSize + desSize;	// size of the DES header for this record
			}
		}
	return totalSize;

	}
示例#2
0
/* Clone an object. The new object is owned by the cloning player */
static dbref
clone_object(dbref player, dbref thing, const char *newname, int preserve)
{
  dbref clone;

  clone = new_object();

  Owner(clone) = Owner(player);
  Name(clone) = NULL;
  if (newname && *newname)
    set_name(clone, newname);
  else
    set_name(clone, Name(thing));
  s_Pennies(clone, Pennies(thing));
  AttrCount(clone) = 0;
  List(clone) = NULL;
  Locks(clone) = NULL;
  clone_locks(player, thing, clone);
  Zone(clone) = Zone(thing);
  Parent(clone) = Parent(thing);
  Flags(clone) = clone_flag_bitmask("FLAG", Flags(thing));
  if (!preserve) {
    clear_flag_internal(clone, "WIZARD");
    clear_flag_internal(clone, "ROYALTY");
    Warnings(clone) = 0;        /* zap warnings */
    Powers(clone) = new_flag_bitmask("POWER");  /* zap powers */
  } else {
    Powers(clone) = clone_flag_bitmask("POWER", Powers(thing));
    Warnings(clone) = Warnings(thing);
    if (Wizard(clone) || Royalty(clone) || Warnings(clone) ||
        !null_flagmask("POWER", Powers(clone)))
      notify(player,
             T
             ("Warning: @CLONE/PRESERVE on an object with WIZ, ROY, @powers, or @warnings."));
  }
  /* We give the clone the same modification time that its
   * other clone has, but update the creation time */
  ModTime(clone) = ModTime(thing);
  CreTime(clone) = mudtime;
  Type(clone) = Type(thing);

  Contents(clone) = Location(clone) = Next(clone) = NOTHING;
  if (IsRoom(thing))
    Exits(clone) = NOTHING;
  else
    Home(clone) = Home(thing);
  atr_cpy(clone, thing);

  queue_event(player, "OBJECT`CREATE", "%s,%s",
              unparse_objid(clone), unparse_objid(thing));
  return clone;

}
const nsAttrName*
nsAttrAndChildArray::AttrNameAt(PRUint32 aPos) const
{
  NS_ASSERTION(aPos < AttrCount(),
               "out-of-bounds access in nsAttrAndChildArray");

  PRUint32 mapped = MappedAttrCount();
  if (aPos < mapped) {
    return mImpl->mMappedAttrs->NameAt(aPos);
  }

  return &ATTRS(mImpl)[aPos - mapped].mName;
}
const nsAttrValue*
nsAttrAndChildArray::AttrAt(uint32_t aPos) const
{
  NS_ASSERTION(aPos < AttrCount(),
               "out-of-bounds access in nsAttrAndChildArray");

  uint32_t mapped = MappedAttrCount();
  if (aPos < mapped) {
    return mImpl->mMappedAttrs->AttrAt(aPos);
  }

  return &ATTRS(mImpl)[aPos - mapped].mValue;
}
// do a crc across all the attributes
EXPORT_C TUint16 CSizeAccumulator::CrcAttribs()
	{
	TUint16 totalCrc=0;
	for (TInt i = 0; i<HandleCount(); i++)
		{
		for (TInt j = 0; j<AttrCount(i); j++)
			{
			CAttrSizeItem* attr = AttributeOf(i,j);
			CSdpAttrValue& theVal = attr->Attr()->Value();
			Mem::Crc(totalCrc, reinterpret_cast<const TAny*>(theVal.Des()[0]), attr->Size());
			}
		}
	return totalCrc;

	}
示例#6
0
static void dump_flat_HTTag(FILE *output, unsigned n, HTTag * tag)
{
    fprintf(output, "\t%u:%s\n", n, tag->name);
#ifdef EXP_JUSTIFY_ELTS
    fprintf(output, "\t\t%s\n", tag->can_justify ? "justify" : "nojustify");
#endif
    dump_flat_attrs(output, tag->attributes, AttrCount(tag));
    dump_flat_attr_types(output, tag->attr_types);
    dump_flat_SGMLContent(output, "contents", tag->contents);
    dump_flat_TagClass(output, "tagclass", tag->tagclass);
    dump_flat_TagClass(output, "contains", tag->contains);
    dump_flat_TagClass(output, "icontains", tag->icontains);
    dump_flat_TagClass(output, "contained", tag->contained);
    dump_flat_TagClass(output, "icontained", tag->icontained);
    dump_flat_TagClass(output, "canclose", tag->canclose);
    dump_flat_TagFlags(output, "flags", tag->flags);
}
示例#7
0
static AttrInfo *sorted_attrs(const SGML_dtd * dtd, unsigned *countp)
{
    int j;

    AttrInfo *data = (AttrInfo *) calloc(dtd->number_of_tags, sizeof(AttrInfo));
    unsigned count = 0;

    /* get the attribute-data */
    for (j = 0; j < dtd->number_of_tags; ++j) {
	if (first_attrs(dtd, j)) {
	    data[count].name = NameOfAttrs(dtd, j);
	    data[count].attrs = dtd->tags[j].attributes;
	    data[count].count = AttrCount(&(dtd->tags[j]));
	    data[count].which = j;
	    ++count;
	}
    }
    /* sort the data by the name of their associated tag */
    qsort(data, count, sizeof(*data), compare_attr);
    *countp = count;
    return data;
}
nsresult
nsAttrAndChildArray::RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue)
{
  NS_ASSERTION(aPos < AttrCount(), "out-of-bounds");

  PRUint32 mapped = MappedAttrCount();
  if (aPos < mapped) {
    if (mapped == 1) {
      // We're removing the last mapped attribute.  Can't swap in this
      // case; have to copy.
      aValue.SetTo(*mImpl->mMappedAttrs->AttrAt(0));
      NS_RELEASE(mImpl->mMappedAttrs);

      return NS_OK;
    }

    nsRefPtr<nsMappedAttributes> mapped;
    nsresult rv = GetModifiableMapped(nsnull, nsnull, false,
                                      getter_AddRefs(mapped));
    NS_ENSURE_SUCCESS(rv, rv);

    mapped->RemoveAttrAt(aPos, aValue);

    return MakeMappedUnique(mapped);
  }

  aPos -= mapped;
  ATTRS(mImpl)[aPos].mValue.SwapValueWith(aValue);
  ATTRS(mImpl)[aPos].~InternalAttr();

  PRUint32 slotCount = AttrSlotCount();
  memmove(&ATTRS(mImpl)[aPos],
          &ATTRS(mImpl)[aPos + 1],
          (slotCount - aPos - 1) * sizeof(InternalAttr));
  memset(&ATTRS(mImpl)[slotCount - 1], nsnull, sizeof(InternalAttr));

  return NS_OK;
}
示例#9
0
void XMLElement :: DumpOn( std::ostream & os, bool recurse  ) const {
	os << "<" << Name();
	for ( unsigned int i = 0; i < AttrCount(); i++ ) {
		os << " " << AttrName(i) << "=\"";
		os << AttrValue( AttrName(i) ) << "\"";
	}
	if ( ! recurse ) {
		os << "/>\n";
	}
	else {
		os << ">\n";
		for ( unsigned int i = 0; i < ChildCount(); i++ ) {
			const XMLElement * ce = ChildElement( i ) ;
			if ( ce ) {
				ce->DumpOn( os, recurse );
			}
			const XMLText * ct = ChildText( i );
			if ( ct ) {
				os << LTrim( ct->Text() ) << "\n";
			}
		}
		os << "</" << Name() << ">\n";
	}
}
/**
	CSizeAccumulator::StartAt
	Supplied with the data sent so far.
	This walks through the list of service search record handles
	and the the list of attributes associated with each record.

	Once it has found the location where the size is less than or
	equal to the parameter supplied, it sets CSizeAccumulators
	internal record and attribute offsets to the point it has
	reached. It will not update the offsets if the data is greater
	than the input offset.
	
	The method returns the two offsets and the data already sent
	from the current attribute.

	The method counts the DES header at the start of any record. It
	does NOT count the overall DES header if there is more than one
	record. To do this would require a count of all bytes to evaluate
	the DES header size. This action is the same as that of SizeLeft.

	******************************************************** 
	IMPORTANT NOTE: If aOffset traverses the database and  
	STOPS IN THE MIDDLE OF A NEW RECORD DES HEADER, it will return 
	THE DES HEADER OFFSET in the ATTRIBUTE OFFSET PARAMETER.
	This is ambiguous...
	****A calling function should ensure aOffset cannot do this***

	The method returns a bool to indicate the setting was OK. It will
	be false if the two index parameters were used and they would
	have set the lists beyond their end. Also it returns false if the
	offset was beyond the end of the data. If the method returns EFalse,
	the two index parameters are set to 0.

	This method can reset the parameters by being called with offset 0.
	However it will then return false.
	Parameter format is
 @verbatim
		Offset in bytes from start of attribute data		TUint
		Record index (0...)									TInt
		Attribute index (0...)								TInt
 @endverbatim
	Return format is
 @verbatim
		Were the offsets set OK								TBool
		Record index is set									TInt
		Attribute index is set								TInt
 @endverbatim

**/
EXPORT_C TBool CSizeAccumulator::StartAt(TUint aOffset, TUint& aPartSent, TInt& aRec, TInt& aAtt)
	{
	// calculates and sets the next record and attribute
	if (aOffset == 0)
		{
		aRec = 0; iFirstRec = 0;
		aAtt = 0; iFirstAtt = 0;
		aPartSent = 0;
		return EFalse;
		}
	TUint totalSize=0;
	TBool more = ETrue;
	TInt topRec = HandleCount();
	if (aRec > topRec)
		{
		aRec = 0; iFirstRec = 0;
		aAtt = 0; iFirstAtt = 0;
		aPartSent = 0;
		return EFalse;
		}
	else if (aRec == topRec)
		{
		TInt partAtt = AttrCount(topRec);
		if (aAtt > partAtt)
			{
			aRec = 0; iFirstRec = 0;
			aAtt = 0; iFirstAtt = 0;
			aPartSent = 0;
			return EFalse;
			}
		}
	iFirstRec = aRec;
	TInt firstAttForNextRecord = aAtt;
	while (more && (iFirstRec < topRec))
		{
		TUint recordSize = iHandleList->At(iFirstRec)->CHandleItem::iRecordSize;
		TInt topAtt = AttrCount(iFirstRec);
		iFirstAtt = firstAttForNextRecord < topAtt ? firstAttForNextRecord : topAtt;
// except for first record we always start with a record's first attribute
		firstAttForNextRecord = 0; 
// add in the DES header size for this record
		TUint desSize;
		desSize = (recordSize > 0xff) ? 3 : 2;
		desSize = (recordSize > 0xffff) ? 5 : desSize;
		if (totalSize + desSize > aOffset)
			//see "IMPORTANT NOTE" above this method
			{
			more = EFalse;
			break;
			}
		totalSize += desSize;
		while (more && (iFirstAtt < topAtt))
			{
			CAttrSizeItem* attr = AttributeOf(iFirstRec, iFirstAtt);
			TUint nextSize = attr->Size();
			nextSize += 3;	// Attribute ID and its header
			if (totalSize + nextSize > aOffset)
				{
				more = EFalse;
				break;
				}
			totalSize += nextSize;
			iFirstAtt++;
			}
		if (more) iFirstRec++;
		}
	if (totalSize == aOffset) more = EFalse;
	if (more)
		{
		aRec = 0; iFirstRec = 0;
		aAtt = 0; iFirstAtt = 0;
		aPartSent = 0;
		return EFalse;
		}
	aRec = iFirstRec;
	aAtt = iFirstAtt;
	aPartSent = aOffset - totalSize;
	return ETrue;
//	__ASSERT_DEBUG(totalSize != aOffset, DbPanic(ESdpDbBadSearchPattern));
	}
示例#11
0
 Plate(const Program& program)
   : shapes::ShapeWrapper(
       AttrNames(),
       AttrCount(),
       shapes::Plane(Vec3f(9, 0, 0), Vec3f(0, 0, -9)),
       program) {}
示例#12
0
const string & XMLElement :: AttrName( unsigned int i ) const {
	if ( i >= AttrCount() ) {
		ATHROW( "Attribute index " << SQuote( Str(i) ) << " out of range" );
	}
	return mAttrs[i].mName;
}