w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to get two class objects from on PFQuery in ios sdk?
The current version of Parse SDK (1.2.12) does not provide such feature right out of the box. The PFQuery Class only provides methods such as queryWithClassName: limited to one Class at a time. You have to create and execute two separate PFQuery.

Categories : Iphone

How to get the PFRelation objects while getting the PFquery objects?
There is a method you can use to include properties which are pointer values. You cannot use the include method with relations. What I do instead is use a Cloud Code function to aggregate the results I want into a JSON object and return that object. See the fetchPostDetails function in the following script. https://github.com/brennanMKE/PostThings/blob/master/Parse/PostThings/cloud/main.js It fetches items are relation objects such as tags and likes which happen to be User objects which are relations to the Post class. There are also comments which are referenced as a pointer back to the post from each comment. The fetchPostTags and fetchPostLikes methods show how to fetch those relations and populate the JSON object which is holding all of the results. You need to deploy those Cloud Co

Categories : Iphone

How to add objects of two PFquery data using parse?
I think you'd be better off storing pointers as opposed to Id's, this way you can include that data as well. I will not use predicates, I realize your query is cleaner with predicates, but I think the logic is easier to see with this. You can convert it back to predicate for yourself. // get your user PFUser * userForQuery; // set up your user for the query, if it's current user, = [PFUser currentUser]; // first part of predicate PFQuery * innerQueryA = [PFQuery queryWithClassName:@"FriendsDetails"]; [innerQueryA whereKey:@"UserFriend" equalTo:userForQuery]; // from @"UserFriendId" [innerQueryA whereKey:@"User" notEqualTo:userForQuery]; // from @"UserId" // second part of predicate PFQuery * innerQueryB = [PFQuery queryWithClassName:@"FriendsDetails"]; [innerQueryB whereKey:@"userF

Categories : IOS

Make DataGridView Show Properties of Derived Class Objects when Using List of Base Class Objects
One way is to cast back each element in the list,do the next change and you will get 1,2,3 in the datagridview: col.DataPropertyName = "MyPropertyDerived"; dataGridView.Columns.Add(col); dataGridView.DataSource = list.ConvertAll(c => c as MyDerivedClass);

Categories : C#

python dict of class objects that inherits attributes from class objects
This is a bit of an odd question, but it very much depends on what 'D' is structurally. If D is just a data structure, then it is perfectly valid to pack the dictionary with the objects, subcript and call the functions like so: class A(object): def __init__(self,x): self.x = x def first(self): return self.x a = A(7) b = A(3) d = {'X':a,'Y':b} print d['X'].first() Alongside this, if you want all "firsts" then you can do something like this: firsts = {} for i,j in d: firsts[i]=j.first() However, it seems like your challenge is a little more complex, plus unsafe: what if an objecy in the dictionary has a keys() method? Which takes precedence, and if its the dictionaries, how do I access the keys() method of the contents? What I'd suggest is reframing, or reaski

Categories : Python

C++ - Copying of objects of derived class into objects of base class
You cannot convert a base object to a derived object because there isn't enough information. It's like having an empty sandwich and pretending its a BLT! The problem with downcasting an object is that the derived class may be bigger so wouldn't fit in the available memory but the pointer is allowed since the derived class is exactly and more of the base class. Continuing the sandwich metaphor: if you ignore the filling, a BLT is just an empty sandwich. In your example mgr6 thinks it is pointing to a manager but say there was a getter for bool salaried called IsSalaried() what should happen if when you call mgr6->IsSalaried(). This is obviously not logical therefore it is not allowed.

Categories : C++

