コード例 #1
0
    /*
     * Marshalls this classes data members into a single
     * contiguous memory location for the purpose of storing
     * the data in a database.
     */
    char *
    getBuffer()
    {
        // Zero out the buffer
        memset(databuf_, 0, 500);
        /*
         * Now pack the data into a single contiguous memory location for
         * storage.
         */
        bufLen_ = 0;
        int dataLen = 0;

        dataLen = sizeof(double);
        memcpy(databuf_, &price_, dataLen);
        bufLen_ += dataLen;

        dataLen = sizeof(long);
        memcpy(databuf_ + bufLen_, &quantity_, dataLen);
        bufLen_ += dataLen;

        packString(databuf_, name_);
        packString(databuf_, sku_);
        packString(databuf_, category_);
        packString(databuf_, vendor_);

        return (databuf_);
    }
コード例 #2
0
ファイル: settings.cpp プロジェクト: thegaragelab/iothing
/** Pack an entire setting description into the buffer
 */
static int packSetting(unsigned char *pBuffer, int index, int size, SettingDescription &setting) {
  if (index>=size)
    return 0;
  // 1 byte for type
  pBuffer[index++] = setting.typeAndModifier;
  // The name
  if ((index=packString(pBuffer, index, size, setting.name))<=0)
    return index;
  // And the value itself
  switch(setting.typeAndModifier & SETTING_TYPE_MASK) {
    case StringSetting:
      index = packString(pBuffer, index, size, setting.value.string);
      break;
    case IntegerSetting:
      index = packInteger(pBuffer, index, size, setting.value.integer);
      break;
    case BooleanSetting:
      index = packBoolean(pBuffer, index, size, setting.value.boolean);
      break;
    case NumberSetting:
      index = packDouble(pBuffer, index, size, setting.value.number);
      break;
    default:
      index = 0;
    }
  return index;
  }
コード例 #3
0
ファイル: ui2uib.cpp プロジェクト: aroraujjwal/qt3
static void packStringSplit( UibStrTable& strings, QDataStream& out,
			     const QString& str, QChar sep )
{
    int pos = str.find( sep );
    if ( pos == -1 )
	pos = str.length();
    packString( strings, out, str.left(pos) );
    packString( strings, out, str.mid(pos) );
}
コード例 #4
0
  void pack(Packer& pk, int index) const {
    int t = lua_type(L, index);
    switch (t) {
    case LUA_TNUMBER: packNumber(pk, index); break;
    case LUA_TBOOLEAN: packBoolean(pk, index); break;
    case LUA_TSTRING:  packString(pk, index); break;
    case LUA_TTABLE: packTable(pk, index); break;
    case LUA_TUSERDATA:
      // TODO: support userdata serialization.
      // Calling __serialize meta-method may be good.

      // raise an error temporally
      luaL_error(L, "Packing userdata has not been supported yet. "
                 "However, it will be implemented soon.");
      return;

    case LUA_TNIL:
    case LUA_TTHREAD:
    case LUA_TLIGHTUSERDATA:
    default:
      luaL_error(L, "invalid type for pack: %s",
                 lua_typename(L, t));
      break;
    }
  }
コード例 #5
0
ファイル: FileIncoming.cpp プロジェクト: awwit/httpserver
	void packFilesIncoming(
		std::vector<char> &buf,
		const std::unordered_multimap<std::string, Transfer::FileIncoming> &map
	) {
		packNumber(buf, map.size() );

		for (auto it = map.cbegin(); map.cend() != it; ++it) {
			packString(buf, it->first);

			const Transfer::FileIncoming &file = it->second;

			packString(buf, file.getTmpName() );
			packString(buf, file.getName() );
			packString(buf, file.getType() );
			packNumber(buf, file.getSize() );
		}
	}
