ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Warning.c
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include <assert.h>
25
26#include "Warning.h"
27
28#define _Class _Warning
29
30#pragma mark - Object
31
35static void dealloc(Object *self) {
36
37 Warning *this = (Warning *) self;
38
39 release(this->message);
40
41 super(Object, self, dealloc);
42}
43
44#pragma mark - Warning
45
50static Warning *initWithFormat(Warning *self, WarningType type, const char *fmt, ...) {
51
52 va_list args;
53 va_start(args, fmt);
54
55 self = $(self, initWithVaList, type, fmt, args);
56
57 va_end(args);
58
59 return self;
60}
61
66static Warning *initWithVaList(Warning *self, WarningType type, const char *fmt, va_list args) {
67
68 self = (Warning *) super(Object, self, init);
69 if (self) {
70 self->type = type;
71 assert(self->type);
72
73 self->message = $(alloc(String), initWithVaList, fmt, args);
74 assert(self->message);
75 }
76
77 return self;
78}
79
80#pragma mark - Class lifecycle
81
85static void initialize(Class *clazz) {
86
87 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
88
89 ((WarningInterface *) clazz->interface)->initWithFormat = initWithFormat;
90 ((WarningInterface *) clazz->interface)->initWithVaList = initWithVaList;
91}
92
97Class *_Warning(void) {
98 static Class *clazz;
99 static Once once;
100
101 do_once(&once, {
102 clazz = _initialize(&(const ClassDef) {
103 .name = "Warning",
104 .superclass = _Object(),
105 .instanceSize = sizeof(Warning),
106 .interfaceOffset = offsetof(Warning, interface),
107 .interfaceSize = sizeof(WarningInterface),
109 });
110 });
111
112 return clazz;
113}
114
115#undef _Class
static View * init(View *self)
Definition Box.c:67
static Warning * initWithFormat(Warning *self, WarningType type, const char *fmt,...)
Definition Warning.c:50
static Warning * initWithVaList(Warning *self, WarningType type, const char *fmt, va_list args)
Definition Warning.c:66
static void dealloc(Object *self)
Definition Warning.c:35
static void initialize(Class *clazz)
Definition Warning.c:85
Class * _Warning(void)
Definition Warning.c:97
Warnings are accumulated on Views so that they may be reported by the DebugViewController.
WarningType
Warning types.
Definition Warning.h:33
The Warning type.
Definition Warning.h:50
String * message
The message.
Definition Warning.h:71
Warning * initWithVaList(Warning *self, WarningType type, const char *fmt, va_list args)
Initializes this Warning with the given type and format string.
Definition Warning.c:66
Warning * initWithFormat(Warning *self, WarningType type, const char *fmt,...)
Initializes this Warning with the given type and format string.
Definition Warning.c:50
WarningType type
The WarningType.
Definition Warning.h:66