Storing structured data in file - any easy way?

2008-07-10 Thread Jules Colding

Hi,

I'm trying to figure out how to write and read structured data to a  
specific file. I have a very bad feeling that the answer is Core Data,  
but I'm feeling totally at lost after having been reading up on Core  
Data for a couple of days by now.


This is what I would like to do:

1) I want to store several top-level objects.

2) A top-level object have a few optional attributes.

3) Each top-level object have two-way relationships to sub-objects.

4) Sub-objects has also a few optional attributes.

5) A top-level object may contain many sub-objects.


Obviously I would like to read and write to the data file as well as  
create and delete objects within. There must be a simple way to do  
this but I just can't figure out how...



Thanks a lot in advance,
  jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-10 Thread Jules Colding


On 10/07/2008, at 15.18, Graham Cox wrote:

Sounds like you want to do archiving - it can handle all the object  
relationships you mention. Check out NSKeyedArchiver and the  
NSCoding protocol.


http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Concepts/archives.html


Thanks a lot. I'll take a look.

Best regards,
  jules




On 10 Jul 2008, at 11:09 pm, Jules Colding wrote:


Hi,

I'm trying to figure out how to write and read structured data to a  
specific file. I have a very bad feeling that the answer is Core  
Data, but I'm feeling totally at lost after having been reading up  
on Core Data for a couple of days by now.


This is what I would like to do:

1) I want to store several top-level objects.

2) A top-level object have a few optional attributes.

3) Each top-level object have two-way relationships to sub-objects.

4) Sub-objects has also a few optional attributes.

5) A top-level object may contain many sub-objects.


Obviously I would like to read and write to the data file as well  
as create and delete objects within. There must be a simple way to  
do this but I just can't figure out how...



Thanks a lot in advance,
jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/graham.cox%40bigpond.com

This email sent to [EMAIL PROTECTED]




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-10 Thread Jules Colding

Hi Graham,

On 10/07/2008, at 15.18, Graham Cox wrote:

Sounds like you want to do archiving - it can handle all the object  
relationships you mention. Check out NSKeyedArchiver and the  
NSCoding protocol.


http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Concepts/archives.html


OK, this is just what the doctor ordered. But, I'd like an advise  
please :-)


I want to store a rather large list of short string pairs and I want  
to be able to be able to use both strings, in a given pair, as the  
key. An example:


Assume that I want to store the set {"HI", "HELLO"}. At one point I  
want to be able to use "HI" as key and get "HELLO". At another point I  
want to use "HELLO" as key and get "HI".


There are several trivial ways to do this. I could use two  
NSDictionary's and use the NSCopying protocol to store both.  
Unfortunately that will make at least one, possibly both, dictionaries  
present in memory at query time.


Another approach would be to make 2 files for each string pair: One  
file named "HI" with the content "HELLO" and another with the name  
"HELLO" and the content "HI". Unfortunately that will make a mess of  
the filesystem, but at least it will be rather quick to get a value  
for a given key.


The best solution seems to be some kind of lightweight database... Is  
there any cocoa framework that implements a simple database or should  
I manually seek through a file?


Thanks,
  jules






hth,

Graham


On 10 Jul 2008, at 11:09 pm, Jules Colding wrote:


Hi,

I'm trying to figure out how to write and read structured data to a  
specific file. I have a very bad feeling that the answer is Core  
Data, but I'm feeling totally at lost after having been reading up  
on Core Data for a couple of days by now.


This is what I would like to do:

1) I want to store several top-level objects.

2) A top-level object have a few optional attributes.

3) Each top-level object have two-way relationships to sub-objects.

4) Sub-objects has also a few optional attributes.

5) A top-level object may contain many sub-objects.


Obviously I would like to read and write to the data file as well  
as create and delete objects within. There must be a simple way to  
do this but I just can't figure out how...



Thanks a lot in advance,
jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/graham.cox%40bigpond.com

This email sent to [EMAIL PROTECTED]




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-10 Thread Jules Colding

Hi again,

On 10/07/2008, at 20.29, Jules Colding wrote:


On 10/07/2008, at 15.18, Graham Cox wrote:

Sounds like you want to do archiving - it can handle all the object  
relationships you mention. Check out NSKeyedArchiver and the  
NSCoding protocol.


