qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, filip.navara@gmail.com, avi@redhat.com
Subject: [Qemu-devel] [PATCH 3/3] Introduce QNumber data type
Date: Thu,  6 Aug 2009 10:52:16 -0300	[thread overview]
Message-ID: <1249566736-5020-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1249566736-5020-1-git-send-email-lcapitulino@redhat.com>

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile  |    2 +-
 qnumber.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qnumber.h |   20 +++++++++++
 qobject.h |    1 +
 4 files changed, 130 insertions(+), 1 deletions(-)
 create mode 100644 qnumber.c
 create mode 100644 qnumber.h

diff --git a/Makefile b/Makefile
index 9e3faec..c4cbbaf 100644
--- a/Makefile
+++ b/Makefile
@@ -104,7 +104,7 @@ obj-y += buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o
 obj-y += qemu-char.o aio.o net-checksum.o savevm.o
 obj-y += msmouse.o ps2.o
 obj-y += qdev.o qdev-properties.o ssi.o
-obj-y += qdict.o qstring.o
+obj-y += qdict.o qstring.o qnumber.o
 
 obj-$(CONFIG_BRLAPI) += baum.o
 
diff --git a/qnumber.c b/qnumber.c
new file mode 100644
index 0000000..cd30150
--- /dev/null
+++ b/qnumber.c
@@ -0,0 +1,108 @@
+/*
+ * QNumber data type.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ *  Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+#include "qobject.h"
+#include "qnumber.h"
+#include "qemu-common.h"
+
+static QType qnumber_type;
+
+
+/**
+ * qnumber_alloc(): Allocate a new QNumber
+ */
+static QNumber *qnumber_alloc(void)
+{
+    QNumber *qnum;
+
+    qnum = qemu_mallocz(sizeof(*qnum));
+    qnum->base.type = &qnumber_type;
+
+    return qnum;
+}
+
+/**
+ * qnumber_from_int(): Create a new QNumber from an int
+ *
+ * return new QNumber.
+ */
+QNumber *qnumber_from_int(int value)
+{
+    QNumber *qnum;
+
+    qnum = qnumber_alloc();
+    qnum->number.n_int = value;
+
+    return qnum;
+}
+
+/**
+ * qnumber_from_int64(): Create a new QNumber from an int64_t
+ *
+ * return new QNumber.
+ */
+QNumber *qnumber_from_int64(int64_t value)
+{
+    QNumber *qnum;
+
+    qnum = qnumber_alloc();
+    qnum->number.n_int64 = value;
+
+    return qnum;
+}
+
+/**
+ * qnumber_destroy(): Free all memory allocated by a QNumber
+ * object
+ */
+void qnumber_destroy(QNumber *qnum)
+{
+    qemu_free(qnum);
+}
+
+/**
+ * qnumber_to_int(): Export QNumber to int type
+ */
+int qnumber_to_int(const QNumber *qnum)
+{
+    return qnum->number.n_int;
+}
+
+/**
+ * qnumber_destroy_obj(): Destroy a QNumber object
+ */
+static void qnumber_destroy_obj(QObject *obj)
+{
+    QNumber *qnum = container_of(obj, QNumber, base);
+    qnumber_destroy(qnum);
+}
+
+/**
+ * qnumber_clone_obj(): Clone a QNumber object
+ *
+ * return a copy of the provided QNumber object.
+ */
+static QObject *qnumber_clone_obj(const QObject *obj)
+{
+    QNumber *old, *new;
+
+    new = qemu_malloc(sizeof(*new));
+    old = container_of(obj, QNumber, base);
+    memcpy(new, old, sizeof(*new));
+
+    return &new->base;
+}
+
+static QType qnumber_type = {
+    .code = QTYPE_QNUMBER,
+    .clone = qnumber_clone_obj,
+    .destroy = qnumber_destroy_obj,
+};
diff --git a/qnumber.h b/qnumber.h
new file mode 100644
index 0000000..918637d
--- /dev/null
+++ b/qnumber.h
@@ -0,0 +1,20 @@
+#ifndef QNUMBER_H
+#define QNUMBER_H
+
+#include "qobject.h"
+#include <stdint.h>
+
+typedef struct QNumber {
+    QObject base;
+    union {
+        int n_int;
+        int64_t n_int64;
+    } number;
+} QNumber;
+
+QNumber *qnumber_from_int(int value);
+QNumber *qnumber_from_int64(int64_t value);
+void qnumber_destroy(QNumber *qnum);
+int qnumber_to_int(const QNumber *qnum);
+
+#endif /* QNUMBER_H */
diff --git a/qobject.h b/qobject.h
index d3378b1..20b9a99 100644
--- a/qobject.h
+++ b/qobject.h
@@ -17,6 +17,7 @@
 typedef enum {
     QTYPE_NONE,
     QTYPE_QSTRING,
+    QTYPE_QNUMBER,
 } qtype_t;
 
 struct QObject;
-- 
1.6.4.rc3.12.gdf73a

  parent reply	other threads:[~2009-08-06 13:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-06 13:52 [Qemu-devel] [PATCH RFC 0/3] QEMU Object Model Luiz Capitulino
2009-08-06 13:52 ` [Qemu-devel] [PATCH 1/3] Introduce qobject header file Luiz Capitulino
2009-08-06 14:02   ` [Qemu-devel] " Avi Kivity
2009-08-06 14:07     ` Luiz Capitulino
2009-08-06 15:54   ` [Qemu-devel] " malc
2009-08-06 13:52 ` [Qemu-devel] [PATCH 2/3] Introduce QString data type Luiz Capitulino
2009-08-06 13:52 ` Luiz Capitulino [this message]
2009-08-06 14:04   ` [Qemu-devel] Re: [PATCH 3/3] Introduce QNumber " Avi Kivity
2009-08-06 14:05     ` François Revol
2009-08-06 14:48       ` Avi Kivity
2009-08-06 14:10     ` Luiz Capitulino
2009-08-06 21:21     ` Luiz Capitulino
2009-08-06 14:06 ` [Qemu-devel] Re: [PATCH RFC 0/3] QEMU Object Model Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1249566736-5020-4-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=filip.navara@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).