I have two object:
@protocol ObjectADelegate
- (void)objectAfirst:(ObjectA *)obj;
- (void)objectAsecond:(ObjectA *)obj;
@end
@interface ObjectA : NSObject {
id<ObjectADelegate> delegate;
- (void)callSecond
{
[self.delegate objectAsecond:self];
}
@end
@interface ObjectB : NSObject <ObjectADelegate>{
ObjectA *myObjectA;
}
@implementation ObjectB
- (void)objectAfirst:(ObjectA *)obj
{
// First is finished, do second
[obj callSecond];
}
- (void)objectASecond:(ObjectA *)obj
{
// Do my stuff
}
@end
As you can see in the code, when ObjectA send the message objectAfirst to its delegate, objectb use again objectA methods that result in objecta calling back objectb.
It means that what first fire objectAfirst is not finished but objectA send the objectAsecond message.
Could it be a problem ?
Any way to let delay message handling in objectB ?
for example, something like using
[obj performSelector:@selector(callSecond) afterDelay:0.01];
instead of
[obj callSecond]; ?
Or if i need to do that, than i should just use shared_ptr?
I know i have many questions regarding smart pointer - i still don't quite understand when to use which smart pointer.
I'm trying to extend my ActiveRecord class with some dynamic methods. I would like to be able to run this from my controller
$user = User::find_by_username(param);
$user = User::find_by_email(param);
I've read a little about overloading and think that's the key. I'v got a static $_attributes in my AR class and I get the table name by pluralizing my model (User = users) in this case.
How do I do this? All models extends the ActiveRecord class.
Consider this function declaration:
int IndexOf(const char *, char);
where char * is a string and char the character to find within the string (returns -1 if the char is not found, otherwise its position). Does it make sense to make the char also const? I always try to use const on pointer parameters but when something is called by value, I normally leave the const away.
What are your thoughts?
I have a bunch of PHP files with classes, in them (although I can't be 100% sure that they won't have code outside of classes in them too), and I need to parse these files to get information about the classes, such as the names of the classes, the methods, the properties, whether they are private/public/static, etc. I looked at PHP's reflection classes and this is very close to what I want but the reflection doesn't seem to use external files and it appears to need to define the classes first. I need to make sure that none of the code is executed and I will be editing the files so I can't guarantee that they will even be error-free.
Any suggestions?
Thanks.
I have a column of states, and, depending on the query, I want to order by results by a particular state, then by id (Asc or Desc, depending). For instance, I might want to show all rows with state "HI", sorted by ID desc, and then all the other rows, sorted by id desc.
I was hoping I could do this in one query, rather than getting all my favored state results, and then getting the rest. Can I?
Consider you have the following class
public class OuterClass {
...
private static class InnerClass {
int foo;
int bar;
}
}
I think I've read somewhere (but not the official Java Tutorial) that if I would declare the static member classes attributes private, the compiler had to generate some sort of accessor methods so that the outer class can actually access the static member class's (which is effectively a package-private top level class) attributes.
Any ideas on that?
I'm reading the gcc manual at the moment, especially the part about warning/error flags. After reading the part about the -Wextra flag, I wonder if it is useful at all. It seems that it complains about things which seem to be rather subjective or a matter of taste. I'm not that experienced with gcc, I only use it from time to time for some small projects at university, so to all experienced C/C++ (or for whatever language you use gcc), what's the deal with -Wextra?
I was wondering if there was a way to make controller methods in rails available only for specific HTTP methods (GET, POST, etc.).
I guess I can create a filter to do that but it seems to me that it is something that is available out-of-the-box in rails.
Is it?
I currently have an array of around 8 - 10 numbers that changes on a periodic basis.
So around every 5 - 10 seconds the numbers get updated.
I need to get the top 3 numbers in the array every 10 seconds.
This is all done on a mobile device.
At the minute I iterate through the array 3 times and each time I take out the three highest numbers and place them in three previously declared variables.
My question is what should I look to do to increase speed and efficiency in this instance?
Consider this piece of code:
public abstract class Validator
{
protected Validator()
{
}
protected abstract void ValidateCore(object instance, string value, IList<ValidationResult> results);
public void Validate(object instance, string value, IList<ValidationResult> results)
{
if (null == instance) throw new ArgumentNullException("instance");
if (null == results) throw new ArgumentNullException("results");
ValidateCore(instance, value, results);
}
}
Look at the Validate() overload, how can an abstract class have definitions like this?
For instance:
private final Object o;
public void doSomething(){
final Object local = this.o;
//access methods of local;
}
This practice is followed in lots of java classes (such as ArrayBlockingQueue). What's the benefit of this?
I'm currently working on an emulation server for a flash-client based game, which has a "pets system", and I was wondering if there was a simpler way of going about checking the level of specified pets.
Current code:
public int Level
{
get
{
if (Expirience 100) // Level 2
{
if (Expirience 200) // Level 3
{
if (Expirience 400) // Level 4 - Unsure of Goal
{
if (Expirience 600) // Level 5 - Unsure of Goal
{
if (Expirience 1000) // Level 6
{
if (Expirience 1300) // Level 7
{
if (Expirience 1800) // Level 8
{
if (Expirience 2400) // Level 9
{
if (Expirience 3200) // Level 10
{
if (Expirience 4300) // Level 11
{
if (Expirience 7200) // Level 12 - Unsure of Goal
{
if (Expirience 8500) // Level 13 - Unsure of Goal
{
if (Expirience 10100) // Level 14
{
if (Expirience 13300) // Level 15
{
if (Expirience 17500) // Level 16
{
if (Expirience 23000) // Level 17
{
return 17; // Bored
}
return 16;
}
return 15;
}
return 14;
}
return 13;
}
return 12;
}
return 11;
}
return 10;
}
return 9;
}
return 8;
}
return 7;
}
return 6;
}
return 5;
}
return 4;
}
return 3;
}
return 2;
}
return 1;
}
}
Yes, I'm aware I've misspelt Experience, I had made the mistake in a previous function and hadn't gotten around to updating everything... :P
i can not see MyLoad.TreeLoader(.... but why i can not see?
i implemented iloader to TreeViewLoad. i should see TreeLoader why?
namespace Rekursive
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//treeView1.Nodes.Add("Test");
iloader MyLoad = new TreeViewLoad();
MyLoad.loader("test", treeView1, 1);
// i can not see MyLoad.TreeLoader(.... but why i can not see?
// i implemented iloader to TreeViewLoad. i should see TreeLoader why?
//TreeViewLoad myloader = new TreeViewLoad();
}
}
interface iloader
{
void loader(string nodeName, TreeView myTre, int id);
}
class TreeViewLoad : iloader
{
public void TreeLoader(TreeView tre)
{
// i will call loader...
}
public void loader(string nodeName, TreeView myTre, int id)
{
myTre.Nodes.Add(nodeName + id.ToString());
if (id
Hey guys,
I'm learning myself to go from function based PHP coding to OOP. And this is the situation:
ClassA holds many basic tool methods (functions). it's __construct makes a DB connection.
ClassB holds specific methods based on a certain activity (extract widgets). ClassB extends ClassA because it uses some of the basic tools in there e.g. a database call.
In a php file I create a $a_class = new ClassA object (thus a new DB connection).
Now I need a method in ClassB. I do $b_class = new ClassB; and call a method, which uses a method from it's parent:: ClassA.
In this example, i'm having ClassA 'used' twice. Onces as object, and onces via a parent:: call, so ClassA creates another DB connection (or not?).
So what is the best setup for this basic classes parent, child (extend) situation? I only want to make one connection of course?
I don't like to forward the object to ClassB like this $b_class = new ClassB($a_object); or is that the best way?
Thanks for thinking with me, and helping :d
Is it possible to use the class methods of some NSObject I've made to controls all existing instances?
I want a delegate class to be able to send messages to the Object's class methods which can then react appropriately with everything out there.
I'm trying to enable a button but the button that I would enable in this function changes. I have an array of the buttons but when I use the .enabled on the array index I want it says that this doesn't work for IDs.
I have used this array to set the text of each button before using:
[[ButtonArray objectAtIndex: Index] setTitle:(@"blahblahblah") forState: UIControlStateNormal];
is there any way to use a similar function call to enable and disable?
I have the following code, which just print the key/value pairs in a dict (the pairs are sorted by keys):
for word, count in sorted(count_words(filename).items()):
print word, count
However, calling iteritems() instead of items() produces the same output
for word, count in sorted(count_words(filename).iteritems()):
print word, count
Now, which one should I choose in this situation? I consulted the Python tutorial but it doesn't really answer my question.
I would like to know
K-means is best suited for clustering of which type of data?
When k-means fails? for which type of data set k-means does not give accurate answer?
COBWEB is best suited for clustering of which type of data?
When COBWEB fails? for which type of data set COBWEB does not give accurate answer?