http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Concepts/archives.html


OK, this is just what the doctor ordered. But, I'd like an advise  
please :-)







I want to store a rather large list of short string pairs and I want  
to be able to be able to use both strings, in a given pair, as the  
key. An example:


The best solution seems to be some kind of lightweight database...



sqlite3 it is.

Best regards,
  jules




Is there any cocoa framework that implements a simple database or  
should I manually seek through a file?


Thanks,
 jules






hth,

Graham


On 10 Jul 2008, at 11:09 pm, Jules Colding wrote:


Hi,

I'm trying to figure out how to write and read structured data to  
a specific file. I have a very bad feeling that the answer is Core  
Data, but I'm feeling totally at lost after having been reading up  
on Core Data for a couple of days by now.


This is what I would like to do:

1) I want to store several top-level objects.

2) A top-level object have a few optional attributes.

3) Each top-level object have two-way relationships to sub-objects.

4) Sub-objects has also a few optional attributes.

5) A top-level object may contain many sub-objects.


Obviously I would like to read and write to the data file as well  
as create and delete objects within. There must be a simple way to  
do this but I just can't figure out how...



Thanks a lot in advance,
jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/graham.cox%40bigpond.com

This email sent to [EMAIL PROTECTED]






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-11 Thread Jules Colding


On 11/07/2008, at 01.28, Chris Hanson wrote:


On Jul 10, 2008, at 6:09 AM, Jules Colding wrote:

I'm trying to figure out how to write and read structured data to a  
specific file. I have a very bad feeling that the answer is Core  
Data, but I'm feeling totally at lost after having been reading up  
on Core Data for a couple of days by now.


That's what Core Data is for, yes.


This is what I would like to do:

1) I want to store several top-level objects.

2) A top-level object have a few optional attributes.

3) Each top-level object have two-way relationships to sub-objects.

4) Sub-objects has also a few optional attributes.

5) A top-level object may contain many sub-objects.


Obviously I would like to read and write to the data file as well  
as create and delete objects within. There must be a simple way to  
do this but I just can't figure out how...


Out of curiosity, what do you find not simple about doing the above  
using Core Data?



It is easy enough to create the data model using xcode, but how that  
connects to actual code is harder to see.


