17 int cmp (
const char *ostring)
const
19 if (cstring && ostring)
20 return strcmp (cstring, ostring);
24 return ostring ? SFI_MININT : 0;
29 cstring = g_strdup (
"");
33 cstring = g_strdup (s.cstring);
35 String (
const std::string &s)
37 cstring = g_strdup (s.c_str());
41 cstring = g_strdup (cstr ? cstr :
"");
43 String& operator= (
const std::string &s)
46 cstring = g_strdup (s.c_str());
49 String& operator= (
const gchar *cstr)
54 cstring = g_strdup (cstr ? cstr :
"");
60 if (s.cstring != cstring)
63 cstring = g_strdup (s.cstring);
67 const char* c_str()
const
71 String& operator+= (
const gchar *cstr)
74 cstring = g_strconcat (old ? old :
"", cstr, NULL);
81 cstring = g_strconcat (old ? old :
"", src.cstring, NULL);
85 String& operator+= (
const std::string &src)
88 cstring = g_strconcat (old ? old :
"", src.c_str(), NULL);
92 String operator+ (
const gchar *cstr)
94 return String (cstring) += cstr;
98 return String (cstring) += src;
100 String operator+ (
const std::string &src)
102 return String (cstring) += src;
104 bool operator< (
const char *src)
const {
return cmp (src) < 0; }
105 bool operator<= (
const char *src)
const {
return cmp (src) <= 0; }
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 String &s)
const {
return cmp (s.cstring) < 0; }
111 bool operator<= (
const String &s)
const {
return cmp (s.cstring) <= 0; }
112 bool operator> (
const String &s)
const {
return cmp (s.cstring) > 0; }
113 bool operator>= (
const String &s)
const {
return cmp (s.cstring) >= 0; }
114 bool operator!= (
const String &s)
const {
return cmp (s.cstring) != 0; }
115 bool operator== (
const String &s)
const {
return cmp (s.cstring) == 0; }
116 bool operator< (
const std::string &s)
const {
return cmp (s.c_str()) < 0; }
117 bool operator<= (
const std::string &s)
const {
return cmp (s.c_str()) <= 0; }
118 bool operator> (
const std::string &s)
const {
return cmp (s.c_str()) > 0; }
119 bool operator>= (
const std::string &s)
const {
return cmp (s.c_str()) >= 0; }
120 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 unsigned int length()
124 return cstring ?
strlen (cstring) : 0;
131 static String value_get_string (
const GValue *value)
133 return sfi_value_get_string (value);
135 static void value_set_string (GValue *value,
138 sfi_value_set_string (value, str.c_str());
143 gpointer
operator new (
size_t s)
145 return g_malloc0 (s);
147 void operator delete (gpointer mem)
151 gpointer
operator new[] (
size_t s)
153 return g_malloc0 (s);
155 void operator delete[] (gpointer mem)
165 } InitializationType;
167 template<
typename Type>
170 typedef Type BoxedType;
175 if (t == INIT_DEFAULT || t == INIT_EMPTY)
181 record =
new Type (*rh.record);
187 record =
new Type (rec);
194 record =
new Type (rec);
198 void set_boxed (Type *rec)
202 record =
new Type (*rec);
206 void take (Type *rec)
223 if (record != src.record)
227 record =
new Type (*src.record);
257 Type& operator[] (
unsigned int index)
260 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
261 return *(index ? NULL : record);
267 operator bool ()
const
272 boxed_copy (gpointer data)
276 Type *r =
reinterpret_cast<Type*
> (data);
283 boxed_free (gpointer data)
287 Type *r =
reinterpret_cast<Type*
> (data);
293 value_get_boxed (
const GValue *value)
295 if (SFI_VALUE_HOLDS_REC (value))
297 SfiRec *rec = sfi_value_get_rec (value);
303 Type *boxed =
reinterpret_cast<Type*
> (g_value_get_boxed (value));
311 value_set_boxed (GValue *value,
314 if (SFI_VALUE_HOLDS_REC (value))
316 SfiRec *rec = Type::to_rec (
self);
317 sfi_value_take_rec (value, rec);
320 g_value_set_boxed (value,
self.c_ptr());
324 template<
typename Type>
327 typedef Type* iterator;
328 typedef const Type* const_iterator;
330 unsigned int n_elements;
339 cseq = g_new0 (
CSeq, 1);
344 cseq = g_new0 (CSeq, 1);
347 Sequence (
const BoxedType &cs)
349 cseq = g_new0 (CSeq, 1);
355 return cseq->elements;
360 return cseq->elements;
365 return cseq->elements + cseq->n_elements;
370 return cseq->elements + cseq->n_elements;
378 g_free (cseq->elements);
388 cseq = g_new0 (CSeq, 1);
399 resize (
unsigned int n)
403 for (i = n; i < length(); i++)
404 cseq->elements[i].~Type();
405 i = cseq->n_elements;
406 cseq->n_elements = n;
407 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
408 for (; i < length(); i++)
409 new (cseq->elements + i) Type ();
412 operator[] (
unsigned int index)
414 if (index >= cseq->n_elements)
415 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
416 return cseq->elements[index];
419 operator[] (
unsigned int index)
const
421 if (index >= cseq->n_elements)
422 g_critical (
"%s: invalid array subscript: %u", G_STRFUNC, index);
423 return cseq->elements[index];
426 operator+= (
const Type &elm)
429 guint i = cseq->n_elements++;
430 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
431 new (cseq->elements + i) Type (elm);
435 set_boxed (
const CSeq *cs)
442 cseq->n_elements = cs->n_elements;
443 cseq->elements = g_renew (Type, cseq->elements, cseq->n_elements);
444 for (guint i = 0; i < length(); i++)
445 new (cseq->elements + i) Type (cs->elements[i]);
448 operator= (
const Sequence &sh)
456 return cseq ? cseq->n_elements : 0;
461 g_free (cseq->elements);
465 boxed_copy (gpointer data)
469 CSeq *cs =
reinterpret_cast<CSeq*
> (data);
476 boxed_free (gpointer data)
480 CSeq *cs =
reinterpret_cast<CSeq*
> (data);
486 template<
typename SeqType> SeqType
487 cxx_value_get_boxed_sequence (
const GValue *value)
489 if (SFI_VALUE_HOLDS_SEQ (value))
491 SfiSeq *seq = sfi_value_get_seq (value);
492 return SeqType::from_seq (seq);
496 typename SeqType::CSeq *boxed =
reinterpret_cast<typename SeqType::CSeq*
> (g_value_get_boxed (value));
500 sh.set_boxed (boxed);
507 template<
typename SeqType>
void
508 cxx_value_set_boxed_sequence (GValue *value,
511 if (SFI_VALUE_HOLDS_SEQ (value))
513 SfiSeq *seq = SeqType::to_seq (
self);
514 sfi_value_take_seq (value, seq);
517 g_value_set_boxed (value,
self.c_ptr());
523 typedef float* iterator;
524 typedef const float* const_iterator;
525 FBlock (
unsigned int length = 0)
527 block = sfi_fblock_new_sized (length);
529 FBlock (SfiFBlock &fblock)
534 FBlock (
unsigned int length,
537 block = sfi_fblock_new();
538 sfi_fblock_append (block, length, values);
543 block = sfi_fblock_ref (fb.block);
545 block = sfi_fblock_new();
550 return block ? block->values : NULL;
555 return block ? block->values : NULL;
560 return block ? block->values + block->n_values : NULL;
565 return block ? block->values + block->n_values : NULL;
568 operator= (SfiFBlock &fb)
573 sfi_fblock_unref (block);
576 sfi_fblock_ref (block);
581 operator= (
const FBlock &s)
583 if (block != s.block)
586 sfi_fblock_unref (block);
589 sfi_fblock_ref (block);
601 sfi_fblock_unref (block);
607 block = sfi_fblock_new();
608 sfi_fblock_ref (block);
613 g_return_if_fail (block != NULL && block->ref_count > 1);
614 sfi_fblock_unref (block);
617 resize (
unsigned int length)
620 sfi_fblock_resize (block, length);
622 block = sfi_fblock_new_sized (length);
628 sfi_fblock_unref (block);
635 return FBlock (block->n_values, block->values);
645 append (
unsigned int length,
649 block = sfi_fblock_new();
650 sfi_fblock_append (block, length, values);
660 return block ? block->n_values : 0;
665 return block ? block->values : NULL;
668 value_get_fblock (
const GValue *value)
670 SfiFBlock *fb = sfi_value_get_fblock (value);
673 self.take (sfi_fblock_ref (fb));
677 value_set_fblock (GValue *value,
680 sfi_value_set_fblock (value,
self.block);
687 BBlock (
unsigned int length = 0)
689 block = sfi_bblock_new_sized (length);
691 BBlock (SfiBBlock &bblock)
696 BBlock (
unsigned int length,
699 block = sfi_bblock_new();
700 sfi_bblock_append (block, length, bytes);
705 block = sfi_bblock_ref (bb.block);
707 block = sfi_bblock_new();
710 operator= (SfiBBlock &bb)
715 sfi_bblock_unref (block);
718 sfi_bblock_ref (block);
723 operator= (
const BBlock &s)
725 if (block != s.block)
728 sfi_bblock_unref (block);
731 sfi_bblock_ref (block);
742 sfi_bblock_unref (block);
748 block = sfi_bblock_new();
749 sfi_bblock_ref (block);
754 g_return_if_fail (block != NULL && block->ref_count > 1);
755 sfi_bblock_unref (block);
757 void resize (
unsigned int length)
760 sfi_bblock_resize (block, length);
762 block = sfi_bblock_new_sized (length);
768 sfi_bblock_unref (block);
774 return BBlock (block->n_bytes, block->bytes);
782 void append (
unsigned int length,
786 block = sfi_bblock_new();
787 sfi_bblock_append (block, length, bytes);
789 void append (guint8 b)
793 unsigned int length()
795 return block ? block->n_bytes : 0;
799 return block ? block->bytes : NULL;
801 static BBlock value_get_bblock (
const GValue *value)
803 SfiBBlock *bb = sfi_value_get_bblock (value);
806 self.take (sfi_bblock_ref (bb));
809 static void value_set_bblock (GValue *value,
812 sfi_value_set_bblock (value,
self.block);
831 crec = sfi_rec_ref (rr.crec);
838 sfi_rec_clear (crec);
841 operator= (SfiRec &sr)
846 sfi_rec_unref (crec);
854 operator= (
const Rec &rr)
859 sfi_rec_unref (crec);
873 sfi_rec_unref (crec);
879 crec = sfi_rec_new();
885 g_return_if_fail (crec != NULL && crec->ref_count > 1);
886 sfi_rec_unref (crec);
892 sfi_rec_unref (crec);
898 return Rec (*sfi_rec_copy_deep (crec));
906 void set (
const gchar *field_name,
910 crec = sfi_rec_new();
911 sfi_rec_set (crec, field_name, value);
913 unsigned int length()
915 return crec ? crec->n_fields : 0;
917 GValue*
get (
const gchar *name)
919 return crec ? sfi_rec_get (crec, name) : NULL;
921 static Rec value_get_rec (
const GValue *value)
923 SfiRec *sr = sfi_value_get_rec (value);
926 self.take (sfi_rec_ref (sr));
929 static void value_set_rec (GValue *value,
932 sfi_value_set_rec (value,
self.crec);
951 cobj = (GObject*) g_object_ref (oh.cobj);
958 g_object_unref (cobj);
965 g_object_unref (cobj);
977 g_object_unref (cobj);
991 g_return_if_fail (cobj != NULL && cobj->ref_count > 0);
997 g_return_if_fail (cobj != NULL && cobj->ref_count > 1);
998 g_object_unref (cobj);
1001 take (GObject *
object)
1004 g_object_unref (cobj);
1020 GObject *
object = (GObject*) g_value_get_object (value);
1023 self.take ((GObject*) g_object_ref (
object));
1026 static void value_set (GValue *value,
1029 g_value_set_object (value,
self.cobj);
1033 template<
typename Type>
void
1034 cxx_boxed_to_rec (
const GValue *src_value,
1038 gpointer boxed = g_value_get_boxed (src_value);
1041 Type *t =
reinterpret_cast<Type*
> (boxed);
1042 rec = Type::to_rec (*t);
1044 sfi_value_take_rec (dest_value, rec);
1047 template<
typename Type>
void
1048 cxx_boxed_from_rec (
const GValue *src_value,
1051 gpointer boxed = NULL;
1052 SfiRec *rec = sfi_value_get_rec (src_value);
1055 RecordHandle<Type> rh = Type::from_rec (rec);
1056 Type *t = rh.steal();
1059 g_value_take_boxed (dest_value, boxed);
1062 template<
typename SeqType>
void
1063 cxx_boxed_to_seq (
const GValue *src_value,
1067 gpointer boxed = g_value_get_boxed (src_value);
1070 typename SeqType::CSeq *t =
reinterpret_cast<typename SeqType::CSeq*
> (boxed);
1073 seq = SeqType::to_seq (cxxseq);
1076 sfi_value_take_seq (dest_value, seq);
1079 template<
typename SeqType>
void
1080 cxx_boxed_from_seq (
const GValue *src_value,
1083 gpointer boxed = NULL;
1084 SfiSeq *seq = sfi_value_get_seq (src_value);
1087 SeqType sh = SeqType::from_seq (seq);
1088 typename SeqType::CSeq *t = sh.steal();
1091 g_value_take_boxed (dest_value, boxed);
1094 template<
typename Type> RecordHandle<Type>
1095 cxx_value_get_rec (
const GValue *value)
1097 SfiRec *rec = sfi_value_get_rec (value);
1099 return Type::from_rec (rec);
1104 template<
typename Type>
void
1105 cxx_value_set_rec (GValue *value,
1106 const RecordHandle<Type> &
self)
1109 sfi_value_take_rec (value, Type::to_rec (
self));
1111 sfi_value_set_rec (value, NULL);
1114 template<
typename SeqType> SeqType
1115 cxx_value_get_seq (
const GValue *value)
1117 SfiSeq *seq = sfi_value_get_seq (value);
1119 return SeqType::from_seq (seq);
1124 template<
typename SeqType>
void
1125 cxx_value_set_seq (GValue *value,
1126 const SeqType &
self)
1128 sfi_value_take_seq (value, SeqType::to_seq (
self));
1133 explicit Init (
void (*f) ()) { f(); }
Definition: sficxx.hh:816
Definition: sficxx.hh:684
Definition: sficxx.hh:329
Definition: sficxx.hh:325
Definition: sficxx.hh:520
Definition: sficxx.hh:1132
Definition: sficxx.hh:168
Definition: sficxx.hh:936
Definition: sficxx.hh:142