w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
C# WPF managing nested structures using ItemsControl
You're not defining any TextBoxes anywhere, That's why you're not getting any TextBoxes in the Visual Tree: <Window x:Class="MiscSamples.NestedItemsControls" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="NestedItemsControls" Height="300" Width="300"> <ItemsControl ItemsSource="{Binding Level1}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding Level2}"> <ItemsControl.Ite

Categories : C#

Accessing fields of nested structures
if you mean just go to the inner variables then var3ptr->var1; var3ptr->var2; for example if struct A { int x; }; struct B { int y; }; then you can do printf("%d", var3ptr->var1.x); printf("%d", var3ptr->var2.y);

Categories : C

Nested Array Structures in Ruby
Restaurant = {:name=>"McDonalds", :location=>"NYC", :chefs=> [{:name=>"Sunny", :food=>"fries"}, {:name=>"Brooklyn", :food=>"burgers"}, {:name=>"Mac", :food=>"burgers"}], :waiters=> [{:name=>"Jess", :role=>"senior manager"}, {:name=>"Sam", :role=>"manager"}, {:name=>"Jack", :role=>"server"}, {:name=>"Mary", :role=>"server"}]} keys = Restaurant.map{|k,v| k if v.is_a? Array}.compact keys.each{|i| Restaurant[i].each{|h| p h.keys,h.values}} Output: [:name, :food] ["Sunny", "fries"] [:name, :food] ["Brooklyn", "burgers"] [:name, :food] ["Mac", "burgers"] [:name, :role] ["Jess", "senior manager"] [:name, :role] ["Sam", "manager"] [:name, :role] ["Jack", "server"] [:name, :role] ["Mary", "server"] keys.each{|i| Re

Categories : Ruby

Parsing of nested structures and object model
It is difficult to answer if some approach is better in terms of effeciency without a more concrete problem description. Below you can find some food for thought. Point 1: When thinking about class design it worths to also examine the desired behaviour and not just the data. The fact that the binary format used for storage, may or may not imply a hierarchy, should be taken into account of course, but it should not be the primary concern. As an example, assume we have a Person class that has a height field and a Rectangle class that also has a height field. They both share some data but having only this information makes them rather irrelevant to each other. If we define the context and we say we want to draw them on the screen then suddenly the height field has a more specific meaning.

Categories : Java

Nested Data Structures in Java (inner classes)
You can do what you suggest. If you want to prevent others creating instances you can make the constructors package local or private. If the classes are also public, you can access the methods anywhere, but only construct them where you have allowed.

Categories : Java

Extracting values from deeply nested JSON structures
You could create your own path mechanism and then query the complicated dict with paths. Example: / : get the root object /key: get the value of root_object['key'], e.g. /foo_code --> 404 /key/key: nesting: /foo_rbody/query/info/acme_no -> 444444 /key[i]: get ith element of that list, e.g. /xyzzy_rbody/api/items[0]/desc --> "OK" The path can also return a dict which you then run more queries on, etc. It would be fairly easy to implement recursively.

Categories : Python

Which languages support Lenses or similar way to update immutable nested structures?
There's really no need for language-level support for lenses—although of course they may be more or less useful depending on properties of the language, and the clarity of the syntax will depend on language features. As I mention in a comment above, there are good lens libraries for Scala even though the language itself doesn't (and arguably shouldn't) provide them. For example, suppose we have the following classes: case class Email(user: String, domain: String) case class Contact(email: Email, web: String) case class Person(name: String, contact: Contact) And an instance: val foo = Person( "Foo McBar", Contact(Email("foo", "mcbar.com"), "http://mcbar.com/foo") ) Using Shapeless you can write the following (note that in the upcoming 2.0 version the isomorphism boilerplate won

Categories : Java

char array marshaling in C#
answer: Have a look at David Heffernan's comments - he seems more knowledgeable and to have spent a lot more time on this. previous attempts: Then again, after some more search, that should answer your exact question. If you want to marshal to char* (which basically is the same as char[]) you will need to use a StringBuilder. See this completely unrelated example that shows the signature from pinvoke.net. You should then either recreate your structure or internally copy/convert it (if used elsewhere as well) to the following: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct CallbackParams { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public StringBuilder displayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]

Categories : C#

Marshaling and Unmarshaling using Castor
i prefer to use jaxB as it is light weight and marshalling and unmarshalling will not occupy much memories click here for example

Categories : Java

Marshaling ushort[,] multidimensional array in C#
My take: A multi-dimensional array is just a continuous array of size of all the dimensions. In your case, the 'C' code will see it as ushort[5 * 100]. To make this work, do the following: ushort[,] myTable = new ushort[5, 100]; // multidimensional array unsafe { fixed (ushort* inputPtr = myTable) { readTable(inputPtr); } } Unfortunately, I dont have time to test this, but it compiles just fine.

Categories : C#

Function taking an array filled with structures, and returning a bigger array with the same structures
You can't reassign friends like that since it's not a pointer, it's an array. Even if you could, what you're doing isn't safe since GrowArray just creates a new array on the stack which will be destroyed when the function returns. You should either use new and delete to create and destroy the arrays (you can then then pass them around as pointers), or preferably, use std::vector which handles all this stuff for you.

Categories : C++

How to get rid of namespace when marshaling generic objects with JAXB
In this use case the http://www.w3.org/2001/XMLSchema-instance and http://www.w3.org/2001/XMLSchema namespaces are being brought in because of the xsi:type attribute. The xsi:type attribute is being brought in because your JAXB implementation believes the property type to be Object. The solution is to ensure the properties aren't typed Object. The XML representation looks like part of the representation for java.util.Map (see: http://blog.bdoughan.com/2013/03/jaxb-and-javautilmap.html). Is this your use case or do you have another object model?

Categories : Java

Testing for deep equality with json marshaling in golang
I figured it out! JSON only has one numerical type, which is floating point, so all integers are converted to Float64 in the marshal/unmarshal process. So, in the res map, the 5 is a float64 instead of an int. Here is a go playground that provides context and evidence of what I'm talking about.

Categories : Json

Struts 1.1 nested and in combination
Use <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> and the code will look like <c:choose> <c:when test="${element.method1 == true}"> <c:choose> <c:when test="${element.method2 == true}"> <span style="color:green;"><c:out value="${element.prop1}/></span> </c:when> <c:otherwise> <span style="color:red;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose> </c:when> <c:otherwise> <span style="color:black;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose>

Categories : Java

C structures declarations
In the very beginning of your program, add forward declaration for NetworkNode: struct NetworkNode; This allows compiler to understand what is NetworkNode and break that catch-22 that in definition of ConnectionNode you need to mention NetworkNode and vice versa. UPDATE: Also, you need to change your definition of ConnectionNode: ... struct NetworkNode target; ... to use pointer instead: struct NetworkNode *target; Without this, compiler would not know how how much memory to allocate for NetworkNode (even with forward declaration). Pointers, on other hand, always have the same size.

Categories : C

C++ best fit data structures
I would define a new graph including only the nodes and archs which are "touched" by at least one of the results of finding the connections between (1, 4). This way you would have only one "routine" that does the path-searching and everything would be homogeneous.

Categories : C++

Removing Structures
If you want to delete a member of structure: Matrixraw = struct('field1', 1, 'field2', '2') Matrixraw = field1: 1 field2: 2 // delete first element of structure Matrixraw(1) = [] Matrixraw = field1: [] field2: [] The syntax below will empty the structure and remove completely your variable data: // both works Matrixraw = {} Matrixraw = []

Categories : Matlab

C- Structures and Unions
Fundamentally, you need to think about data storage in C differently. In essence, a union in C says that it can hold any of the items in it (enough memory is allocated for any type included), but that a single instance will only hold 1. When you access a field, such as an integer, you're looking at the place in memory and treating the bits (0s and 1s) in memory there as an integer. Strings are written as an array of characters. You can look at any place in memory as a number and there will be one (constructed of whatever happen to be there before). Now what you are seeing is that treating this union as either of two possible structures both contain the string. This is because the location of the string is in the same place in either struct (at the beginning, offset 0), so with either

Categories : C

How use two structures of xml with the same function
Try with simplexml_load_file $xmlfile = "rss.xml"; // or feed.xml $xml= simplexml_load_file($xmlfile); $array = $xml->channel->item ? $xml->channel->item : $xml->article; foreach($array as $value) { echo $value->link; }

Categories : PHP

Unpredictable output using structures in C
You should use unsigned int. The highest bit, defines whether a number is negative or positive if signed values are used. If you have only one bit, and this is 1, then it it is interpreted as a negative number as the highest bit is set. If you set the other values to 15 you will also get a negative output. You could modify the output by using %u in the printf command, but you would still have possibly unwanted effects when assigning and comparing it with other values.

Categories : C

search through an array of structures
you have to use strstr() and not strcmp() int i; for (i=0; i<sizeof(comp)/sizeof(comp[0]); i++) { if (strstr(comp[i].company, mystring)) printf("Country is: %s ", comp[i].country) }

Categories : C

simple pointer to structures
scanf("%d",(pStudents+i)->age); the argument of scanf must be of a pointer type. Change (pStudents+i)->age to &(pStudents+i)->age.

Categories : C

C++ data structures instead of database
Take a look at Berkeley DB, it is a popular embedded database that has good performance. Latest versions offer a SQL-like API, this can simplify the migration of your code from your a classical SQL database. However, be careful of the license terms of this library. It is available in both a GPL-like license and commercial license (i.e. no LGLP-like license is available). Depending of your application (and your wallet), this may be an issue.

Categories : C++

How to read an array of Structures in IOS
Did you read the documentation? Graphics Type Conversions When going back and forth between Cocoa and Quartz code, some conversion of data types may be necessary. Table 9-1 shows the Cocoa equivalents of some basic Quartz types. Table 9-1 Simple data-type conversions Cocoa type Quartz type NSRect CGRect NSPoint CGPoint NSSize CGSize Although in each case the structure layout is the same, you cannot pass the Quartz data type directly to a method expecting the Cocoa type. To convert, you must cast from one type to another, as shown in the following example: NSRect cocoaRect = *(NSRect*)&myCGRect;

Categories : IOS

Structures and input from files
You probably want to do something like this. This implementation assumes that there are no blank lines in the input file. There are lot of hard coding here, you may want to make it better. I hope this helps you... typedef struct foo { char occupation[256]; int numbers[2][5]; }FOO; void function(FOO input[]); void function(FOO input[]) { FILE* file; file = fopen("textfile.txt","r"); int a = 0, count, i; char temp[81]; char randomwords[81]; if (file == NULL) { return; } fscanf(file, "%[^ ] ", randomwords); printf("%s ", randomwords); while (feof(file) != EOF) { i = 0; i = fscanf(file, "%[^ ] ", input[a].occupation); if (i == -1) break; for (count=0; count < 5; count++)

Categories : C

Populating a 3D array of structures in C
A few ways to do this off the top of my head: Have your data be equal to the size of your 3D array. Pad the unused or empty elements with 0s or so other sentinel value so you know it is "not real." This is less space efficient, but makes reading and setting the data as simple as a single fread() call. Use an RLE type scheme where you have a 1 byte where the top bit says if the next run is valid data or empty followed by the number of bytes in the run (up to 127 or 128 if 0 runs are not allowed). If valid data, read that many structures in and directly load them into your grid. If invalid run, skip that many structures or mark them some how as invalid. Advantage being it is pretty space efficient, but slower to read as it will take multiple IO calls. XML data format where you can set

Categories : C

Turn "foreach" into "for" with structures
You can access the details of the array with <?php for ($i = 0; $i <=4; $i++) { echo $_additional[$i]['label']; echo $_helper->productAttribute($_product, $_additional[$i]['value'], $_additional[$i]['code']); }

Categories : PHP

Is it possible to add attributes to external structures?
Attributes are metadata class, that are included to the assemply at compile time, So it is impossible to add attiributes to a class dynamically at runtime, check this questions: Can attributes be added dynamically in C#?

Categories : C#

C++ data structures and CUDA
C++ template is designed for this situation. template <class T> void compute(){ // some code // data on devices (up to 10) T xxx[10]; // this is where i want either type1 or type2 structures // the "type" is not known at compile time but i want to // determine at runtime based on some input variable. this // part is not real code rather this is what i want to achive. int DevUsed; // some code to give value to int DevUsed for(int idev=0;idev<DevUsed;idev++){ // set cuda device if ( cudaMalloc(&xxx[iDev], sizeof(T)) != cudaSuccess ) // print error message; cudaMemcpy(xxx[iDev], pIF1, sizeof(T), cudaMemcpyHostToDevice); function2<<<grid, block>>>(xxx

Categories : C++

P/invoke conditional structures
If you need to support Windows XP, then you need to use only the fields defined in Windows XP. The issue isn't directly the size of the structure, but the value of cbSize. If it does not match a value that the API is expecting then the API call will fail. So passing a cbSize of the larger Vista version of the struct will cause the API to fail (that is return a failure code, it won't crash). If you need to you could detect the version of Windows that you are running on and pass in the size that there version of Windows expects (You can pass in the larger sized struct, Windows will just ignore the extra bytes) But you only need to do that if you need to have c and d filled in on Vista+. See this blog post for the reasons why a sending in a larger cbSize are rejected.

Categories : C#

JOIN data from two many-to-many SQL structures
Use DISTINCT in the GROUP_CONCAT maybe SELECT *, GROUP_CONCAT(DISTINCT ambienceName SEPARATOR ' ') AS ambiences, GROUP_CONCAT(DISTINCT specificName SEPARATOR ' ') AS specifics FROM Films AS f LEFT OUTER JOIN Films_Ambiences as fa ON f.id = fa.film_id LEFT OUTER JOIN Ambiences AS a ON a.id = fa.ambience_id LEFT OUTER JOIN Films_Specifics as fs ON f.id = fs.film_id LEFT OUTER JOIN Specifics AS s ON s.id = fs.specific_id GROUP BY Title

Categories : Mysql

Pointer to array of Structures
You need to ensure that the field has pointer type. You can do this with Structure.ByReference (make a subclass of your structure class which implements the Structure.ByReference tagging interface) and then use Structure.toArray() to overlay a contiguous array of struct over that memory. You can also just use a simple Pointer, but then you'll need to manually read/write the structure and related objects, as well as do native memory synchronization that JNA normally does for you. For example: class StructA { public static class ByReference extends StructA implements Structure.ByReference { } } class StructB { public StructA.ByReference sa; public int size; public StructA[] getMembers() { return (StructA[])sa.toArray(this.size); } }

Categories : Java

Passing Structures by Reference
You need to allocate memory for both coeff and roots structures. Replace the two lines c = NULL; r = NULL; by c = malloc ( sizeof ( struct coeff ) ); r = malloc ( sizeof ( struct roots ) ); Also, at the end of code (before the return statement), deallocate the memory by free ( c ); free ( r );

Categories : C

Sorting an array of structures in C
Look up qsort() from <stdlib.h>. It takes a comparator function. You can write separate comparator functions for the different sort orders, but still use the standard library qsort() to do the sorting. For example: int ms_cmp_string1(const void *vp1, const void *vp2) { const MyStruct *ms1 = vp1; const MyStruct *ms2 = vp2; int cmp = strcmp(ms1->string1, ms1->string2); if (cmp != 0) return cmp; else if (ms1->number1 < ms2->number1) return -1; else if (ms1->number1 > ms2->number1) return +1; //...other comparisons as required... else return 0; } This is a decent outline for comparators. This one sorts on string1 and then by number1. You can either write variants that sort on different fields

Categories : C

Polymorphic data structures in C
I hope I understand what you want - I'm unsure but I guess you want to do something like that: typedef struct { int type; // file or folder? } Item; typedef struct { struct A; // data related to a file } File; typedef struct { struct A; // data related to a folder - like pointer to list of Item } Folder; As long as both structure follow the same memory mapping (same variables) and adds to it as a child, you'll be able to use the pointer properly in both structs. Check this one out as well: How can I simulate OO-style polymorphism in C? Edit: I'm not sure about the syntax above (took it from the link above). I'm used to writing it this way instead: typedef struct { int type; // data for file } File; typedef struct { int type; // data for folder - list, etc }

Categories : C

C: Data structures alignment
Be careful, you aren't sure that your variables are aligned (but it often is). If you use GCC you can use the attribute packed for be sure that your datas are aligned. Example : struct foo { char c; int x; } __attribute__((packed)); As I understand it's not working with stand-alone variables. Like char str[] = "Hello";? This table will be aligned in your memory.

Categories : C++

restrict the pointers in structures
You need to do this: a2.p = malloc( sizeof( int ) ); // << Note this. if ( a2.p == NULL ) { // We ran out of memory in the memory pool. Do some error handling. } *( a2.p ) = 30; ... note that a1.p and a2.p both point to the same block of memory. Hence, change where a2.p points before mutating its value. Aside: Do not malloc a fixed size (your malloc( 4 ) should be malloc( sizeof( int ) )).

Categories : C

Best way to store vector of structures
It depends if your vector will instantiate those structures or not. If former, you don't have any reason to store pointers at all. Pointers are helpful if you store actual values somewhere else, but need to gather pointers to those values in one place.

Categories : C++

Data structures in java
The following: Customer temp = customer; if(ptr==null){ ptr = temp; }else{ ptr.next = temp; // <<<< } loses the original value of ptr.next. As a result, your list only keeps the first and the last elements that you add.

Categories : Java

Using LINQ with tree structures
I believe you can use an iterator. Something like this might just work: static IEnumerable<Folder> Descendants(Folder root) { var nodes = new Stack<Folder>(new[] { root }); while (nodes.Any()) { Folder node = nodes.Pop(); yield return node; foreach (var n in node.Children) nodes.Push(n); } } For each node yielded it will only traverse the previous nodes children. This is basically stolen (only slightly modified) from here I believe you could then do something like: // This is the function I currently have that only returns 1 folder // needs to somehow be expanded to return devices for all folders beneath it too function GetFolderDevices(int folderId, PaginationOptions options)

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.