How to use PFQuery in ios for beginner
Example: PFQuery *query = [PFQuery queryWithClassName:@"tempClass"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { // The find succeeded. The first 100 objects are available in objects } else { // Log details of the failure NSLog(@"Error: %@ %@", error, [error userInfo]); } }]; Good starter: Parse with TableView

Categories : Iphone

adding multiple class objects to a single list and returning the values from the objects
You can provide an overload of the ToString method for each class: class classOne:onetwo { int item1 = 10; int item2 = 11; public override string ToString() { return string.Format("item1: {0}, item2: {1}", item1, item2); } } class classTwo:onetwo { string item3 = "red"; string item4 = "blue"; public override string ToString() { return string.Format("item3: {0}, item4: {1}", item3, item4); } } Another alternative is to provide a custom method in your base class to generate a formatted string via reflection: class onetwo { public virtual string ToPrintableString() { return string.Join(", ", this.GetType() .GetFields() .Select(p => p.Name + ": " + p.G

Categories : C#

Java - Collection of abstract class, children contain disparate objects - Any "good" way to handle these wrapped objects?
You discarded in your question the "good" way of doing it. Generics will not help in this case. Yes, you are going to be cursed to a nasty place for the ugly use of type checking. You can disguise the type checking using a common instance member called, say, category and its corresponding accessor getCategory defined in MyClass. And them do a switch if you can (instead of multiple ifs) on getCategory(). However, the people who will condemn you could dislike ifs and switches no matter if they are checking for types or not. And they could also be smart and understand what you are trying to do. Anything but for(MyClass e: collection ) e.doYourAction(); is "bad". Now, for software that seems to have no specification at all, you could be pardoned.

Categories : Java

Convert one set of objects to another set of objects of different class in single line. C#
You could use LINQ: List<event> listOfEvents = (from eachEvent in eventsFromArgus select new Event( ReaderName = eachEvent.DeviceName, EventCode = eachEvent.EventCode, EventReceivedTime = eachEvent.ReceiveTime.ToString(), EventOriginTime = eachEvent.OriginTime.ToString(), CardNumber = eachEvent.CredentialIdentifier)).ToList(); But that's not terribly different from what you already have. Or, you could look into something like AutoMapper.

Categories : C#

PFquery table view control show detail
Then I try to explain as best as possible ... I downloaded from the project parse.com PFQueryTableViewController. I entered all the data perfectly recall the Databrowser ... My cells are thus created: #import "TableViewParse.h" #import "CustomNav.h" #import "ListaInAttesa.h" @implementation TableViewParse @synthesize TableViewInAttesa; - (id)initWithCoder:(NSCoder *)aCoder { self = [super initWithCoder:aCoder]; // Custom the table // The className to query on self.parseClassName = @"miaclasse"; // The key of the PFObject to display in the label of the default cell style self.textKey = @"titolomio"; // Whether the built-in pull-to-refresh is enabled self.pullToRefreshEnabled = YES; // Whether the built-in pag

Categories : Iphone

What should be the PFQuery to fetch record for column type "array" at parse?
In the docs there is a section for query on array values: // Find objects where the array in arrayKey contains 2. [query whereKey:@"arrayKey" equalTo:[NSNumber numberWithInt:2]];

Categories : IOS

Fetching objects of class B stored in a list inside class A with Hibernate Criteria
This is the expected result. You are running the query on the User class so, the output would be a collection of User and not notification public List<Notification> getNotifications(Long id){ //Start the transaction //do some error handling and transaction rollback User user = session.createQuery("from User where id = :id").setParameter("id", id).uniqueParameter(); List<Notification> notifications = new ArrayList<Notification>(); for (Notification notification : user.getNotifications()){ if (notification.getDate.before(calendar.getTime()){ notifications.add(notification); } } //commit the transaction //close the session return notifications; } Or the other way of doing it would be to use Filters. You can find a tutorial on filters here

Categories : Java

Creating an array of pointers of derivative class objects. C++. Abstract base class
Since there isn't a question: make sure your base class has a virtual destructor. Without a virtual destructor you won't be able to easily delete the objects. To maintain the objects I would create a simple version of std::unique_ptr if I have to write it myself (well, for my own standard library implementation I, obviously, have an implementation anyway which I'd think I should be able to use...).

Categories : C++

Comparing objects from two instances of a Class and storing result in List
The best way to do this is to make ESHClass know how to compare itself for equality. See this link for a fairly in-depth example, or this question for a more minimal set. Basically, you give the code enough information to be able to evaluate eshlist[0] == eshlist[1] directly.

Categories : C#

Class instantiation in Dart and sharing code between Class objects
Sure. Classes have the state and the behavior. The state is encoded in member variables of the class. Each instance has its own copy of variables, thus its own state. The behavior is specified by the methods implemented in the class ('methods' here stand for all static, non-static methods, setters and getters). Implementation is shared by all instances of the class, so all instances behave the same, but actual results and side-effects depend on instance state, obviously.

Categories : Dart

Map with Class as keys and values having objects operating on key class instances
You can't do this with just a normal Map; you have to do your own wrapping with a method that enforces the type constraint. See the related question Java generics enforce same type for keys and values of map.

Categories : Java

Class creating multiple objects of another class at the same memory location (C++)
This line: std::cout << &myFSM.getTopNode(); probably prints the address of a temporary object, not the actual object in the vector. This will be true if you're not returning by reference but rather by value. So it's not weird if the temporary happens to be created at the same location each time, since after the temporary dies, its location in memory is free to be used again later. In order to get the actual object rather than a copy of it, getTopNode() needs to do: Node& FSM::getTopNode() { if (nodeList.empty()) { // Up to you how to handle this error. } return nodeList.back(); } Of course, if your current getTopNode() implementation actually already returns a pointer: Node* FSM::getTopNode() then your problem is that you're printing out the ad

Categories : C++

Objects of same class having varying selection of the class members (C++)
Use inheritance. You may need some virtual methods too. class Settlement { public: virtual void updateMarketCount()=0;//pure virtual function }; class Town : public Settlement { public: virtual void updateMarketCount(); private: int m_markets; int m_industries; }; class Village : public Settlement { public: virtual void updateMarketCount(); private: int m_markets; }; This way you can assign all of these objects to a generic settlement pointer. For example: std::shared_ptr<Settlement> mysettlementPtr(new Town());//C++ 11 only. Found in memory header Settlement* mysettlementPtr = new Town();//C++ < 11 Here is how to do a vector: std::vector<std::shared_ptr<Settlement>> mySettlements; mySettlements

Categories : C++

Accumulate objects of the same class within a class member function
Your problem is that Raven::sum_life is a member function. Thankfully, you can use std::bind and pass "this" as the first argument. Your code would look like: auto f = std::bind(&Raven::sum_life, this, std::placeholders::_1, std::placeholders::_2); _avg_lifespan = (float)std::accumulate(flock.begin(), flock.end(),0,f)/flock.size();

Categories : C++

Objects of class A in Class B in Class Diagram
It is not generalization as you are not inheriting in here, so it cannot qualify as an "is-a" relationship. As for association, composition or aggregation... here you can find a pretty good explanation which is which. It is not possible to tell the right one for you without knowing your use case better. However, reading the other link will help you to understand the differences and judge based on your scenario. Difference between association, aggregation and composition Hope that helps.

Categories : C++

When a class "has a" relationship with other class objects
Definitely do not make an attached to property. I would just make the wheels a property on the appropriate class, but a property called attached is an awkward approach. This looks like a good use of the Builder pattern. http://www.dofactory.com/Patterns/PatternBuilder.aspx In general use SOLID and prefer composition over inheritance. http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)

Categories : C#

In c++, is it possible for a class to have an array that contains objects of another class?
You can certainly create an array inside the class Basket using Apple fruit[10]; to allow for a maximum of 10 apples in the basket. So, your Basket declaration will look like: // define basket class Basket { //class attrs; private private: std::string name; // I want Basket objects to have an array of Apple objects // How do I do this? Apple fruit [10]; public: //class function Basket(std::string); //constructor std::string get_name() {return (name);} }; Another way will be to create a vector of Apples.

Categories : C++

How store class objects in vector> and access and pass them to function either by reference or value
The nested vector's entries are only filled if i is set to 1. But you attempt to access its element [0][0] regardless. You have out of bounds access when i is not 1.

Categories : C++

Parse.com + iOS Avoid simultaneous calls of PFQuery to avoid NSInternalInconsistencyException error crash
To avoid simultaneous calls of a PFQuery, call [query cancel] before findObjects is called: query.cachePolicy = kPFCachePolicyCacheThenNetwork; [query cancel]; //cancels the current network request being made by this query (if any) [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { //do stuff }];

Categories : Iphone

Lua class objects?
There're many ways. This is a simple one. Not really much OOP, you don't have inheritance and some other stuff. But I think this will work in your case. function weaponFire () print "BANG BANG" end function newWeapon (opts) local weaponInstance = {} weaponInstance.name = opts.name weaponInstance.damage = opts.damage weapon.fire = weaponFire return weaponInstance end

Categories : Lua

Best container for C++ class objects
Arraylist equivalent in C++ is the std::vector (they are very close). If you don't know which data structure to use, get std::vector. It's the best practice in C++ (IIRC, Scott Meyers/Bjarne/Sutter(item 76) recommend to use std::vector by default).

Categories : C++

C++ Keep objects of class in array
You can approximate a polymorphic collection using std::vector<std::unique_ptr<Base>> or . std::vector<std::shared_ptr<Base>>. Note that copy semantics of the vector are not good, but you might not do copy on that level at all. If that is needed, the easy way out is to create your own smart pointer and use that as above. The heavier way is to write a real, first-class polymorphic container.

Categories : C++

Use array of objects in another class
This should work. class cmdquest{ public foe foes[] = new foe[100]; public static void main(String args[]) throws Exception{ //Importing foes.txt to create objects of foes java.io.File file = new java.io.File("foes.txt"); Scanner imp = new Scanner(file); for(int i =0; i<3; i++){ foes[i]=foe.leDados(imp); } }

Categories : Java

I need compare objects of the same class
I think you're asking, "How can I determine instanceFoo's class?" but the grammar is hard to decipher. If so, use the instanceof operator. In your case, instanceFoo will be the attribute's parent object: if (instanceFoo instanceof classBar){ //do stuff } Or you can try the getClass() method, which is explained in detail at http://docs.oracle.com/javase/tutorial/reflect/class/classNew.html

Categories : Java

C++ calling objects from another class
You implicitly cannot and should not do what you appear to be trying to do, which is to call the constructor of a class without constructing an instance of the class. If you want the behavior of Parser in Signal, then you have at least three options: 1. Inherit Parser, 2. Add a Parser member, 3. Create a "Parseable" interface-class which Parser can take as an argument. class Parser { public: class Interface { public: std::vector<double> m_data; }; Parser(Interface& interface) { parse(interface); } }; class SignalInheriting : public Parser::Interface { public: SignalInheriting() { Parser p(*this); // can take the Parser::Interface view of this object. } }; class SignalMember { Parser::Interface m_parserIface; public:

Categories : C++

getattr on class objects
Is this good enough? import types class Test(object): @staticmethod def foo(): print 'foo' def bar(self): print 'bar' In combination with: >>>(isinstance(getattr(Test, 'foo'), types.FunctionType), isinstance(getattr(Test, 'bar'), types.FunctionType)) True, False You can also use the inspect module: >>> inspect.isfunction(Test.foo) True >>> inspect.isfunction(Test.bar) False With a little additional work you can even distinguish class methods from instance methods and static methods: import inspect def get_type(cls, attr): try: return [a.kind for a in inspect.classify_class_attrs(cls) if a.name == attr][0] except IndexError: return None class Test(object): @classmethod def foo(cls):

Categories : Python

Load existing class objects in JVM from another JVM
Objects and their references (aliases) are bound to the current running JVM. There is no possibility to share them between several JVMs. If you want to "share" data between two JVMs, you must serialize this data, which means sending them from on JVM to the other. This also requires the classes, whose instances shall be serialized, to implement the interface Serializable. Note, that arrays automatically implement Serializable. You can either stream those serializable objects yourself using sockets, output and input streams (which is much effort) or you can use RMI for calling remote methods and just stream your data. In either case, all objects are copied and built up again in the other JVM. There is no chance to have them shared. In case of application servers, RMI calls are typically i

Categories : Java

Should I have to have duplicate values in VBA class objects?
Have you tried to get or set the msRegion property in your code that is calling the class? If you do you will notice that it is not callable. You are structuring the class correctly. The locals window shows all declared variables, including private varibale within a class.

Categories : Excel

NSSet regroup objects by class
>there are not many subclasses That would make it feasible to have the superclass have an attribute that indicates the subclass. Now grouping with fetched results controller's sectionNameKeyPath is a breeze.

Categories : IOS

Passing class objects by reference
The problem is the line class Entity; This tells the compiler that there is a class Entity at global scope. This class is different from the class Entity you define within the namespace. main() resides in global namespace, and thus uses the forward declaration. However, the line comp.set_parent(entity); tries to pass an object of this global scope class to a function defined within your namespace, which consequently expects an object of the class within that namespace. To fix this, you need to delete the line with the forward declaration and change the instanciation of entity to xe::Entity entity(1 /*id*/); Edit: There was a number of other namespace/scope related problems in the code, the version below compiles without error. I would suggest that take a close look at each error

Categories : C++

Make Counter consider two objects of the same class the same
How about this? Counter(type(x) for x in [Type1(), Type1(), Type2(), Type2()]) This is how you would use it: >>> type_counter = Counter(type(x) for x in [Type1(), Type1(), Type2(), Type2()]) >>> type_counter Counter({<class '__main__.Type2'>: 2, <class '__main__.Type1'>: 2}) >>> type_counter[Type1] 2 >>> type_counter[type(Type2())] 2

Categories : Python

Is it possible to Iterate on objects contained in another class?
If 'B' needs to be accessed (logically) outside of it's class, there's no use making it private. So just make B public but make sure you provide a standard getter and setter instead of addressing the fields directly.

Categories : Java

Exception class for objects of different classes
Implement an interface in the classes you want to use with this exception. The interface has a method to define a message, possible another to provide an attribute. Alternatively, provide an array of attributes and use String.format to build the message. Use that interface to define the object parameter passed in to the exception ctor. Call that method in the exception to get the message. Personally, I find this to be an anti-pattern, unless the classes you want to use with the exception are very tightly related. Otherwise you're giving up semantically-meaningful exception property names. I'd rather see an app-specific superclass with subclasses with semantic meaning.

Categories : Java

List of objects in a parent class
Use some sort of queue void Main() { Events.Queue(new Message(){ Text = "Hit points +5" }); Events.Queue(new Message(){ Text = "Hit points +6" }); Events.Queue(new Message(){ Text = "Hit points +7" }); while(Events.HasNext()) { Console.WriteLine(Events.GetNext().Text); } } public static class Events { private static Queue<Message> messages = new Queue<Message>(); public static void Queue(Message message) { messages.Enqueue(message); } public static Message GetNext() { return messages.Dequeue(); } public static bool HasNext() { return messages.Count > 0; } } public class Message { public string Text {get; set;} } In a more dynamic way, you can use interfaces to build a

Categories : C#



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