csc Any::rand(bir ssr) const { auto bs = bytesize(); csc bufI(0, static_cast<size_t>(bs)); uint8array_rangerand(reinterpret_cast<uint8_t*>(const_cast<char*>(bufI.data())), bs, 0, 255); return bufI; }
// { dg-do compile { target c++11 } } // From N2235 // function template 1 template<typename T> constexpr int bytesize(T t) { return sizeof (t); } // OK char buf[bytesize(0)]; // OK -- not C99 VLA // function template 2 template<typename _Tp> constexpr _Tp square(_Tp x) { return x; } // Explicit specialization template<> constexpr unsigned long square(unsigned long x) { return x * x; } // Explicit instantiation template int square(int); class A { }; template A square(A); template long square(long);
void MoralityServer::getCommand(int PlayerID, MoralThread *theThread, QByteArray packetcommand) { qDebug() << "GETTING COMMAND FROM THE THREAD" <<endl; qDebug() << "COMMAND: " << packetcommand << endl; // RESPOND TO THE CLIENT REQUEST HERE! // Response to the client would be more difficult and would have to have repeating keys for which we can use regular expressions to split // LOCATION::ID1-1,ID2-4,ID3-19 // {socket descriptor that your computer would turn into player 0, 1, 2, ... n players // WINNING ::ID // Which socket descriptor won // SCORE ::ID1-900,ID2-100000 // etc. QString incomingcommand(packetcommand); if (!incomingcommand.contains("//") || !incomingcommand.contains("::")) return; // DONT DO ANYTHING WITH EMPTY LINES QStringList BytesCommand = incomingcommand.split("//",QString::SkipEmptyParts); qint16 bytesize(BytesCommand[0].toInt()); // if (BytesCommand[1].size() != bytesize) // no it's not really bytes // qDebug() << "incorrect packet size!"; // but do nothing... really how big are our packets? 20 bytes? QStringList CKeyVal = BytesCommand[1].split("::"); QString commandString; if (CKeyVal[0] == "LOCATION") { commandString="LOCATION::"; qDebug() << CKeyVal[1] << endl; int newlocation = CKeyVal[1].toInt(); qDebug() << newlocation << endl; moveToLocation(PlayerID, newlocation); commandString.append(getLocations()); } else if (CKeyVal[0] == "WINNING") { commandString="WINNING::"; commandString.append(QString::number(PlayerID)); // just broadcast this to all players } else if (CKeyVal[0] == "SCORE") { // After winning is received on the server, clients will send a SCORE VALUE... // when received from all clients, will emit back in unison // commandString="SCORE::"; // commandString.append() NOT SURE ABOUT THIS YET SCORE OR ALIGNMENT // IT COULD BE DISPLAYED SOMEHOW } else if (CKeyVal[0] == "DAMAGE") { emit sendCommand(packetcommand); // the same one that came from the client since already in the right format return; } else if (incomingcommand.contains("SOCKETID")) { commandString="SOCKETID::"; commandString.append(QString::number(theThread->getSocketDescriptor())); QString command; command = QString::number(commandString.size()); // packet size command.append(tr("//")); command.append(commandString); QByteArray newPacketCommand; newPacketCommand.append(command); for (int i =0; i < Morals.size(); i++) { if (Morals[i]->getSocketDescriptor() == theThread->getSocketDescriptor()) { Morals[i]->commandToSocket(newPacketCommand); return; } } } else { return; } QString command; command = QString::number(commandString.size()); // packet size command.append(tr("//")); command.append(commandString); QByteArray newPacketCommand; newPacketCommand.append(command); for (int i =0; i < Morals.size(); i++) { Morals[i]->commandToSocket(newPacketCommand); } qDebug() << "THE PACKET: " << newPacketCommand <<endl; }
Offset<const Table *> CopyTable(FlatBufferBuilder &fbb, const reflection::Schema &schema, const reflection::Object &objectdef, const Table &table, bool use_string_pooling) { // Before we can construct the table, we have to first generate any // subobjects, and collect their offsets. std::vector<uoffset_t> offsets; auto fielddefs = objectdef.fields(); for (auto it = fielddefs->begin(); it != fielddefs->end(); ++it) { auto &fielddef = **it; // Skip if field is not present in the source. if (!table.CheckField(fielddef.offset())) continue; uoffset_t offset = 0; switch (fielddef.type()->base_type()) { case reflection::String: { offset = use_string_pooling ? fbb.CreateSharedString(GetFieldS(table, fielddef)).o : fbb.CreateString(GetFieldS(table, fielddef)).o; break; } case reflection::Obj: { auto &subobjectdef = *schema.objects()->Get(fielddef.type()->index()); if (!subobjectdef.is_struct()) { offset = CopyTable(fbb, schema, subobjectdef, *GetFieldT(table, fielddef)).o; } break; } case reflection::Union: { auto &subobjectdef = GetUnionType(schema, objectdef, fielddef, table); offset = CopyTable(fbb, schema, subobjectdef, *GetFieldT(table, fielddef)).o; break; } case reflection::Vector: { auto vec = table.GetPointer<const Vector<Offset<Table>> *>( fielddef.offset()); auto element_base_type = fielddef.type()->element(); auto elemobjectdef = element_base_type == reflection::Obj ? schema.objects()->Get(fielddef.type()->index()) : nullptr; switch (element_base_type) { case reflection::String: { std::vector<Offset<const String *>> elements(vec->size()); auto vec_s = reinterpret_cast<const Vector<Offset<String>> *>(vec); for (uoffset_t i = 0; i < vec_s->size(); i++) { elements[i] = use_string_pooling ? fbb.CreateSharedString(vec_s->Get(i)).o : fbb.CreateString(vec_s->Get(i)).o; } offset = fbb.CreateVector(elements).o; break; } case reflection::Obj: { if (!elemobjectdef->is_struct()) { std::vector<Offset<const Table *>> elements(vec->size()); for (uoffset_t i = 0; i < vec->size(); i++) { elements[i] = CopyTable(fbb, schema, *elemobjectdef, *vec->Get(i)); } offset = fbb.CreateVector(elements).o; break; } } // FALL-THRU default: { // Scalars and structs. auto element_size = GetTypeSize(element_base_type); if (elemobjectdef && elemobjectdef->is_struct()) element_size = elemobjectdef->bytesize(); fbb.StartVector(element_size, vec->size()); fbb.PushBytes(vec->Data(), element_size * vec->size()); offset = fbb.EndVector(vec->size()); break; } } break; } default: // Scalars. break; } if (offset) { offsets.push_back(offset); } } // Now we can build the actual table from either offsets or scalar data. auto start = objectdef.is_struct() ? fbb.StartStruct(objectdef.minalign()) : fbb.StartTable(); size_t offset_idx = 0; for (auto it = fielddefs->begin(); it != fielddefs->end(); ++it) { auto &fielddef = **it; if (!table.CheckField(fielddef.offset())) continue; auto base_type = fielddef.type()->base_type(); switch (base_type) { case reflection::Obj: { auto &subobjectdef = *schema.objects()->Get(fielddef.type()->index()); if (subobjectdef.is_struct()) { CopyInline(fbb, fielddef, table, subobjectdef.minalign(), subobjectdef.bytesize()); break; } } // ELSE FALL-THRU case reflection::Union: case reflection::String: case reflection::Vector: fbb.AddOffset(fielddef.offset(), Offset<void>(offsets[offset_idx++])); break; default: { // Scalars. auto size = GetTypeSize(base_type); CopyInline(fbb, fielddef, table, size, size); break; } } } assert(offset_idx == offsets.size()); if (objectdef.is_struct()) { fbb.ClearOffsets(); return fbb.EndStruct(); } else { return fbb.EndTable(start, static_cast<voffset_t>(fielddefs->size())); } }