File: guile2cc.cc

package info (click to toggle)
rumor 1.0.5-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 544 kB
  • ctags: 317
  • sloc: cpp: 1,438; makefile: 33; lisp: 24; sh: 4
file content (52 lines) | stat: -rw-r--r-- 1,879 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
  Convenience templates for more c++-like conversions
    between c++ and guile data,
  not everything from guile/gh.h implemented!
*/

#include"rumor.hh"

#ifdef HAVE_GUILE

#include<stdexcept>

#define SPECIALIZATION_OF_SCM_TO(c_type,scm_conv,scm_pred) \
template<> const c_type SCM_to<c_type>(SCM s){ \
  if (!scm_pred(s)) throw script_error("SCM_to: predicate " #scm_pred " false."); \
  return scm_conv(s);}
SPECIALIZATION_OF_SCM_TO(unsigned long,scm_to_long,scm_is_number)
SPECIALIZATION_OF_SCM_TO(unsigned,scm_to_long,scm_is_number)
SPECIALIZATION_OF_SCM_TO(long,scm_to_long,scm_is_number)
SPECIALIZATION_OF_SCM_TO(int,scm_to_int,scm_is_number)
SPECIALIZATION_OF_SCM_TO(double,scm_to_double,scm_is_number)
SPECIALIZATION_OF_SCM_TO(bool,scm_to_bool,scm_is_bool)
#undef SPECIALIZATION_OF_SCM_TO

template<> const char SCM_to<char>(SCM s){
  if (!scm_is_true (scm_char_p (s))) throw script_error("SCM_to: predicate " " scm_is_true " " false.");
  return scm_to_char(s);} //FIXME: oget: recheck

template<> const std::string SCM_to<std::string>(SCM s){
  if (!scm_is_string(s)) throw script_error("SCM_to: predicate " "scm_is_string" " false.");
  char* pstr=scm_to_locale_string(s);
  std::string ret(pstr);
  delete[] pstr; //FIXME: is this correct?
  return ret;
}
#define SPECIALIZATION_OF_TO_SCM(c_type,scm_conv) \
template<> SCM to_SCM(const c_type& arg){ \
  return scm_conv(arg); }
SPECIALIZATION_OF_TO_SCM(unsigned long,scm_from_ulong)
SPECIALIZATION_OF_TO_SCM(unsigned,scm_from_ulong)
SPECIALIZATION_OF_TO_SCM(long,scm_from_ulong)
SPECIALIZATION_OF_TO_SCM(int,scm_from_int)
SPECIALIZATION_OF_TO_SCM(bool,scm_from_bool)
SPECIALIZATION_OF_TO_SCM(double,scm_make_real)
SPECIALIZATION_OF_TO_SCM(char,SCM_MAKE_CHAR)
#undef SPECIALIZATION_OF_TO_SCM

template<> SCM to_SCM(const std::string& arg){
  return scm_from_locale_string(arg.c_str()); }


#endif /*HAVE_GUILE*/