~ubuntu-branches/ubuntu/lucid/gauche-c-wrapper/lucid

« back to all changes in this revision

Viewing changes to src/ObjCError.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2008-04-07 09:15:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080407091503-wu0h414koe95kj4i
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  ObjCError.m
 
3
 *  
 
4
 *   Copyright (c) 2006 KOGURO, Naoki (naoki@koguro.net)
 
5
 *  
 
6
 *   Permission is hereby granted, free of charge, to any person 
 
7
 *   obtaining a copy of this software and associated 
 
8
 *   documentation files (the "Software"), to deal in the 
 
9
 *   Software without restriction, including without limitation 
 
10
 *   the rights to use, copy, modify, merge, publish, distribute, 
 
11
 *   sublicense, and/or sell copies of the Software, and to 
 
12
 *   permit persons to whom the Software is furnished to do so, 
 
13
 *   subject to the following conditions:
 
14
 *  
 
15
 *   The above copyright notice and this permission notice shall 
 
16
 *   be included in all copies or substantial portions of the 
 
17
 *   Software.
 
18
 *  
 
19
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
 
20
 *   KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 
21
 *   WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 
22
 *   PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 
 
23
 *   OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
 
24
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 
25
 *   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 
26
 *   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
 *  
 
28
 *   $Id: ffi.c 233 2006-05-03 15:58:37Z naoki $
 
29
 */
 
30
 
 
31
#include <gauche.h>
 
32
#include <gauche/class.h>
 
33
#include <gauche/exception.h>
 
34
 
 
35
#import "ObjCError.h"
 
36
 
 
37
static ScmObj objc_error_allocate(ScmClass *klass, ScmObj initargs);
 
38
static void objc_error_print(ScmObj objc_error, ScmPort *port, ScmWriteContext *ctx);
 
39
 
 
40
static ScmClass *default_cpl[] = {
 
41
    SCM_CLASS_STATIC_PTR(Scm_TopClass), NULL
 
42
};
 
43
 
 
44
SCM_DEFINE_BASE_CLASS(Scm_ObjCErrorClass, ScmObjCError,
 
45
                      objc_error_print, NULL, NULL, objc_error_allocate,
 
46
                      default_cpl);
 
47
 
 
48
static ScmObj objc_error_allocate(ScmClass *klass, ScmObj initargs)
 
49
{
 
50
    ScmObjCError *err = SCM_ALLOCATE(ScmObjCError, klass);
 
51
    SCM_SET_CLASS(err, klass);
 
52
    err->name = SCM_FALSE;
 
53
    err->reason = SCM_FALSE;
 
54
 
 
55
    SCM_RETURN(SCM_OBJ(err));
 
56
}
 
57
 
 
58
static void objc_error_print(ScmObj obj, ScmPort *port, ScmWriteContext *ctx)
 
59
{
 
60
    Scm_Printf(port, "#<objc-error %A (%A)>"
 
61
               , SCM_OBJC_ERROR(obj)->name, SCM_OBJC_ERROR(obj)->reason);
 
62
}
 
63
 
 
64
static ScmObj objc_error_name_get(ScmObjCError *err)
 
65
{
 
66
    SCM_RETURN(err->name);
 
67
}
 
68
 
 
69
static ScmObj objc_error_reason_get(ScmObjCError *err)
 
70
{
 
71
    SCM_RETURN(err->reason);
 
72
}
 
73
 
 
74
static ScmClassStaticSlotSpec objc_error_slots[] = {
 
75
    SCM_CLASS_SLOT_SPEC("name", objc_error_name_get, NULL),
 
76
    SCM_CLASS_SLOT_SPEC("reason", objc_error_reason_get, NULL),
 
77
    { NULL }
 
78
};
 
79
 
 
80
ScmObj Scm_MakeObjCError(ScmObj name, ScmObj reason)
 
81
{
 
82
    ScmObj e = objc_error_allocate(SCM_CLASS_OBJC_ERROR, SCM_NIL);
 
83
    SCM_OBJC_ERROR(e)->name = name;
 
84
    SCM_OBJC_ERROR(e)->reason = reason;
 
85
 
 
86
    SCM_RETURN(e);
 
87
}
 
88
 
 
89
void Scm_Init_ObjCError(ScmModule *mod)
 
90
{
 
91
    Scm_InitStaticClass(&Scm_ObjCErrorClass, "<objc-error>", mod, objc_error_slots, 0);
 
92
}
 
93