3 * Copyright 2006,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <gruel/pmt.h>
33 pmt_write_list_tail(pmt_t obj, std::ostream &port)
35 pmt_write(pmt_car(obj), port); // write the car
36 obj = pmt_cdr(obj); // step to cdr
38 if (pmt_is_null(obj)) // ()
41 else if (pmt_is_pair(obj)){ // normal list
43 pmt_write_list_tail(obj, port);
53 pmt_write(pmt_t obj, std::ostream &port)
55 if (pmt_is_bool(obj)){
61 else if (pmt_is_symbol(obj)){
62 port << pmt_symbol_to_string(obj);
64 else if (pmt_is_number(obj)){
65 if (pmt_is_integer(obj))
66 port << pmt_to_long(obj);
67 else if (pmt_is_uint64(obj))
68 port << pmt_to_uint64(obj);
69 else if (pmt_is_real(obj))
70 port << pmt_to_double(obj);
71 else if (pmt_is_complex(obj)){
72 std::complex<double> c = pmt_to_complex(obj);
73 port << c.real() << '+' << c.imag() << 'i';
78 else if (pmt_is_null(obj)){
81 else if (pmt_is_pair(obj)){
83 pmt_write_list_tail(obj, port);
85 else if (pmt_is_tuple(obj)){
87 size_t len = pmt_length(obj);
89 port << pmt_tuple_ref(obj, 0);
90 for (size_t i = 1; i < len; i++)
91 port << " " << pmt_tuple_ref(obj, i);
95 else if (pmt_is_vector(obj)){
97 size_t len = pmt_length(obj);
99 port << pmt_vector_ref(obj, 0);
100 for (size_t i = 1; i < len; i++)
101 port << " " << pmt_vector_ref(obj, i);
105 else if (pmt_is_dict(obj)){
107 // port << "#<dict " << obj << ">";
110 else if (pmt_is_uniform_vector(obj)){
112 // port << "#<uniform-vector " << obj << ">";
113 port << "#<uniform-vector>";
118 // port << "#<" << obj << ">";
119 port << "#<unknown>";
123 std::ostream& operator<<(std::ostream &os, pmt_t obj)
130 pmt_write_string(pmt_t obj)
132 std::ostringstream s;
138 pmt_read(std::istream &port)
140 throw pmt_notimplemented("notimplemented: pmt_read", PMT_NIL);
144 pmt_serialize(pmt_t obj, std::ostream &sink)
146 throw pmt_notimplemented("notimplemented: pmt_serialize", obj);
150 * \brief Create obj from portable byte-serial representation
153 pmt_deserialize(std::istream &source)
155 throw pmt_notimplemented("notimplemented: pmt_deserialize", PMT_NIL);
158 } /* namespace pmt */