Maybe I'm just overwhelmed... I've had to learn about Sync Services,  
Cocoa, xcode, the Foundation framework and not to forget Objective-C,  
from scratch in just the last month or so. I'm new to the entire Mac  
development environment (I'm coming from linux) so you can imagine  
that my head is rather busy digesting it all. Anyway, I must say that  
I find it the best thought-out development environment that I've ever  
had the pleasure to work within.



Best regards,
  jules
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-11 Thread Jules Colding

Hi Jens,

On 10/07/2008, at 22.50, Jens Alfke wrote:



On 10 Jul '08, at 11:29 AM, Jules Colding wrote:

Assume that I want to store the set {"HI", "HELLO"}. At one point I  
want to be able to use "HI" as key and get "HELLO". At another  
point I want to use "HELLO" as key and get "HI".


There are several trivial ways to do this. I could use two  
NSDictionary's and use the NSCopying protocol to store both.  
Unfortunately that will make at least one, possibly both,  
dictionaries present in memory at query time.


You mean NSCoding, not NSCopying, right?


oops, yes.


The overhead for two dictionaries as opposed to one shouldn't be too  
high. Hash-table overhead is something like 4*sizeof(void*) bytes  
times the number of keys. It's the strings themselves that will take  
up most of the memory, and those are shared between dictionaries.


On the other hand, if the overhead of even one copy of the data in  
memory is too high, archiving isn't the way to go.


The best solution seems to be some kind of lightweight database...  
Is there any cocoa framework that implements a simple database or  
should I manually seek through a file?


The typical solution for this is SQLite,


Exactly what I've decided.

Thanks,
  jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing structured data in file - any easy way?

2008-07-12 Thread Jules Colding

Hi,

On 12/07/2008, at 02.22, Ben Trumbull wrote:

At 12:39 AM -0700 7/11/08, [EMAIL PROTECTED] wrote:

> Out of curiosity, what do you find not simple about doing the above

using Core Data?


It is easy enough to create the data model using xcode, but how  
that connects to actual code is harder to see.


Maybe I'm just overwhelmed... I've had to learn about Sync  
Services, Cocoa, xcode, the Foundation framework and not to forget  
Objective-C, from scratch in just the last month or so. I'm new to  
the entire Mac development environment (I'm coming from linux) so  
you can imagine that my head is rather busy digesting it all.  
Anyway, I must say that I find it the best thought-out development  
environment that I've ever had the pleasure to work within.


Once you've gotten the Cocoa memory management, and Key Value Coding  
concepts down, it's straight forward.  The low level Core Data  
tutorial is pretty good for showing how the pieces fit together with  
the code.





Additionally, here's a cmd line example that assumes you've created  
a model named 'WordModel' with an entity 'Word' that has an  
attribute named 'text'.  Of course, it would also require you save  
some data for it to be useful.  But it shows how to set up a stack  
and fetch data.



Thanks a lot Ben! This sample puts code to the bones so to speak ;-)

Best regards,
  jules




#import 
#include 

int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   NSError *error = nil;
   // Create a Core Data stack
   NSManagedObjectModel* model = [[NSManagedObjectModel alloc]  
initWithContentsOfURL:[NSURL fileURLWithPath:@"WordModel.mom"]];
   NSPersistentStoreCoordinator *coordinator =  
[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:  
model];

   [model release];
   NSManagedObjectContext* context = [[NSManagedObjectContext alloc]  
init];

   [context setPersistentStoreCoordinator: coordinator];
   [context setUndoManager:nil];
   [coordinator release];
   NSURL *dburl = [NSURL fileURLWithPath: [NSString  
stringWithUTF8String:argv[argc-1]]];

   NSDictionary* opts = nil;
   id store;
   if (nil == (store = [coordinator addPersistentStoreWithType:  
NSSQLiteStoreType configuration: nil URL: dburl options: opts error:  
&error])) {
   NSLog(@"Could not access database file.  NSError = %@ ui =  
%@", error, [error userInfo]);

   exit(-1);
   }

   // Create a fetch request
   NSFetchRequest* request = [[[NSFetchRequest alloc] init]  
autorelease];
   [request setEntity:[NSEntityDescription entityForName:@"Word"  
inManagedObjectContext:context]];


   // Perform the fetch
   NSArray* results = [context executeFetchRequest:request  
error:&error];


   if (nil == results) {
   NSLog(@"Error during fetch = %@ with userInfo = %@", error,  
[error userInfo]);

   exit(-1);
   }

   unsigned long count = [results count];
  NSString* text;
   for (NSManagedObject* word in results) {
   text = word.text;
   }

   [context release];
   [pool drain];
   return 0;
}

--

-Ben


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


How do I register a cocoa bundle identifier?

2008-08-20 Thread Jules Colding

Hi,

I have this cocoa bundle which contains an executable (a shell tool)  
in the "Contents/MacOS" directory. I would like to register to bundle  
so that I can execute the contained program with "open -b com. 
42tools.julia.backend" from the terminal.


I've tried using LSRegisterFSRef() with various paths in the FSRef -  
the executablePath, the bundlePath and the path of the "Info.plist"  
file as below:


static void
register_bundle(void)
{
FSRef fsref;
OSStatus oss;
NSBundle *bundle = [NSBundle mainBundle];
	NSString *plist = [NSString stringWithFormat:@"%@/Contents/ 
Info.plist", [bundle bundlePath]];


oss = FSPathMakeRef([plist UTF8String], &fsref, NULL);
NSLog(@"FSPathMakeRef = %d", oss);

oss = LSRegisterFSRef(&fsref, true);
NSLog(@"LSRegisterFSRef = %d", oss);
}

LSRegisterFSRef() returns "-10811" ("kLSNotAnApplicationErr") for all  
of them. Is there a way to do what I want?


Thanks a lot in advance,
  jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: !foo vs foo == nil

2008-08-21 Thread Jules Colding


On 21/08/2008, at 01.56, John C. Randolph wrote:



On Aug 20, 2008, at 4:15 PM, Torsten Curdt wrote:


There was a common perception that NULL is not really the same as  
nil. But seems like in the end it really is (void*)0.



They differ in type, not in value.

"NULL" is (void *) 0.
"nil" is (id) 0.
"Nil" is (Class) 0.

Personally, I prefer "if (!foo)" over "if (foo == nil)", because the  
latter has the hazard of a typo that compiles.  You can lose a fair  
bit of time staring at "if (foo = nil)" before you spot the mistake.


Which is why you should always write "if (nil == foo)".

--
  jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: !foo vs foo == nil

2008-08-21 Thread Jules Colding


On 21/08/2008, at 09.21, Thomas Davie wrote:



On 21 Aug 2008, at 09:06, Jules Colding wrote:



On 21/08/2008, at 01.56, John C. Randolph wrote:



On Aug 20, 2008, at 4:15 PM, Torsten Curdt wrote:


There was a common perception that NULL is not really the same as  
nil. But seems like in the end it really is (void*)0.



They differ in type, not in value.

"NULL" is (void *) 0.
"nil" is (id) 0.
"Nil" is (Class) 0.

Personally, I prefer "if (!foo)" over "if (foo == nil)", because  
the latter has the hazard of a typo that compiles.  You can lose a  
fair bit of time staring at "if (foo = nil)" before you spot the  
mistake.


Which is why you should always write "if (nil == foo)".


Just to add my 2 cents to this discussion, I think there's something  
which hasn't been brought up (and I guess isn't often brought up by  
C programmers).


One of the two options doesn't make sense here.
Because of C's weak type system ! works on almost anything you throw  
at it.  However, it is a *boolean* operator.  Boolean negating a  
pointer is a hack that by happy coincidence works.  On the other  
hand, nil == foo is type safe, and makes semantic sense.


For that simple reason, I'd go for nil == foo every time.


Yes, and in general you should always do "if (CONSTANT == foo)" to  
catch the potential "if (CONSTANT = foo)" error.


Best regards,
  jules

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: !foo vs foo == nil

2008-08-22 Thread Jules Colding

On 22/08/2008, at 00.38, Andy Lee wrote:


On Aug 21, 2008, at 3:42 PM, Jim Correia wrote:

On Aug 21, 2008, at 3:54 AM, Jules Colding wrote:


For that simple reason, I'd go for nil == foo every time.


Yes, and in general you should always do "if (CONSTANT == foo)" to  
catch the potential "if (CONSTANT = foo)" error.


If your name is Yoda, then perhaps if (3 != x) reads naturally to  
you. :-)


