Node Node::prepend(const std::string& tag, const Attributes& attributes, const std::string& text) { Node child = prepend(tag); for(auto attribute : attributes){ child.pimpl_->append_attribute(attribute.first.c_str()) = attribute.second.c_str(); } if(text.length()>0) child.pimpl_->append_child(pugi::node_pcdata).set_value(text.c_str()); return child; }
void Matrix3D::prependRotation(const float degrees, const Vector3D &axis, Vector3D *pivot) { if (pivot) { getAxisRotation(axis.x, axis.y, axis.y, pivot->x, pivot->y, pivot->z, degrees, _mt); } else { getAxisRotation(axis.x, axis.y, axis.y, 0, 0, 0, degrees, _mt); } prepend(_mt); }
// Returns the path from the source to given vertex // Pre: 1 <= u <= getOrder(G) void getPath(List L, Graph G, int u) { if(getSource(G) == NIL) { printf("Graph Error: calling getPath() with NULL source\n"); } if(u < 1 || u > getOrder(G)) { printf("Graph Error: calling getPath() with vertex out of bounds\n"); exit(1); } int s = G->source; if(u == s) { prepend(L, s); } else if(G->parent[u] == NIL) { append(L, NIL); } else { prepend(L, u); getPath(L, G, G->parent[u]); } }
template <class elem_t, class holder_t> void cdlist_tos_base<elem_t, holder_t>::insert(size_t elem_num, elem_t the_elem) { assert(elem_num >= 0); size_t total; holder_t *follow; if (elem_num == 0) { prepend(the_elem); return; } if (elem_num >= _cached_size) { while (_cached_size < elem_num) append(zero((elem_t *)0)); append(the_elem); return; } else if (elem_num - 1 <= _cached_index / 2) { /* Start at front. */ total = 0; follow = _head_e; } else if (elem_num - 1 <= (_cached_index + _cached_size) / 2) { /* Start at cache. */ total = _cached_index; follow = _cached_e; } else { /* Start at end. */ total = _cached_size - 1; follow = _tail_e; } while (total < elem_num - 1) { ++total; follow = follow->next; } while (total > elem_num - 1) { --total; follow = follow->previous; } holder_t *new_e = new holder_t(the_elem, follow->next, follow); follow->next = new_e; if (_tail_e == follow) _tail_e = new_e; else new_e->next->previous = new_e; _cached_index = elem_num; _cached_e = new_e; ++_cached_size; }
/* Returns the list of source vertices in g */ static List source_vertices(Graph graph) { List sources = NULL; for (int i = 0; i < graph->order; i++) { if (!graph->vertices[i].in) prepend(&sources, graph->vertices + i); } return sources; }
namespace boost { namespace hana { struct Function { struct hana { struct operators : boost::hana::operators::of<Comparable> { }; }; }; template <typename Domain, typename Codomain, typename F, typename = operators::adl> struct function_type { struct hana { using datatype = Function; }; Domain dom; Codomain cod; F def; friend constexpr auto domain(function_type f) { return f.dom; } friend constexpr auto codomain(function_type f) { return f.cod; } template <typename X> constexpr auto operator()(X x) const { if (!elem(domain(*this), x)) throw std::domain_error{"use of a hana::function with an argument out of the domain"}; return def(x); } }; BOOST_HANA_CONSTEXPR_LAMBDA auto function = [](auto domain, auto codomain) { return [=](auto definition) { return function_type<decltype(domain), decltype(codomain), decltype(definition)>{ domain, codomain, definition }; }; }; BOOST_HANA_CONSTEXPR_LAMBDA auto frange = [](auto f) { // Note: that would be better handled by a set data structure, but // whatever for now. return foldl(transform(domain(f), f), make<Tuple>(), [](auto xs, auto x) { return if_(elem(xs, x), xs, prepend(x, xs)); }); }; template <> struct equal_impl<Function, Function> { template <typename F, typename G> static constexpr auto apply(F f, G g) { return domain(f) == domain(g) && all_of(domain(f), demux(equal)(f, g)); } }; }} // end namespace boost::hana
Graph *add_edge(Graph *gr, uint32_t src, uint32_t dst, double prb) { EdgeNode *dst_node = new_edge_node(dst); dst_node->prob = prb; Vertex *src_vertex = gr->vertices[src]; if (src_vertex != NULL) { /* Don't access NULL pointers */ src_vertex->edges= prepend(dst_node, src_vertex->edges); src_vertex->num_edges = src_vertex->num_edges + 1; } return gr; }
/* Adds a key-value pair to a map. */ void map_add(Map *map, Hashable *key, Value *value) { int i; //holds for (i = 0; i<map->n; i++) { if (map->lists[i] == NULL){ map->lists[i] = prepend(key, value, NULL); break; } } }
inline Ptr operator*(Ptr value) { auto m1 = Matrix4x4::create(shared_from_this()); m1->prepend(value); return m1; }
/* * If the previous process is your parent increase identation level. */ int add_depth(pid_t parent, pid_t pid, struct node **head) { int rlist; if (parent == pid) { rlist = prepend(head, (pid_t) parent); return rlist; } return 2; }
Pix BaseDLList::ins_after(Pix p, const void *datum) { if (p == 0) return prepend(datum); BaseDLNode* u = (BaseDLNode*) p; BaseDLNode* t = copy_node(datum); t->bk = u; t->fd = u->fd; u->fd->bk = t; u->fd = t; return Pix(t); }
Polygon::Polygon(const Circle& circle, int points) { if(points <= 0) points = round(circle.radius() * 15); if(points < 3) points = 3; qreal max = 2 * M_PI; qreal inc = max / points; reserve(points); for(qreal d = 0; d < max; d += inc) { prepend(Point(cos(d) * circle.radius() + circle.center().x(), sin(d) * circle.radius() + circle.center().y())); } }
// take binary data and pack it to a TCP pack QByteArray PackParser::packRaw(const QByteArray &content) { auto result = content; quint32 length = content.length(); uchar c1, c2, c3, c4; c1 = length & 0xFF; length >>= 8; c2 = length & 0xFF; length >>= 8; c3 = length & 0xFF; length >>= 8; c4 = length & 0xFF; result.prepend(c1); result.prepend(c2); result.prepend(c3); result.prepend(c4); return result; }
ByteArray& ByteArray::prepend(const ByteArray& other) { if (isEmpty()) { d = other.d; } else { prepend(other.data(), other.size()); } return *this; }
struct node* build_n_nodes(int num) { struct node **ref_plast; struct node *phead = NULL; int i; ref_plast = &phead; for(i = 0; i < num; i++) { prepend(ref_plast, i); ref_plast = &((*ref_plast)->next); } return phead; }
int main () { //these work fine - functions given by Allen Hashable *hashable1 = make_hashable_int (1); Hashable *hashable2 = make_hashable_string ("Allen"); Hashable *hashable3 = make_hashable_int (2); // make_int_value also given Value *value1 = make_int_value (17); //failing here! Node *node1 = make_node(hashable1, value1, NULL); fprintf(stdout, "Print node:\n"); print_node (node1); Value *value2 = make_string_value ("Downey"); Node *list = prepend(hashable2, value2, node1); fprintf(stdout, "Print list:\n"); print_list (list); // run some test lookups Value *value = list_lookup (list, hashable1); fprintf(stdout, "List lookup:\n"); print_lookup(value); fprintf(stdout, "List lookup:\n"); value = list_lookup (list, hashable2); print_lookup(value); fprintf(stdout, "List lookup:\n"); value = list_lookup (list, hashable3); print_lookup(value); // make a map Map *map = make_map(10); map_add(map, hashable1, value1); map_add(map, hashable2, value2); printf ("Map\n"); print_map(map); // run some test lookups value = map_lookup(map, hashable1); print_lookup(value); value = map_lookup(map, hashable2); print_lookup(value); value = map_lookup(map, hashable3); print_lookup(value); return 0; }
OCompletionMatches::OCompletionMatches( const OCompletionMatchesWrapper& matches ) : _sorting( matches.sorting()) { if( matches.sortedList != 0L ) OCompletionMatchesList::operator=( *matches.sortedList ); else { QStringList l = matches.list(); for( QStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) prepend( OSortableItem<QString, int>( 1, *it ) ); } }
void pr_char(t_conv *conv) { int i; char fillchar; i = 1; fillchar = conv->zero ? '0' : ' '; while (i++ < conv->width) conv->str = conv->minus ? append(conv->str, i - 1, fillchar) : \ prepend(conv->str, i - 1, fillchar); if (conv->width == 0) conv->width = 1; }
void decimalfraction2pltext(int type, const std::string& n, std::string& tequiv, std::string& tinflection) { size_t pos = n.find(', '); if (pos == std::string::npos) { integer2pltext(type, n, tequiv, tinflection); return; } std::string n0, n1, te0, te1, ti0, ti1; n0 = n.substr(0, pos); n1 = n.substr(pos+1); integer2pltext(type, n0, te0, ti0); if (equals_one_half(n1)) { if (type == BEFORE_NOUN) { if (te0 != "#") tequiv = te0 + "ipół"; } else { join2(te0, "i pół", ti0, "0 0", tequiv, tinflection); } return; } if (type != CARDINAL && type != CARDINAL_G) return; if (n1.length() <= 3) { fractional2pltext(type, n1, te1, ti1); join3(te0, "i", te1, ti0, "0", ti1, tequiv, tinflection); } else { integer2pltext(CARDINAL, n1, te1, ti1); int i; for (i=0; n1[i]=='0'; i++) { prepend(te1, "zero", CARDINAL); prepend(ti1, "0", CARDINAL); } join3(te0, "przecinek", te1, ti0, "0", ti1, tequiv, tinflection); } }
static int send_incexc_str(const char *pre, const char *str) { char *tosend=NULL; if(!str) return 0; if(!(tosend=prepend(pre, str, strlen(str), " = "))) return -1; if(async_write_str(CMD_GEN, tosend)) { logp("Error in async_write_str when sending incexc\n"); return -1; } return 0; }
void PhotosTab::PerformCtxMenu (std::function<void (QModelIndex)> functor) { const auto& idx = sender ()->property ("Blasq/Index").value<QModelIndex> (); if (!idx.isValid ()) return; auto rows = Ui_.CollectionsTree_->selectionModel ()->selectedRows (); if (!rows.contains (idx)) rows.prepend (idx); for (const auto& row : rows) functor (row); }
QList<ProjectExplorer::NamedWidget *> IosBuildConfiguration::createSubConfigWidgets() { auto subConfigWidgets = QmakeBuildConfiguration::createSubConfigWidgets(); Core::Id devType = ProjectExplorer::DeviceTypeKitAspect::deviceTypeId(target()->kit()); // Ownership of this widget is with BuildSettingsWidget auto buildSettingsWidget = new IosBuildSettingsWidget(devType, m_signingIdentifier, m_autoManagedSigning); subConfigWidgets.prepend(buildSettingsWidget); connect(buildSettingsWidget, &IosBuildSettingsWidget::signingSettingsChanged, this, &IosBuildConfiguration::onSigningSettingsChanged); return subConfigWidgets; }
int main(int argc, char* argv[]){ List A = newList(); List B = newList(); List C = NULL; int i; for(i=1; i<=20; i++){ append(A,i); prepend(B,i); } printList(stdout,A); printf("\n"); printList(stdout,B); printf("\n"); for(moveFront(A); index(A)>=0; moveNext(A)){ printf("%d ", get(A)); } printf("\n"); for(moveBack(B); index(B)>=0; movePrev(B)){ printf("%d ", get(B)); } printf("\n"); C = copyList(A); printf("%s\n", equals(A,B)?"true":"false"); printf("%s\n", equals(B,C)?"true":"false"); printf("%s\n", equals(C,A)?"true":"false"); moveFront(A); for(i=0; i<5; i++) moveNext(A); // at index 5 insertBefore(A, -1); // at index 6 for(i=0; i<9; i++) moveNext(A); // at index 15 insertAfter(A, -2); for(i=0; i<5; i++) movePrev(A); // at index 10 delete(A); printList(stdout,A); printf("\n"); printf("%d\n", length(A)); clear(A); printf("%d\n", length(A)); freeList(&A); freeList(&B); freeList(&C); return(0); }
void append(Listnode **start, Data elem) { Listnode *ptr; Listnode *temp = (Listnode *) malloc(sizeof(Listnode)); if (temp == NULL) out_of_memory(); temp->content = elem; temp->next = NULL; if (*start == NULL) prepend(start, elem); else { for (ptr = *start; ptr->next != NULL; ptr = ptr->next); ptr->next = temp; } }
void ConcreteSite::handleReplyFinished () { auto reply = qobject_cast<QNetworkReply*> (sender ()); const auto& data = reply->readAll (); const auto& contentType = reply->header (QNetworkRequest::ContentTypeHeader); reply->deleteLater (); deleteLater (); if (reply->error () != QNetworkReply::NoError) return; #ifdef QT_DEBUG qDebug () << Q_FUNC_INFO << "got from" << Desc_.Name_ << "the data:" << data; #endif const auto codec = QTextCodec::codecForName (Desc_.Charset_.toLatin1 ()); if (!codec) qWarning () << Q_FUNC_INFO << "no codec for charset" << Desc_.Charset_ << "; will fallback to UTF-8"; auto str = codec ? codec->toUnicode (data) : QString::fromUtf8 (data.constData ()); if (std::any_of (Desc_.InvalidIndicators_.begin (), Desc_.InvalidIndicators_.end (), [&str] (const QString& ind) { return str.contains (ind); })) return; for (auto excluder : Desc_.Matchers_) str = (*excluder) (str); str = str.trimmed (); const bool isPlainText = contentType.toString ().toLower ().startsWith ("text/plain"); if (isPlainText) { str.prepend ("<pre>"); str.append ("</pre>"); } if (str.size () >= 100) emit gotLyrics ({ Query_, { { Desc_.Name_, str } } }); }
char *testContext_full_test_name(TestContext *context) { TestContext *current = context; size_t required_length = 0; while (1) { required_length += strlen(current->name); if (current->parent != NULL && current->parent->name != NULL) { required_length += 1; current = current->parent; } else { required_length += 1; break; } } current = context->parent; char *name = calloc(1, required_length); while (current != NULL && current->name != NULL) { prepend(name, " "); prepend(name, current->name); current = current->parent; } strncat(name, context->name, required_length); return name; }
template <class elem_t, class holder_t> void adlist_tos_base<elem_t, holder_t>::insert(size_t elem_num, elem_t the_elem) { assert(elem_num >= 0); if (elem_num == 0) { prepend(the_elem); return; } if (elem_num >= _cached_size) { while (_cached_size < elem_num) append(zero((elem_t *)0)); append(the_elem); return; } extend_array(); holder_t *follow; if (elem_num - 1 < _index_size) { follow = _index[elem_num - 1]; } else { if (_index_size == 0) { _index[0] = _head_e; typedef adlist_tos_base<elem_t, holder_t> *this_type; ++(CONST_CAST(this_type, this)->_index_size); } size_t total = _index_size - 1; follow = _index[total]; while (total < elem_num - 1) { ++total; follow = follow->next; _index[total] = follow; } } holder_t *new_e = new holder_t(the_elem, follow->next, follow); follow->next = new_e; if (_tail_e == follow) _tail_e = new_e; else new_e->next->previous = new_e; _index[elem_num] = new_e; _index_size = elem_num + 1; ++_cached_size; }
void SegmentedString::push(UChar c) { ASSERT(c); // pushIfPossible attempts to rewind the pointer in the SegmentedSubstring, // however it will fail if the SegmentedSubstring is empty, or // when we prepended some text while consuming a SegmentedSubstring by // document.write(). if (m_currentString.pushIfPossible(c)) { m_currentChar = c; return; } prepend(SegmentedString(String(&c, 1)), PrependType::Unconsume); }
static int append_to_feat(char **feat, const char *str) { char *tmp=NULL; if(!*feat) { if(!(*feat=strdup_w(str, __func__))) return -1; return 0; } if(!(tmp=prepend(*feat, str))) return -1; free_w(feat); *feat=tmp; return 0; }
/* get a filename from the next entry in the dll path */ static char *next_dll_path( struct dll_path_context *context ) { unsigned int index = context->index++; int namelen = context->namelen; char *path = context->name; switch(index) { case 0: /* try programs dir for .exe files */ if (!context->win16 && namelen > 4 && !memcmp( context->name + namelen - 4, ".exe", 4 )) { path = prepend( path, context->name, namelen - 4 ); path = prepend( path, "/programs", sizeof("/programs") - 1 ); path = prepend( path, build_dir, strlen(build_dir) ); return path; } context->index++; /* fall through */ case 1: /* try dlls dir with subdir prefix */ if (namelen > 4 && !memcmp( context->name + namelen - 4, ".dll", 4 )) namelen -= 4; if (!context->win16) path = prepend( path, context->name, namelen ); path = prepend( path, "/dlls", sizeof("/dlls") - 1 ); path = prepend( path, build_dir, strlen(build_dir) ); return path; default: index -= 2; if (index < nb_dll_paths) return prepend( context->name, dll_paths[index], strlen( dll_paths[index] )); break; } return NULL; }