コード例 #6
0
ファイル: EEmcDbIO.C プロジェクト: star-bnl/star-emc
int
EEmcDbCCIO<eemcDbPIXname>::scan (const char *line , char *name, int i)
{
  if(i==0) {// clear data before first use
    memset(data()->tubeName,' ',sizeof(data()->tubeName));
    data()->tubeName[sizeof(data()->tubeName)-1]=0;
  }
  char txt  [EEMCDbMaxName];
  int r=sscanf(line,"%s %s",    name,txt);
  packString(data()->tubeName,i,EEMCDbMaxName,txt);
  if(r>=2)dprintf("%s %s\n",name,txt);
  return(r>=2);
}
コード例 #7
0
int icq_httpGatewayWrapSend( HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend )
{
	icq_packet packet;
	int sendResult;

	packet.wLen = len;
	write_httphdr( &packet, HTTP_PACKETTYPE_FLAP );
	packString( &packet, buf, ( WORD )len );
	sendResult = Netlib_Send( hConn, packet.pData, packet.wLen, flags );
	mir_free( packet.pData );
	if( sendResult <= 0 )
		return sendResult;
	if( sendResult < 14 )
		return 0;
	return sendResult - 14;
}
コード例 #8
0
ファイル: EEmcDbIO.C プロジェクト: star-bnl/star-emc
int 
EEmcDbCCIO<T>::read(FILE *f)
{
  char line[MaxLine];
  char tn  [EEMCDbMaxName];
  T*   s = data();

  memset(bytePtr,0x00,bytes);
  resetString(s->name,getSize(),EEMCDbMaxName);
  memset(s->comment,0x20,sizeof(s->comment));

  int i=0;
  while ( fgets(line,MaxLine,f) != NULL && i<getSize() )  { 
    if( ! checkLine(line) ) continue;
    memset(tn,0x00,EEMCDbMaxName);    
    if( ! scan(line,tn,i) ) *tn=0x00; 
    packString(s->name,i,EEMCDbMaxName,tn);
    i++;
  };
  s->name   [sizeof(s->name)   -1]=0x00; // *** potential bug for last name ***
  if(comment) strncpy(s->comment,comment,EEMCDbMaxComment);
  return (i>0);
}
コード例 #9
0
ファイル: ui2uib.cpp プロジェクト: aroraujjwal/qt3
void convertUiToUib( QDomDocument& doc, QDataStream& out )
{
    QByteArray introBlock;
    QByteArray actionsBlock;
    QByteArray buddiesBlock;
    QByteArray connectionsBlock;
    QByteArray functionsBlock;
    QByteArray imagesBlock;
    QByteArray menubarBlock;
    QByteArray slotsBlock;
    QByteArray tabstopsBlock;
    QByteArray toolbarsBlock;
    QByteArray variablesBlock;
    QByteArray widgetBlock;

    QDomElement actionsElem;
    QDomElement connectionsElem;
    QDomElement imagesElem;
    QDomElement menubarElem;
    QDomElement tabstopsElem;
    QDomElement toolbarsElem;
    QDomElement widgetElem;

    QMap<int, QStringList> buddies;
    UibStrTable strings;
    UibIndexMap objects;
    int widgetNo = -1;
    QCString className;
    Q_INT16 defaultMargin = -32768;
    Q_INT16 defaultSpacing = -32768;
    Q_UINT8 introFlags = 0;

    QDomElement elem = doc.firstChild().toElement().firstChild().toElement();
    while ( !elem.isNull() ) {
	QString tag = elem.tagName();

	switch ( tag[0].latin1() ) {
	case 'a':
	    if ( tag == "actions" )
		actionsElem = elem;
	    break;
	case 'c':
	    if ( tag == "class" ) {
		className = elem.firstChild().toText().data().latin1();
	    } else if ( tag == "connections" ) {
		connectionsElem = elem;
	    }
	    break;
	case 'f':
	    if ( tag == "functions" ) {
		QDataStream out2( functionsBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "function" ) {
			packStringSplit( strings, out2,
					 f.attribute("name").latin1(), '(' );
			packString( strings, out2,
				    f.firstChild().toText().data() );
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'i':
	    if ( tag == "images" ) {
		QDataStream out2( imagesBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "image" ) {
			QString name = f.attribute( "name" );
			QDomElement g = f.firstChild().toElement();
			if ( g.tagName() == "data" ) {
			    QString format = g.attribute( "format", "PNG" );
			    QString hex = g.firstChild().toText().data();
			    int n = hex.length() / 2;
			    QByteArray data( n );
			    for ( int i = 0; i < n; i++ )
				data[i] = (char) hex.mid( 2 * i, 2 )
						    .toUInt( 0, 16 );

			    packString( strings, out2, name );
			    packString( strings, out2, format );
			    packUInt32( out2, g.attribute("length").toInt() );
			    packByteArray( out2, data );
			}
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'l':
	    if ( tag == "layoutdefaults" ) {
		QString margin = elem.attribute( "margin" );
		if ( !margin.isEmpty() )
		    defaultMargin = margin.toInt();
		QString spacing = elem.attribute( "spacing" );
		if ( !spacing.isEmpty() )
		    defaultSpacing = spacing.toInt();
	    }
	    break;
	case 'm':
	    if ( tag == "menubar" )
		menubarElem = elem;
	    break;
	case 'p':
	    if ( tag == "pixmapinproject" )
		introFlags |= Intro_Pixmapinproject;
	    break;
	case 's':
	    if ( tag == "slots" ) {
		QDataStream out2( slotsBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "slot" ) {
			QString language = f.attribute( "language", "C++" );
			QString slot = UibHack::normalize(
				f.firstChild().toText().data() );
			packString( strings, out2, language );
			packStringSplit( strings, out2, slot, '(' );
		    }
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 't':
	    if ( tag == "tabstops" ) {
		tabstopsElem = elem;
	    } else if ( tag == "toolbars" ) {
		toolbarsElem = elem;
	    }
	    break;
	case 'v':
	    if ( tag == "variable" ) {
		QDataStream out2( variablesBlock, IO_WriteOnly | IO_Append );
		packString( strings, out2, elem.firstChild().toText().data() );
	    } else if ( tag == "variables" ) {
		QDataStream out2( variablesBlock, IO_WriteOnly );
		QDomElement f = elem.firstChild().toElement();
		while ( !f.isNull() ) {
		    if ( f.tagName() == "variable" )
			packString( strings, out2,
				    f.firstChild().toText().data() );
		    f = f.nextSibling().toElement();
		}
	    }
	    break;
	case 'w':
	    if ( tag == "widget" )
		widgetElem = elem;
	}
	elem = elem.nextSibling().toElement();
    }

    {
	QDataStream out2( widgetBlock, IO_WriteOnly );
	widgetNo = outputObject( buddies, objects, strings, out2, widgetElem,
				 "QWidget" );
    }

    if ( !tabstopsElem.isNull() ) {
	QDataStream out2( tabstopsBlock, IO_WriteOnly );
	QDomElement f = tabstopsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "tabstop" ) {
		QString widgetName = f.firstChild().toText().data();
		int no = objects.find( widgetName );
		if ( no != -1 )
		    packUInt16( out2, no );
	    }
	    f = f.nextSibling().toElement();
	}
    }

    if ( !actionsElem.isNull() ) {
	QDataStream out2( actionsBlock, IO_WriteOnly );
	outputObject( buddies, objects, strings, out2, actionsElem );
    }

    if ( !menubarElem.isNull() ) {
	QDataStream out2( menubarBlock, IO_WriteOnly );
	outputObject( buddies, objects, strings, out2, menubarElem,
		      "QMenuBar" );
    }

    if ( !toolbarsElem.isNull() ) {
	QDataStream out2( toolbarsBlock, IO_WriteOnly );
	QDomElement f = toolbarsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "toolbar" )
		outputObject( buddies, objects, strings, out2, f, "QToolBar" );
	    f = f.nextSibling().toElement();
	}
    }

    if ( !buddies.isEmpty() ) {
	QDataStream out2( buddiesBlock, IO_WriteOnly );
	QMap<int, QStringList>::ConstIterator a = buddies.begin();
	while ( a != buddies.end() ) {
	    QStringList::ConstIterator b = (*a).begin();
	    while ( b != (*a).end() ) {
		int no = objects.find( *b );
		if ( no != -1 ) {
		    packUInt16( out2, a.key() );
		    packUInt16( out2, no );
		}
		++b;
	    }
	    ++a;
	}
    }

    if ( !connectionsElem.isNull() ) {
	QString prevLanguage = "C++";
	int prevSenderNo = 0;
	QString prevSignal = "clicked()";
	int prevReceiverNo = 0;
	QString prevSlot = "accept()";

	QDataStream out2( connectionsBlock, IO_WriteOnly );
	QDomElement f = connectionsElem.firstChild().toElement();
	while ( !f.isNull() ) {
	    if ( f.tagName() == "connection" ) {
		QMap<QString, QString> argMap;

		QDomElement g = f.firstChild().toElement();
		while ( !g.isNull() ) {
		    argMap[g.tagName()] = g.firstChild().toText().data();
		    g = g.nextSibling().toElement();
		}

		QString language = f.attribute( "language", "C++" );
		int senderNo = objects.find( argMap["sender"], widgetNo );
		int receiverNo = objects.find( argMap["receiver"], widgetNo );
		QString signal = UibHack::normalize( argMap["signal"] );
		QString slot = UibHack::normalize( argMap["slot"] );

		Q_UINT8 connectionFlags = 0;
		if ( language != prevLanguage )
		    connectionFlags |= Connection_Language;
		if ( senderNo != prevSenderNo )
		    connectionFlags |= Connection_Sender;
		if ( signal != prevSignal )
		    connectionFlags |= Connection_Signal;
		if ( receiverNo != prevReceiverNo )
		    connectionFlags |= Connection_Receiver;
		if ( slot != prevSlot )
		    connectionFlags |= Connection_Slot;
		out2 << connectionFlags;

		if ( connectionFlags & Connection_Language )
		    packString( strings, out2, language );
		if ( connectionFlags & Connection_Sender )
		    packUInt16( out2, senderNo );
		if ( connectionFlags & Connection_Signal )
		    packStringSplit( strings, out2, signal, '(' );
		if ( connectionFlags & Connection_Receiver )
		    packUInt16( out2, receiverNo );
		if ( connectionFlags & Connection_Slot )
		    packStringSplit( strings, out2, slot, '(' );

		prevLanguage = language;
		prevSenderNo = senderNo;
		prevSignal = signal;
		prevReceiverNo = receiverNo;
		prevSlot = slot;
	    } else if ( f.tagName() == "slot" ) {
		// ###
	    }
	    f = f.nextSibling().toElement();
	}
    }

    {
	QDataStream out2( introBlock, IO_WriteOnly );
	out2 << introFlags;
	out2 << defaultMargin;
	out2 << defaultSpacing;
	packUInt16( out2, objects.count() );
	packCString( strings, out2, className );
    }

    out << UibMagic;
    out << (Q_UINT8) '\n';
    out << (Q_UINT8) '\r';
    out << (Q_UINT8) out.version();
    outputBlock( out, Block_Strings, strings.block() );
    outputBlock( out, Block_Intro, introBlock );
    outputBlock( out, Block_Images, imagesBlock );
    outputBlock( out, Block_Widget, widgetBlock );
    outputBlock( out, Block_Slots, slotsBlock );
    outputBlock( out, Block_Tabstops, tabstopsBlock );
    outputBlock( out, Block_Actions, actionsBlock );
    outputBlock( out, Block_Menubar, menubarBlock );
    outputBlock( out, Block_Toolbars, toolbarsBlock );
    outputBlock( out, Block_Variables, variablesBlock );
    outputBlock( out, Block_Functions, functionsBlock );
    outputBlock( out, Block_Buddies, buddiesBlock );
    outputBlock( out, Block_Connections, connectionsBlock );
    out << (Q_UINT8) Block_End;
}
コード例 #10
0
ファイル: ui2uib.cpp プロジェクト: aroraujjwal/qt3
static void outputProperty( QMap<int, QStringList>& buddies, int objectNo,
			    UibStrTable& strings, QDataStream& out,
			    QDomElement elem )
{
    QCString name = elem.attribute( "name" ).latin1();
    QDomElement f = elem.firstChild().toElement();
    QString tag = f.tagName();
    QString comment;
    QVariant value;

    if ( name == "resizeable" )
	name = "resizable";

    if ( tag == "font" ) {
	QString family;
	Q_UINT16 pointSize = 65535;
	Q_UINT8 fontFlags = 0;

	QDomElement g = f.firstChild().toElement();
	while ( !g.isNull() ) {
	    QString text = g.firstChild().toText().data();
	    if ( g.tagName() == "family" ) {
		fontFlags |= Font_Family;
		family = text;
	    } else if ( g.tagName() == "pointsize" ) {
		fontFlags |= Font_PointSize;
		pointSize = (Q_UINT16) text.toUInt();
	    } else {
		if ( g.firstChild().toText().data().toInt() != 0 ) {
		    if ( g.tagName() == "bold" ) {
			fontFlags |= Font_Bold;
		    } else if ( g.tagName() == "italic" ) {
			fontFlags |= Font_Italic;
		    } else if ( g.tagName() == "underline" ) {
			fontFlags |= Font_Underline;
		    } else if ( g.tagName() == "strikeout" ) {
			fontFlags |= Font_StrikeOut;
		    }
		}
	    }
	    g = g.nextSibling().toElement();
	}

	out << (Q_UINT8) Object_FontProperty;
	packCString( strings, out, name );
	out << fontFlags;
	if ( fontFlags & Font_Family )
	    packString( strings, out, family );
	if ( fontFlags & Font_PointSize )
	    packUInt16( out, pointSize );
    } else if ( tag == "palette" ) {
	out << (Q_UINT8) Object_PaletteProperty;
	packCString( strings, out, name );

	QDomElement g = f.firstChild().toElement();
	while ( !g.isNull() ) {
	    QDomElement h = g.firstChild().toElement();
	    while ( !h.isNull() ) {
		value = DomTool::elementToVariant( h, Qt::gray );
		if ( h.tagName() == "color" ) {
		    out << (Q_UINT8) Palette_Color;
		    out << value.asColor();
		} else if ( h.tagName() == "pixmap" ) {
		    out << (Q_UINT8) Palette_Pixmap;
		    packVariant( strings, out, value, "pixmap" );
		}
		h = h.nextSibling().toElement();
	    }

	    if ( g.tagName() == "active" ) {
		out << (Q_UINT8) Palette_Active;
	    } else if ( g.tagName() == "inactive" ) {
		out << (Q_UINT8) Palette_Inactive;
	    } else {
		out << (Q_UINT8) Palette_Disabled;
	    }
	    g = g.nextSibling().toElement();
	}
	out << (Q_UINT8) Palette_End;
    } else {
	value = DomTool::elementToVariant( f, value, comment );
	if ( value.isValid() ) {
	    if ( name == "buddy" ) {
		buddies[objectNo] += value.asString();
	    } else {
		if ( tag == "string" ) {
		    out << (Q_UINT8) Object_TextProperty;
		    packCString( strings, out, name );
		    packCString( strings, out, value.asString().utf8() );
		    packCString( strings, out, comment.utf8() );
		} else {
		    out << (Q_UINT8) Object_VariantProperty;
		    packCString( strings, out, name );
		    packVariant( strings, out, value, tag );
		}
	    }
	}
    }
}
コード例 #11
0
ファイル: ui2uib.cpp プロジェクト: aroraujjwal/qt3
static void packVariant( UibStrTable& strings, QDataStream& out,
			 QVariant value, QString tag = "" )
{
    QStringList::ConstIterator s;

    Q_UINT8 type = value.type();
    if ( tag == "pixmap" ) {
	type = QVariant::Pixmap;
    } else if ( tag == "image" ) {
	type = QVariant::Image;
    } else if ( tag == "iconset" ) {
	type = QVariant::IconSet;
    }
    out << type;

    switch ( type ) {
    case QVariant::String:
    case QVariant::Pixmap:
    case QVariant::Image:
    case QVariant::IconSet:
	packString( strings, out, value.asString() );
	break;
    case QVariant::StringList:
	packUInt16( out, value.asStringList().count() );
	s = value.asStringList().begin();
	while ( s != value.asStringList().end() ) {
	    packString( strings, out, *s );
	    ++s;
	}
	break;
    case QVariant::Font:
	out << value.asFont();
	break;
    case QVariant::Rect:
	packUInt16( out, value.asRect().x() );
	packUInt16( out, value.asRect().y() );
	packUInt16( out, value.asRect().width() );
	packUInt16( out, value.asRect().height() );
	break;
    case QVariant::Size:
	packUInt16( out, value.asSize().width() );
	packUInt16( out, value.asSize().height() );
	break;
    case QVariant::Color:
	out << value.asColor();
	break;
    case QVariant::Point:
	packUInt16( out, value.asPoint().x() );
	packUInt16( out, value.asPoint().y() );
	break;
    case QVariant::Int:
	packUInt32( out, value.asInt() );
	break;
    case QVariant::Bool:
	out << (Q_UINT8) value.asBool();
	break;
    case QVariant::Double:
	out << value.asDouble();
	break;
    case QVariant::CString:
	packCString( strings, out, value.asCString() );
	break;
    case QVariant::Cursor:
	out << value.asCursor();
	break;
    case QVariant::Date:
	out << value.asDate();
	break;
    case QVariant::Time:
	out << value.asTime();
	break;
    case QVariant::DateTime:
	out << value.asDateTime();
	break;
    default:
	out << value;
    }
}