void DataDictionary::iterate( const FieldMap& map, const MsgType& msgType ) const { int lastField = 0; FieldMap::const_iterator i; for ( i = map.begin(); i != map.end(); ++i ) { const FieldBase& field = (*i); if( i != map.begin() && (field.getTag() == lastField) ) throw RepeatedTag( lastField ); checkHasValue( field ); if ( m_hasVersion ) { checkValidFormat( field ); checkValue( field ); } if ( m_beginString.getValue().length() && shouldCheckTag(field) ) { checkValidTagNumber( field ); if ( !Message::isHeaderField( field, this ) && !Message::isTrailerField( field, this ) ) { checkIsInMessage( field, msgType ); checkGroupCount( field, map, msgType ); } } lastField = field.getTag(); } }
inline void LogCodec::mapFieldToTerm(const std::string& field, const pion::platform::Vocabulary::Term& term, char delim_start, char delim_end, bool opt_delims, bool urlencode, char escape_char, const std::string& empty_val, bool do_time_offset, const PionDateTime::time_duration_type& time_offset) { for (FieldMap::const_iterator i = m_field_map.begin(); i != m_field_map.end(); ++i) { if (i->second->log_term.term_ref == term.term_ref) throw PionException("Duplicate Field Term"); } if (m_field_map.find(field) != m_field_map.end()) throw PionException("Duplicate Field Name"); // prepare a new Logfield object LogFieldPtr field_ptr(new LogField(field, term, delim_start, delim_end, opt_delims, urlencode, escape_char, empty_val, do_time_offset, time_offset)); switch (term.term_type) { case pion::platform::Vocabulary::TYPE_DATE_TIME: case pion::platform::Vocabulary::TYPE_DATE: case pion::platform::Vocabulary::TYPE_TIME: field_ptr->log_time_facet.setFormat(term.term_format); break; default: break; // do nothing } // add it to the mapping of field names m_field_map[field] = field_ptr; // append the new field to the current (default) format m_format.push_back(field_ptr); }
bool Document::matchesSearch (Glib::ustring const &search) { /* This is a bit of a hack, I guess, but it's a low-impact way of * implementing the change. If the search term contains a space, I * iteratively decompose it into substrings and pass those onto * this function. If anything doesn't match, we return a failure. */ if (search.find(' ') != Glib::ustring::npos) { Glib::ustring::size_type p1 = 0; Glib::ustring::size_type p2; do { /* Find the next space in the string, if any. */ p2 = search.find(' ', p1); /* Extract the appropriate substring. */ Glib::ustring const searchTerm = search.substr(p1, p2); /* If the term is empty, ignore it and move on. It might just be a * trailing or duplicate space character. */ if (searchTerm.empty()) { break; } /* Now that we have the substring, which is guaranteed to be * free of spaces, we can pass it recursively into this function. * If the term does NOT match, fail the entire comparison right away. */ if (!matchesSearch(searchTerm)) { return false; } p1 = p2 + 1; /* +1 to skip over the space */ } while (p2 != Glib::ustring::npos); /* Terminate at end of string */ return true; /* All matched, so OK. */ } Glib::ustring const searchNormalised = search.casefold(); FieldMap fields = getFields (); FieldMap::iterator fieldIter = fields.begin (); FieldMap::iterator const fieldEnd = fields.end (); for (; fieldIter != fieldEnd; ++fieldIter) { if (fieldIter->second.casefold().find(searchNormalised) != Glib::ustring::npos) return true; } if (notes_.casefold().find(searchNormalised) != Glib::ustring::npos) return true; if (key_.casefold().find(searchNormalised) != Glib::ustring::npos) return true; return false; }
HTTPRequest::HTTPRequest( HTTPConnection * inConnection, const char * inURL, bool inIsPost, const FieldMap& inExtraFields, const char * inContentBuffer, int inContentBufferLength, const char * inDestFile) { mConnection = NULL; mGotWholeHeader = false; mResponseNum = status_Pending; mDestFile = NULL; mDestFileName = inDestFile ? inDestFile : ""; mIncomingLength = -1; mReceivedPayload = 0; string request; if (inIsPost) request = "POST "; else request = "GET "; request += inURL; request += " HTTP/1.1\r\n"; for (FieldMap::const_iterator iter = inExtraFields.begin(); iter != inExtraFields.end(); ++iter) { request += iter->first; request += ": "; request += iter->second; request += "\r\n"; } if (inContentBuffer) { char buf[256]; sprintf(buf, "Content-Length: %d\r\n", inContentBufferLength); request += buf; } request += "\r\n"; mRequest.insert(mRequest.end(),request.begin(),request.end()); if (inContentBuffer) mRequest.insert(mRequest.end(),inContentBuffer,inContentBuffer+inContentBufferLength); if (inConnection) Retry(inConnection); }
std::vector<char *> getFieldNames(){ std::vector<char *> names; for (int i = 0; i < fieldMap.size(); i++){ names.push_back(fieldMap[i].name.getString()); } return names; }
int getFieldType(SString &name){ for (int i = 0; i < fieldMap.size(); i++){ if (fieldMap[i].name == name){ return fieldMap[i].val; } } throw DipException("field does not exist"); }
void Message::setGroup( const std::string& msg, const FieldBase& field, const std::string& string, std::string::size_type& pos, FieldMap& map, const DataDictionary& dataDictionary ) { int group = field.getTag(); int delim; const DataDictionary* pDD = 0; if ( !dataDictionary.getGroup( msg, group, delim, pDD ) ) return ; std::unique_ptr<Group> pGroup; while ( pos < string.size() ) { std::string::size_type oldPos = pos; FieldBase field = extractField( string, pos, &dataDictionary, &dataDictionary, pGroup.get() ); // Start a new group because... if (// found delimiter (field.getTag() == delim) || // no delimiter, but field belongs to group OR field already processed (pDD->isField( field.getTag() ) && (pGroup.get() == 0 || pGroup->isSetField( field.getTag() )) )) { if ( pGroup.get() ) { map.addGroupPtr( group, pGroup.release(), false ); } pGroup.reset( new Group( field.getTag(), delim, pDD->getOrderedFields() ) ); } else if ( !pDD->isField( field.getTag() ) ) { if ( pGroup.get() ) { map.addGroupPtr( group, pGroup.release(), false ); } pos = oldPos; return ; } if ( !pGroup.get() ) return ; pGroup->setField( field, false ); setGroup( msg, field, string, pos, *pGroup, *pDD ); } }
inline void LogCodec::changeELFFormat(char *fmt) { m_format.clear(); char *ptr; bool last_field = false; while (!last_field && *fmt != '\0' && m_event_split.find(*fmt) == std::string::npos) { // skip leading spaces while (*fmt == ' ') ++fmt; // find the end of the field name ptr = fmt; while (*ptr != '\0' && m_event_split.find(*ptr) == std::string::npos && *ptr != ' ') ++ptr; // set last_field if we're at the end if (*ptr == '\0' || m_event_split.find(*ptr) != std::string::npos) last_field = true; *ptr = '\0'; FieldMap::const_iterator i = m_field_map.find(fmt); if (i == m_field_map.end()) throw BadFormatException(fmt); m_format.push_back(i->second); fmt = ptr + 1; } }
IniConfigT::Iterator::Iterator(const FieldMap &container, ConstStrA section, ConstStrA prefix) :innerIter(container.seek(SectionField(section,ConstStrA()))) { if (innerIter.hasItems()) { const FieldMap::Entity &e = innerIter.peek(); if (e.key.section == section) { this->section = e.key.section; if (e.key.field.head(prefix.length()) == prefix) { prefix = e.key.field.head(prefix.length()); } } } }
void QFieldDefinitionData::init(TagMap &tagMap, FieldMap &fieldMap, ActionMap &actionMap, QTranslatableSettings &config) { QList<QFieldDefinition> fields; QMap<QString, QFieldAction> actions; fields = QFieldDefinitionData::readFields(config); actions = QFieldDefinitionData::readActions(config); foreach(QFieldDefinition def, fields) { if (!fieldMap.contains(def.id())) { fieldMap.insert(def.id(), def); QStringList tags = def.tags(); foreach(QString tag, tags) { QSet<QString> taggedFields; if (tagMap.contains(tag)) taggedFields = tagMap.value(tag); taggedFields.insert(def.id()); tagMap.insert(tag, taggedFields); } }
std::string Message::toXMLFields(const FieldMap& fields, int space) const { std::stringstream stream; FieldMap::iterator i; std::string name; for(i = fields.begin(); i != fields.end(); ++i) { int field = i->first; std::string value = i->second.getString(); stream << std::setw(space) << " " << "<field "; if(s_dataDictionary.get() && s_dataDictionary->getFieldName(field, name)) { stream << "name=\"" << name << "\" "; } stream << "number=\"" << field << "\""; if(s_dataDictionary.get() && s_dataDictionary->getValueName(field, value, name)) { stream << " enum=\"" << name << "\""; } stream << ">"; stream << "<![CDATA[" << value << "]]>"; stream << "</field>" << std::endl; } FieldMap::g_iterator j; for(j = fields.g_begin(); j != fields.g_end(); ++j) { std::vector<FieldMap*>::const_iterator k; for(k = j->second.begin(); k != j->second.end(); ++k) { stream << std::setw(space) << " " << "<group>" << std::endl << toXMLFields(*(*k), space+2) << std::setw(space) << " " << "</group>" << std::endl; } } return stream.str(); }
bool ProtobufTree::addTreeData(QTreeWidgetItem* parent, const google::protobuf::Message& msg) { const Reflection* ref = msg.GetReflection(); // Get fields in the message vector<const FieldDescriptor*> fields; ref->ListFields(msg, &fields); // Get map of field numbers to child items FieldMap fieldMap = parent->data(Column_Tag, FieldMapRole).value<FieldMap>(); bool newFields = false; // Clear data for missing fields const Descriptor* desc = msg.GetDescriptor(); for (FieldMap::const_iterator i = fieldMap.begin(); i != fieldMap.end(); ++i) { const FieldDescriptor* field = desc->FindFieldByNumber(i.key()); if (!field) { // Field has left the descriptor - should never happen printf("Lost field %s.%d\n", desc->name().c_str(), i.key()); continue; } QTreeWidgetItem* item = i.value(); bool hasData; if (field->is_repeated()) { hasData = ref->FieldSize(msg, field); if (!hasData && item->childCount()) { // Remove and delete children for (QTreeWidgetItem* child : item->takeChildren()) { delete child; } } } else { hasData = ref->HasField(msg, field); } if (!hasData) { item->setText(Column_Value, QString()); item->setData(Column_Value, Qt::CheckStateRole, QVariant()); } } for (const FieldDescriptor* field : fields) { // Get the item for this field if the field has been seen before QTreeWidgetItem* item; FieldMap::iterator fieldIter = fieldMap.find(field->number()); if (fieldIter != fieldMap.end()) { // Field is already in parent item = *fieldIter; } else { // New field item = new QTreeWidgetItem(parent); fieldMap.insert(field->number(), item); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); parent->setData(Column_Tag, FieldMapRole, QVariant::fromValue<FieldMap>(fieldMap)); item->setData(Column_Tag, Qt::DisplayRole, field->number()); item->setData(Column_Tag, FieldDescriptorRole, QVariant::fromValue(field)); item->setText(Column_Field, QString::fromStdString(field->name())); if (field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_repeated()) { // Singular messages are expanded by default expandItem(item); } newFields = true; } if (field->is_repeated()) { // Repeated field int n = ref->FieldSize(msg, field); // Show the number of elements as the value for the field itself item->setData(Column_Value, Qt::DisplayRole, n); // Make sure we have enough children int children = item->childCount(); if (children < n) { // Add children for (int i = children; i < n; ++i) { QTreeWidgetItem* child = new QTreeWidgetItem(item); child->setText(Column_Field, QString("[%1]").arg(i)); child->setData(Column_Tag, FieldDescriptorRole, field); // For repeated items, the tag column holds the index in the // field child->setData(Column_Tag, Qt::DisplayRole, i); // A FieldMap is not used here because the items don't // actually have tags. The item's position in its parent is // its position in the repeated field. } newFields = true; } else if (children > n) { // Remove excess children // Internally, QTreeWidgetItem stores a QList of children. // Hopefully this is efficient. QList<QTreeWidgetItem*> kids = item->takeChildren(); for (int i = 0; i < (children - n); ++i) { delete kids.back(); kids.pop_back(); } item->addChildren(kids); } // Set data for children for (int i = 0; i < n; ++i) { QTreeWidgetItem* child = item->child(i); switch (field->type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_SINT32: case FieldDescriptor::TYPE_FIXED32: case FieldDescriptor::TYPE_SFIXED32: child->setData(Column_Value, Qt::DisplayRole, ref->GetRepeatedInt32(msg, field, i)); break; case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_SINT64: case FieldDescriptor::TYPE_FIXED64: case FieldDescriptor::TYPE_SFIXED64: child->setData( Column_Value, Qt::DisplayRole, (qlonglong)ref->GetRepeatedInt64(msg, field, i)); break; case FieldDescriptor::TYPE_UINT32: child->setData(Column_Value, Qt::DisplayRole, ref->GetRepeatedUInt32(msg, field, i)); break; case FieldDescriptor::TYPE_UINT64: child->setData( Column_Value, Qt::DisplayRole, (qulonglong)ref->GetRepeatedUInt64(msg, field, i)); break; case FieldDescriptor::TYPE_FLOAT: child->setData(Column_Value, Qt::DisplayRole, ref->GetRepeatedFloat(msg, field, i)); break; case FieldDescriptor::TYPE_DOUBLE: child->setData(Column_Value, Qt::DisplayRole, ref->GetRepeatedDouble(msg, field, i)); break; case FieldDescriptor::TYPE_BOOL: child->setCheckState(Column_Value, ref->GetRepeatedBool(msg, field, i) ? Qt::Checked : Qt::Unchecked); break; case FieldDescriptor::TYPE_ENUM: { const EnumValueDescriptor* ev = ref->GetRepeatedEnum(msg, field, i); child->setText(Column_Value, QString::fromStdString(ev->name())); break; } case FieldDescriptor::TYPE_STRING: child->setText(Column_Value, QString::fromStdString( ref->GetRepeatedString( msg, field, i))); break; case FieldDescriptor::TYPE_MESSAGE: child->setData(Column_Tag, IsMessageRole, true); newFields |= addTreeData( child, ref->GetRepeatedMessage(msg, field, i)); break; case FieldDescriptor::TYPE_BYTES: addBytes(child, ref->GetRepeatedString(msg, field, i)); break; default: child->setText(Column_Value, QString("??? %1").arg(field->type())); break; } } } else switch (field->type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_SINT32: case FieldDescriptor::TYPE_FIXED32: case FieldDescriptor::TYPE_SFIXED32: item->setData(Column_Value, Qt::DisplayRole, ref->GetInt32(msg, field)); break; case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_SINT64: case FieldDescriptor::TYPE_FIXED64: case FieldDescriptor::TYPE_SFIXED64: item->setData(Column_Value, Qt::DisplayRole, (qlonglong)ref->GetInt64(msg, field)); break; case FieldDescriptor::TYPE_UINT32: item->setData(Column_Value, Qt::DisplayRole, ref->GetUInt32(msg, field)); break; case FieldDescriptor::TYPE_UINT64: item->setData(Column_Value, Qt::DisplayRole, (qulonglong)ref->GetUInt64(msg, field)); break; case FieldDescriptor::TYPE_FLOAT: item->setData(Column_Value, Qt::DisplayRole, ref->GetFloat(msg, field)); break; case FieldDescriptor::TYPE_DOUBLE: item->setData(Column_Value, Qt::DisplayRole, ref->GetDouble(msg, field)); break; case FieldDescriptor::TYPE_BOOL: item->setCheckState(Column_Value, ref->GetBool(msg, field) ? Qt::Checked : Qt::Unchecked); break; case FieldDescriptor::TYPE_ENUM: { const EnumValueDescriptor* ev = ref->GetEnum(msg, field); item->setText(Column_Value, QString::fromStdString(ev->name())); break; } case FieldDescriptor::TYPE_STRING: item->setText( Column_Value, QString::fromStdString(ref->GetString(msg, field))); break; case FieldDescriptor::TYPE_MESSAGE: item->setData(Column_Tag, IsMessageRole, true); newFields |= addTreeData(item, ref->GetMessage(msg, field)); break; case FieldDescriptor::TYPE_BYTES: addBytes(item, ref->GetString(msg, field)); break; default: item->setText(Column_Value, QString("??? %1").arg(field->type())); break; } } return newFields; }
foreach(Node *node, nodeList) { repulsionMap.add(node, node->pos()); }
// edge attraction QVector2D edgeAttractionForce = Newton::calculateAttractionForce(_attraction, QVector2D(node1->pos()), QVector2D(node2->pos())); node1->addToNetForce(edgeAttractionForce); node2->addToNetForce(-edgeAttractionForce); // edge repulsion QVector2D edgeRepulsionForce = Newton::calculateRepulsionForce(_repulsion, QVector2D(node1->pos()), QVector2D(node2->pos()), node1->getWeight(), node2->getWeight()); if(QVector2D(node1->pos() - node2->pos()).length() < 5) { node2->setPos(node2->pos() + QPointF(10, 10)); } node1->addToNetForce(edgeRepulsionForce); node2->addToNetForce(-edgeRepulsionForce); } // create repulsion fields FieldMap<Node> repulsionMap; foreach(Node *node, nodeList) { repulsionMap.add(node, node->pos()); } //calculate repulsion QList< QPair<Node*, Node*> > influencingNodes = repulsionMap.getInfluencingElements(); QPair<Node*, Node*> influencingPair; foreach(influencingPair, influencingNodes) { Node *node1 = influencingPair.first; Node *node2 = influencingPair.second; if(QVector2D(node1->pos() - node2->pos()).length() < 5) { node2->setPos(node2->pos() + QPointF(10, 10)); } QVector2D repulsionForce = Newton::calculateRepulsionForce(_repulsion, QVector2D(node1->pos()), QVector2D(node2->pos()), node1->getWeight(), node2->getWeight()); influencingPair.first->addToNetForce(repulsionForce);
DipPub(char ** names, int *types, int count) { for (int i = 0; i < count; i++){ fieldMap.push_back(Tuple(names[i], types[i])); } }
// // Method: fieldMapUpdate() // // Description: // Update the fieldmap // template<class dsa> void TypeSafety<dsa>::fieldMapUpdate (const DSNode * N) { FieldMap fmap; // // There are no overlapping fields if the DSNode has no fields. // if (N->type_begin() == N->type_end()) return; // // Iterate through the DSNode to see if the previous fields overlaps with the // current field. // DSNode::const_type_iterator tn = N->type_begin(); while (true) { // // If this is the last field, then we are done updating. // if (tn == N->type_end()) { break; } // // Get the information about the current field. // unsigned offset = tn->first; SuperSet<Type*>::setPtr TypeSet = tn->second; // // If there are multiple types in the current field, then the field is type-unsafe. // if (TypeSet) { svset<Type*>::const_iterator tb = TypeSet->begin(); if (++tb != TypeSet->end()) { fmap[offset] = true; DEBUG(errs() << "Multiple fields at " << offset << "\n"); } } for (DSNode::const_type_iterator ti = ++tn; ti != N->type_end(); ++ti) { // // Get the offset of the next field. // unsigned next_offset = ti->first; assert((next_offset >= offset) && "next offset should be larger than offset."); // // Check to see if any of the types in the current field extend into the // next field. // if (TypeSet) { bool overlaps = false; for (svset<Type*>::const_iterator ni = TypeSet->begin(), ne = TypeSet->end(); ni != ne; ++ni) { unsigned field_length = TD->getTypeStoreSize (*ni); if ((offset + field_length) > next_offset) { if(TypeInferenceOptimize) { if(const ArrayType *AT = dyn_cast<ArrayType>(*ni)) { Type *ElemTy = AT->getElementType(); while(ArrayType *AT1 = dyn_cast<ArrayType>(ElemTy)) ElemTy = AT1->getElementType(); if(next_offset < (TD->getTypeStoreSize(ElemTy) + offset)) { assert(isa<StructType>(ElemTy) && "Array Not of Struct Type??"); //overlaps = false; //fmap[next_offset] = false; continue; } } } fmap[offset] = true; fmap[next_offset] = true; overlaps = true; if(overlaps) { DEBUG(errs() << "Found overlap at " << offset << " with " << next_offset << "\n"); break; } } } if (!overlaps) break; } } if (fmap.find(offset) == fmap.end()) fmap[offset] = false; } // // Return the result. // NodeInfo[N] = fmap; return; }