18 int cmp (
const char *ostring)
const
20 if (cstring && ostring)
21 return strcmp (cstring, ostring);
25 return ostring ? SFI_MININT : 0;
30 cstring = g_strdup (
"");
34 cstring = g_strdup (s.cstring);
38 cstring = g_strdup (s.
c_str());
42 cstring = g_strdup (cstr ? cstr :
"");
48 cstring = g_strdup (s.
c_str());
56 cstring = g_strdup (cstr ? cstr :
"");
62 if (s.cstring != cstring)
65 cstring = g_strdup (s.cstring);
69 const char* c_str()
const
76 cstring = g_strconcat (old ? old :
"", cstr, NULL);
83 cstring = g_strconcat (old ? old :
"", src.cstring, NULL);
90 cstring = g_strconcat (old ? old :
"", src.
c_str(), NULL);
106 bool operator< (
const char *src)
const {
return cmp (src) < 0; }
107 bool operator<= (
const char *src)
const {
return cmp (src) <= 0; }
108 bool operator> (
const char *src)
const {
return cmp (src) > 0; }
109 bool operator>= (
const char *src)
const {
return cmp (src) >= 0; }
110 bool operator!= (
const char *src)
const {
return cmp (src) != 0; }
111 bool operator== (
const char *src)
const {
return cmp (src) == 0; }
112 bool operator< (
const SfiString &s)
const {
return cmp (s.cstring) < 0; }
113 bool operator<= (
const SfiString &s)
const {
return cmp (s.cstring) <= 0; }
114 bool operator> (
const SfiString &s)
const {
return cmp (s.cstring) > 0; }
115 bool operator>= (
const SfiString &s)
const {
return cmp (s.cstring) >= 0; }
116 bool operator!= (
const SfiString &s)
const {
return cmp (s.cstring) != 0; }
117 bool operator== (
const SfiString &s)
const {
return cmp (s.cstring) == 0; }
119 bool operator<= (
const std::string &s)
const {
return cmp (s.
c_str()) <= 0; }
121 bool operator>= (
const std::string &s)
const {
return cmp (s.
c_str()) >= 0; }
122 bool operator!= (
const std::string &s)
const {
return cmp (s.
c_str()) != 0; }
123 bool operator== (
const std::string &s)
const {
return cmp (s.
c_str()) == 0; }
124 unsigned int length()
126 return cstring ?
strlen (cstring) : 0;
133 static SfiString value_get_string (
const GValue *value)
135 return sfi_value_get_string (value);
137 static void value_set_string (GValue *value,
const SfiString& str)
139 sfi_value_set_string (value, str.c_str());
144 gpointer
operator new (
size_t s)
146 return g_malloc0 (s);
148 void operator delete (gpointer mem)
152 gpointer
operator new[] (
size_t s)
154 return g_malloc0 (s);
156 void operator delete[] (gpointer mem)
166 } InitializationType;
168 template<
typename Type>
171 typedef Type BoxedType;
176 if (t == INIT_DEFAULT || t == INIT_EMPTY)
182 record =
new Type (*rh.record);
188 record =
new Type (rec);
195 record =
new Type (rec);
199 void set_boxed (Type *rec)
203 record =
new Type (*rec);
207 void take (Type *rec)
224 if (record != src.record)
228 record =
new Type (*src.record);
258 Type& operator[] (
unsigned int index)
261 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
262 return *(index ? NULL : record);
268 operator bool ()
const
273 boxed_copy (gpointer data)
277 Type *r =
reinterpret_cast<Type*
> (data);
284 boxed_free (gpointer data)
288 Type *r =
reinterpret_cast<Type*
> (data);
294 value_get_boxed (
const GValue *value)
296 if (SFI_VALUE_HOLDS_REC (value))
298 SfiRec *rec = sfi_value_get_rec (value);
304 Type *boxed =
reinterpret_cast<Type*
> (g_value_get_boxed (value));
312 value_set_boxed (GValue *value,
315 if (SFI_VALUE_HOLDS_REC (value))
317 SfiRec *rec = Type::to_rec (
self);
318 sfi_value_take_rec (value, rec);
321 g_value_set_boxed (value,
self.c_ptr());
325 template<
typename Type>
328 typedef Type* iterator;
329 typedef const Type* const_iterator;
331 unsigned int n_elements;
340 cseq = g_new0 (
CSeq, 1);
345 cseq = g_new0 (CSeq, 1);
348 Sequence (
const BoxedType &cs)
350 cseq = g_new0 (CSeq, 1);
356 return cseq->elements;
361 return cseq->elements;
366 return cseq->elements + cseq->n_elements;
371 return cseq->elements + cseq->n_elements;
379 g_free (cseq->elements);
389 cseq = g_new0 (CSeq, 1);
400 resize (
unsigned int n)
404 for (i = n; i < length(); i++)
405 cseq->elements[i].~Type();
406 i = cseq->n_elements;
407 cseq->n_elements = n;
408 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
409 for (; i < length(); i++)
410 new (cseq->elements + i) Type ();
413 operator[] (
unsigned int index)
415 if (index >= cseq->n_elements)
416 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
417 return cseq->elements[index];
420 operator[] (
unsigned int index)
const
422 if (index >= cseq->n_elements)
423 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
424 return cseq->elements[index];
427 operator+= (
const Type &elm)
430 guint i = cseq->n_elements++;
431 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
432 new (cseq->elements + i) Type (elm);
436 set_boxed (
const CSeq *cs)
443 cseq->n_elements = cs->n_elements;
444 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
445 for (guint i = 0; i < length(); i++)
446 new (cseq->elements + i) Type (cs->elements[i]);
449 operator= (
const Sequence &sh)
457 return cseq ? cseq->n_elements : 0;
462 g_free (cseq->elements);
466 boxed_copy (gpointer data)
470 CSeq *cs =
reinterpret_cast<CSeq*
> (data);
477 boxed_free (gpointer data)
481 CSeq *cs =
reinterpret_cast<CSeq*
> (data);
487 template<
typename SeqType> SeqType
488 cxx_value_get_boxed_sequence (
const GValue *value)
490 if (SFI_VALUE_HOLDS_SEQ (value))
492 SfiSeq *seq = sfi_value_get_seq (value);
493 return SeqType::from_seq (seq);
497 typename SeqType::CSeq *boxed =
reinterpret_cast<typename SeqType::CSeq*
> (g_value_get_boxed (value));
501 sh.set_boxed (boxed);
508 template<
typename SeqType>
void
509 cxx_value_set_boxed_sequence (GValue *value,
512 if (SFI_VALUE_HOLDS_SEQ (value))
514 SfiSeq *seq = SeqType::to_seq (
self);
515 sfi_value_take_seq (value, seq);
518 g_value_set_boxed (value,
self.c_ptr());
524 typedef float* iterator;
525 typedef const float* const_iterator;
526 FBlock (
unsigned int length = 0)
528 block = sfi_fblock_new_sized (length);
530 FBlock (SfiFBlock &fblock)
535 FBlock (
unsigned int length,
538 block = sfi_fblock_new();
539 sfi_fblock_append (block, length, values);
544 block = sfi_fblock_ref (fb.block);
546 block = sfi_fblock_new();
551 return block ? block->values : NULL;
556 return block ? block->values : NULL;
561 return block ? block->values + block->n_values : NULL;
566 return block ? block->values + block->n_values : NULL;
569 operator= (SfiFBlock &fb)
574 sfi_fblock_unref (block);
577 sfi_fblock_ref (block);
582 operator= (
const FBlock &s)
584 if (block != s.block)
587 sfi_fblock_unref (block);
590 sfi_fblock_ref (block);
602 sfi_fblock_unref (block);
608 block = sfi_fblock_new();
609 sfi_fblock_ref (block);
614 RAPICORN_ASSERT_RETURN (block != NULL && block->ref_count > 1);
615 sfi_fblock_unref (block);
618 resize (
unsigned int length)
621 sfi_fblock_resize (block, length);
623 block = sfi_fblock_new_sized (length);
629 sfi_fblock_unref (block);
636 return FBlock (block->n_values, block->values);
646 append (
unsigned int length,
650 block = sfi_fblock_new();
651 sfi_fblock_append (block, length, values);
661 return block ? block->n_values : 0;
666 return block ? block->values : NULL;
669 value_get_fblock (
const GValue *value)
671 SfiFBlock *fb = sfi_value_get_fblock (value);
674 self.take (sfi_fblock_ref (fb));
678 value_set_fblock (GValue *value,
681 sfi_value_set_fblock (value,
self.block);
688 BBlock (
unsigned int length = 0)
690 block = sfi_bblock_new_sized (length);
692 BBlock (SfiBBlock &bblock)
697 BBlock (
unsigned int length,
700 block = sfi_bblock_new();
701 sfi_bblock_append (block, length, bytes);
706 block = sfi_bblock_ref (bb.block);
708 block = sfi_bblock_new();
711 operator= (SfiBBlock &bb)
716 sfi_bblock_unref (block);
719 sfi_bblock_ref (block);
724 operator= (
const BBlock &s)
726 if (block != s.block)
729 sfi_bblock_unref (block);
732 sfi_bblock_ref (block);
743 sfi_bblock_unref (block);
749 block = sfi_bblock_new();
750 sfi_bblock_ref (block);
755 RAPICORN_ASSERT_RETURN (block != NULL && block->ref_count > 1);
756 sfi_bblock_unref (block);
758 void resize (
unsigned int length)
761 sfi_bblock_resize (block, length);
763 block = sfi_bblock_new_sized (length);
769 sfi_bblock_unref (block);
775 return BBlock (block->n_bytes, block->bytes);
783 void append (
unsigned int length,
787 block = sfi_bblock_new();
788 sfi_bblock_append (block, length, bytes);
790 void append (guint8 b)
794 unsigned int length()
796 return block ? block->n_bytes : 0;
800 return block ? block->bytes : NULL;
802 static BBlock value_get_bblock (
const GValue *value)
804 SfiBBlock *bb = sfi_value_get_bblock (value);
807 self.take (sfi_bblock_ref (bb));
810 static void value_set_bblock (GValue *value,
813 sfi_value_set_bblock (value,
self.block);
832 crec = sfi_rec_ref (rr.crec);
839 sfi_rec_clear (crec);
842 operator= (SfiRec &sr)
847 sfi_rec_unref (crec);
855 operator= (
const Rec &rr)
860 sfi_rec_unref (crec);
874 sfi_rec_unref (crec);
880 crec = sfi_rec_new();
886 RAPICORN_ASSERT_RETURN (crec != NULL && crec->ref_count > 1);
887 sfi_rec_unref (crec);
893 sfi_rec_unref (crec);
899 return Rec (*sfi_rec_copy_deep (crec));
907 void set (
const gchar *field_name,
911 crec = sfi_rec_new();
912 sfi_rec_set (crec, field_name, value);
914 unsigned int length()
916 return crec ? crec->n_fields : 0;
918 GValue*
get (
const gchar *name)
920 return crec ? sfi_rec_get (crec, name) : NULL;
922 static Rec value_get_rec (
const GValue *value)
924 SfiRec *sr = sfi_value_get_rec (value);
927 self.take (sfi_rec_ref (sr));
930 static void value_set_rec (GValue *value,
933 sfi_value_set_rec (value,
self.crec);
952 cobj = (GObject*) g_object_ref (oh.cobj);
959 g_object_unref (cobj);
966 g_object_unref (cobj);
978 g_object_unref (cobj);
992 RAPICORN_ASSERT_RETURN (cobj != NULL && cobj->ref_count > 0);
998 RAPICORN_ASSERT_RETURN (cobj != NULL && cobj->ref_count > 1);
999 g_object_unref (cobj);
1002 take (GObject *
object)
1005 g_object_unref (cobj);
1021 GObject *
object = (GObject*) g_value_get_object (value);
1024 self.take ((GObject*) g_object_ref (
object));
1027 static void value_set (GValue *value,
1030 g_value_set_object (value,
self.cobj);
1034 template<
typename Type>
void
1035 cxx_boxed_to_rec (
const GValue *src_value,
1039 gpointer boxed = g_value_get_boxed (src_value);
1042 Type *t =
reinterpret_cast<Type*
> (boxed);
1043 rec = Type::to_rec (*t);
1045 sfi_value_take_rec (dest_value, rec);
1048 template<
typename Type>
void
1049 cxx_boxed_from_rec (
const GValue *src_value,
1052 gpointer boxed = NULL;
1053 SfiRec *rec = sfi_value_get_rec (src_value);
1056 RecordHandle<Type> rh = Type::from_rec (rec);
1057 Type *t = rh.steal();
1060 g_value_take_boxed (dest_value, boxed);
1063 template<
typename SeqType>
void
1064 cxx_boxed_to_seq (
const GValue *src_value,
1068 gpointer boxed = g_value_get_boxed (src_value);
1071 typename SeqType::CSeq *t =
reinterpret_cast<typename SeqType::CSeq*
> (boxed);
1074 seq = SeqType::to_seq (cxxseq);
1077 sfi_value_take_seq (dest_value, seq);
1080 template<
typename SeqType>
void
1081 cxx_boxed_from_seq (
const GValue *src_value,
1084 gpointer boxed = NULL;
1085 SfiSeq *seq = sfi_value_get_seq (src_value);
1088 SeqType sh = SeqType::from_seq (seq);
1089 typename SeqType::CSeq *t = sh.steal();
1092 g_value_take_boxed (dest_value, boxed);
1095 template<
typename Type> RecordHandle<Type>
1096 cxx_value_get_rec (
const GValue *value)
1098 SfiRec *rec = sfi_value_get_rec (value);
1100 return Type::from_rec (rec);
1105 template<
typename Type>
void
1106 cxx_value_set_rec (GValue *value,
1107 const RecordHandle<Type> &
self)
1110 sfi_value_take_rec (value, Type::to_rec (
self));
1112 sfi_value_set_rec (value, NULL);
1115 template<
typename SeqType> SeqType
1116 cxx_value_get_seq (
const GValue *value)
1118 SfiSeq *seq = sfi_value_get_seq (value);
1120 return SeqType::from_seq (seq);
1125 template<
typename SeqType>
void
1126 cxx_value_set_seq (GValue *value,
1127 const SeqType &
self)
1129 sfi_value_take_seq (value, SeqType::to_seq (
self));
1134 explicit Init (
void (*f) ()) { f(); }
Definition: sficxx.hh:817
Definition: sficxx.hh:685
Definition: sficxx.hh:330
Definition: sficxx.hh:326
Definition: sficxx.hh:521
Definition: sficxx.hh:1133
Definition: sficxx.hh:169
Definition: sficxx.hh:937
Definition: sficxx.hh:143
The Sfi namespace contains utilities for synthesis.
Definition: oldidl.idl:4