Skip to content
Snippets Groups Projects
Select Git revision
  • 16988605fe3645fc8caef5facc9ae7afbc0acb3f
  • main default protected
  • ud_training_script
  • fix_seed
  • merged-with-ner
  • multiword_fix_transformer
  • transformer_encoder
  • combo3
  • save_deprel_matrix_to_npz
  • master protected
  • combo-lambo
  • lambo-sent-attributes
  • adding_lambo
  • develop
  • update_allenlp2
  • develop_tmp
  • tokens_truncation
  • LR_test
  • eud_iwpt
  • iob
  • eud_iwpt_shared_task_bert_finetuning
  • 3.3.1
  • list
  • 3.2.1
  • 3.0.3
  • 3.0.1
  • 3.0.0
  • v1.0.6
  • v1.0.5
  • v1.0.4
  • v1.0.3
  • v1.0.2
  • v1.0.1
  • v1.0.0
34 results

Configuration.md

Blame
  • variables.cpp 1.59 KiB
    #include <libwccl/variables.h>
    #include <boost/mpl/always.hpp>
    #include <boost/mpl/pop_front.hpp>
    
    namespace Wccl {
    
    Variables::Variables()
    {
    }
    
    namespace {
    struct delhelper
    {
    	Variables& v;
    	const std::string& s;
    	bool& r;
    	delhelper(Variables& v, const std::string& s, bool& r): v(v), s(s), r(r) {}
    
    	template<typename T>
    	void operator()(const boost::mpl::always<T>&) {
    		r = v.del<T>(s) || r;
    	}
    };
    
    struct puthelper
    {
    	Variables& v;
    	const std::string& s;
    	bool& rv;
    	const boost::shared_ptr<Value>& p;
    	puthelper(Variables& v, const std::string& s, bool& rv,
    		const boost::shared_ptr<Value>& p): v(v), s(s), rv(rv), p(p) {}
    
    	template<typename T>
    	void operator()(const boost::mpl::always<T>&) {
    		if (rv) return;
    		boost::shared_ptr<T> t = boost::dynamic_pointer_cast<T>(p);
    		if (t) {
    			rv = true;
    			v.put(s, t);
    		}
    	}
    };
    
    } /* end anon ns */
    
    bool Variables::del_any(const std::string &s)
    {
    	bool rv = false;
    	typedef boost::mpl::pop_front< types >::type concrete;
    	// call delhelper::operator()<T> once for each of the allowed
    	// Value subtypes (but not for Value itself).
    	boost::mpl::for_each<concrete, boost::mpl::always<boost::mpl::_1> >(
    		delhelper(*this, s, rv));
    	return rv;
    }
    
    void Variables::put_any(const std::string &s, const boost::shared_ptr<Value> &v)
    {
    	bool rv = false;
    	typedef boost::mpl::pop_front< types >::type concrete;
    	// call puthelper::operator()<T> once for each of the allowed
    	// Value subtypes (but not for Value itself).
    	boost::mpl::for_each<concrete, boost::mpl::always<boost::mpl::_1> >(
    		puthelper(*this, s, rv, v));
    	if (!rv) throw VariableTypeMismatch(s);
    }
    
    } /* end ns Wccl */