+};
+
+template <class Super>
+class Smob_base
+{
+ static scm_t_bits smob_tag_;
+ static Scm_init scm_init_;
+ static void init (void);
+ static string smob_name_;
+ static Super *unchecked_unsmob (SCM s)
+ {
+ return reinterpret_cast<Super *> (SCM_SMOB_DATA (s));
+ }
+protected:
+ // reference scm_init_ in smob_tag which is sure to be called. The
+ // constructor, in contrast, may not be called at all in classes
+ // like Smob1.
+ static scm_t_bits smob_tag () { (void) scm_init_; return smob_tag_; }
+ Smob_base () { }
+ static SCM register_ptr (Super *p);
+ static Super *unregister_ptr (SCM obj);
+private:
+ // Those fallbacks are _only_ for internal use by Smob_base. They
+ // are characterized by no knowledge about the implemented type
+ // apart from the type's name. Overriding them as a template
+ // specialization is _not_ intended since a type-dependent
+ // implementation will in general need access to possibly private
+ // parts of the Super class. So any class-dependent override should
+ // be done by redefining the respective function in the Super class
+ // (where it will mask the private template member) rather than
+ // specializing a different template function/pointer.
+ //
+ // Since we consider those internal-only, two of them are actually
+ // implemented as literal zero constant. That allows us to fall
+ // back to GUILE's default implementation. Arguably the same could
+ // be done for print_smob, but the resulting default output of, say,
+ // #<Context_mod 0x7352414> would depend on memory layout, thus
+ // being unsuitable for regtest comparisons unless filtered.
+
+ static const int mark_smob = 0;
+ static const int equal_p = 0;
+ static int print_smob (SCM, SCM, scm_print_state *);
+ static size_t free_smob (SCM obj)
+ {
+ delete Smob_base<Super>::unregister_ptr (obj);
+ return 0;
+ }
+ // type_p_name_ can be overriden in the Super class with a static
+ // const char [] string. This requires both a declaration in the
+ // class as well as a single instantiation outside. Using a
+ // template specialization for supplying a different string name
+ // right in Smob_base<Super> itself seems tempting, but the C++
+ // rules would then require a specialization declaration at the
+ // class definition site as well as a specialization instantiation
+ // in a single compilation unit. That requires just as much source
+ // code maintenance while being harder to understand and quite
+ // trickier in its failure symptoms when things go wrong. So we
+ // just do things like with the other specializations.
+ static const int type_p_name_ = 0;
+public:
+ static bool is_smob (SCM s)
+ {
+ return SCM_SMOB_PREDICATE (smob_tag (), s);
+ }
+ static SCM smob_p (SCM s)
+ {
+ return is_smob (s) ? SCM_BOOL_T : SCM_BOOL_F;
+ }
+ static Super *unsmob (SCM s)
+ {
+ return is_smob (s) ? Super::unchecked_unsmob (s) : 0;
+ }
+};