Actually it does even though my name isn't Yoda ;-)

Anyway, it is a matter of personal taste what style you choose. I just  
happen to prefer to put the constant first. An old habit I guess...


Best regards,
  jules






As in most things, I think it is critical to strike a balance  
between code readability/skim-ability and other considerations.


I keep changing my mind about this, so my code is inconsistent about  
it, but I've basically come to the same conclusion.  One thing I've  
noticed is that I rarely get a bug due to misreading a boolean  
expression.  More often I'm looking right at it (even if it's as  
unmistakeable as "nil == obj") and I do the wrong thing anyway.   
Like I'll get the if-block and the else-block mixed up.  It's like  
some kind of boolean-dyslexia in my brain.


I find it helps to comment my logic.

--Andy


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSDate autorelease problem

2008-09-03 Thread Jules Colding


On 03/09/2008, at 19.02, [EMAIL PROTECTED] wrote:


Hi,

I'm trying to calculate the elapsed time by calling this twice and  
getting the difference.


double Seconds()
{
  return [[NSDate date] timeIntervalSince1970];
}


There is no need to use cocoa for everything. Use gettimeofday()  
instead.


HTH,
  jules


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Start traces with CrashReporter

2009-01-23 Thread Jules Colding

Hi,

Is there any way to make CrashReporter show stack frame content and  
line numbers instead of signatures and offsets? Maybe a way to make  
gdb automatically attach to crashing processes and do a "t a a bt f"  
on them?


Thanks,
  jules

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Start traces with CrashReporter

2009-01-23 Thread Jules Colding


On 23/01/2009, at 20.33, Jean-Daniel Dupas wrote:


OK, this does not contains as much info as you want.

depending your need, you may activate core dump generation. So you  
will be able to launch gdb on the dump to retreive the info you need.


http://developer.apple.com/technotes/tn2004/tn2124.html#SECCOREDUMPS


Yes, that is my thought too. Now I just have to wait for a crash ;-)

Thanks,
  jules

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com