Exemple #1
0
encoder operator<<(encoder e, const value& v) {
    data edata = e.data();
    if (edata == v.data_) throw conversion_error("cannot insert into self");
    data vdata = v.decode().data();
    check(edata.append(vdata), e.pn_object());
    return e;
}
Exemple #2
0
object sqlite3::compile(flusspferd::string sql_in, value bind ) {
    local_root_scope scope;

    size_t n_bytes = sql_in.length() * 2;
    sqlite3_stmt * sth = 0;
    js_char16_t * tail = 0; // uncompiled part of the sql (when multiple stmts)
    
    if (sqlite3_prepare16_v2(db, sql_in.data(), n_bytes, &sth, (const void**)&tail) != SQLITE_OK)
    {
        raise_sqlite_error(db);
    }

    object cursor = create<sqlite3_cursor>(fusion::make_vector(sth));

    string tail_str;
    if (tail) {
        tail_str = string(tail);
    }
    
    string sql = sql_in.substr( 0, sql_in.size() - tail_str.size() );

    cursor.define_property("sql", sql);
    cursor.define_property("tail", tail_str);        

    if ( !bind.is_undefined_or_null() ) {
        cursor.call("bind", bind );
    }
    
    return cursor;
}
Exemple #3
0
  value value::multiply(const value& that) const
  {
    if (that.is(m_type))
    {
      switch (m_type)
      {
        case type::number:
          return multiply_number(*m_value_number, *that.m_value_number);

        case type::vector:
          return multiply_vector(*m_value_vector, *that.m_value_vector);

        default:
          break;
      }
    }

    throw error(
      error::type::type,
      U"Cannot multiply " +
      type_description(that.m_type) +
      U" with " +
      type_description(m_type)
    );
  }
/// Like coerce(const value&) but assigns the value to a reference
/// instead of returning it.  May be more efficient for complex values
/// (arrays, maps, etc.)
///
/// @related proton::value
template<class T> void coerce(const value& v, T& x) {
    codec::decoder d(v, false);
    if (type_id_is_scalar(v.type())) {
        scalar s;
        d >> s;
        x = internal::coerce<T>(s);
    } else {
Exemple #5
0
object fs_base::raw_open(char const* name, value mode, value perms) {
  // TODO: Deal with permissions somewhere :)
  if (!perms.is_undefined_or_null())
    throw exception("rawOpen: permissions not yet supported");

  return create_native_object<io::file>(object(), name, mode);
}
 unsigned get_version(quickbook::state& state, bool using_docinfo,
         value version)
 {
     unsigned result = 0;
 
     if (!version.empty()) {
         value_consumer version_values(version);
         bool before_docinfo = version_values.optional_consume(
             doc_info_tags::before_docinfo).check();
         int major_verison = version_values.consume().get_int();
         int minor_verison = version_values.consume().get_int();
         version_values.finish();
 
         if (before_docinfo || using_docinfo) {
             result = ((unsigned) major_verison * 100) +
                 (unsigned) minor_verison;
         
             if(result < 100 || result > 107)
             {
                 detail::outerr(state.current_file->path)
                     << "Unknown version: "
                     << major_verison
                     << "."
                     << minor_verison
                     << std::endl;
                 ++state.error_count;
             }
         }
     }
     
     return result;
 }
// ==========================================================================
// METHOD IconRequestHandler::run
// ==========================================================================
int IconRequestHandler::run (string &uri, string &postbody, value &inhdr,
							 string &out, value &outhdr, value &env,
							 tcpsocket &s)
{
	bool isdown = (uri.strstr ("/down/") >= 0);
	string uuid = uri.copyafterlast ("/");
	uuid.cropat ('.');
	
	app->log (log::debug, "httpicon", "Request for <%s>" %format (uuid));
	
	if (inhdr.exists ("If-Modified-Since"))
	{
		s.puts ("HTTP/1.1 304 NOT CHANGED\r\n"
				"Connection: %s\r\n"
				"Content-length: 0\r\n\r\n"
				%format (env["keepalive"].bval() ? "keep-alive" : "close"));
		
		env["sentbytes"] = 0;
		return -304;
	}
	
	if (! app->mdb->classExistsUUID (uuid))
	{
		string orgpath;
		
		if (isdown)
		{
			orgpath = "/var/openpanel/http/images/icons/down_%s.png" %format (uuid);
		}
		else
		{
			orgpath = "/var/openpanel/http/images/icons/%s.png" %format (uuid);
		}
		if (fs.exists (orgpath))
		{
			out = fs.load (orgpath);
			outhdr["Content-type"] = "image/png";
			return 200;
		}
		return 404;
	}
	CoreClass &c = app->mdb->getClassUUID (uuid);
	string path;
	if (isdown)
	{
		path = "%s/down_%s" %format (c.module.path, c.icon);
	}
	else
	{
		path = "%s/%s" %format (c.module.path, c.icon);
	}
	
	app->log (log::debug, "httpicon", "Loading %s" %format (path));
	
	if (! fs.exists (path)) return 404;
	
	outhdr["Content-type"] = "image/png";
	out = fs.load (path);
	return 200;
}
Exemple #8
0
BigInt::reference BigInt::operator/= ( value o )
{
    if ( o == zero )
        throw std::domain_error ( "Division by zero" );

    bool rsign = false;

    if ( sign_ )
    {
        abs();
        rsign = true;
    }
    if ( o.sign_ )
    {
        o.abs();
        rsign = !rsign;
    }

    BigInt q = zero;
    while ( *this >= 0 )
    {
        operator-= ( o );
        ++q;
    }
    // now, *this + o = r
    --q;

    buffer= q.buffer;
    sign_ = rsign;

    return normalize();
}
Exemple #9
0
void LLCCEP::IRGenerator::insertTop(value out)
{
	IR_GENERATOR_OK;

	::std::fprintf(output, "top %s\n", out.getMnemonic().c_str());

	IR_GENERATOR_OK;
}
Exemple #10
0
 static bool can_convert_from(const value& val) {
     if (val.type() != value_type::vector_type) {
         return false;
     }
     const auto& vec = val.get<value_vector_type>();
     return vec.size() == sizeof...(T)
         && tuple_value_converter<T...>::types_match(vec, 0);
 }
Exemple #11
0
 switch_instruction switch_(value const & cond, label const & default_)
 {
   llvm::IRBuilder<> & bldr = current_builder();
   llvm::SwitchInst * rv = SPRITE_APICALL(
       bldr.CreateSwitch(cond.ptr(), default_.ptr())
     );
   return switch_instruction(rv);
 }
Exemple #12
0
static int get_byte(value byte_) {
  int byte;
  if (byte_.is_int()) {
    byte = byte_.get_int();
    if (byte < 0 || byte > 255)
      throw exception("Byte is outside the valid range for bytes");
    return byte;
  }
  object byte_o = byte_.to_object();
  if (byte_o.is_null())
    throw exception("Not a valid byte");
  binary &byte_bin = flusspferd::get_native<binary>(byte_o);
  if (byte_bin.get_length() != 1)
    throw exception("Byte must not be a non single-element Binary");
  byte = byte_bin.get_const_data()[0];
  return byte;
}
Exemple #13
0
object base_parser::parse(value source) {
  if (source.is_object()) {
    object o = source.get_object();

    if (is_native<io::stream>(o)) {
      io::stream &s = flusspferd::get_native<io::stream>(o);

      // TODO: Work out if the stream is readable or not!
      std::ifstream stream;
      dynamic_cast<std::ios&>(stream).rdbuf( s.streambuf() );
      sax_source is;
      is.setByteStream(stream);
      return parse_source(is);
    }
    /*else if (is_native<binary>(o)) {
      // Couldn't get this working. Compile errors
      binary &b = flusspferd::get_native<flusspferd::binary>(o);

      call_context c;
      c.arg.push_back(b);
      create<io::binary_stream>(c);
      root_object s(b_s);

      std::ifstream stream;
      dynamic_cast<std::ios&>(stream).rdbuf( b_s.streambuf() );
      sax_source is;
      is.setByteStream(stream);
      return parse_source(is);
    }*/
  }

  std::string str = source.to_std_string();

  security &sec = security::get();
  if (!sec.check_path(str, security::READ)) {
    throw exception(
      format("xml.Parser#parse: could not open file: 'denied by security' (%s)")
             % str
    );
  }

  sax_source is;
  is.setSystemId(str);

  return parse_source(is);
}
void traverse(const value&                                           tree,
              const std::function<void (const path&, const value&)>& func,
              const path&                                            base_path,
              bool                                                   leafs_only
             )
{
    if (!leafs_only || tree.empty() || (tree.kind() != kind::array && tree.kind() != kind::object))
        func(base_path, tree);
    
    if (tree.kind() == kind::object)
    {
        for (const auto& field : tree.as_object())
        {
            traverse(field.second,
                     func,
                     base_path + field.first,
                     leafs_only
                    );
        }
    }
    else if (tree.kind() == kind::array)
    {
        for (value::size_type idx = 0; idx < tree.size(); ++idx)
            traverse(tree[idx],
                     func,
                     base_path + idx,
                     leafs_only
                    );
    }
}
void print(value &v){
    stringstream ss;
    v.serialize(ss);
    string str;
    getline(ss, str);
    for(int i = 0 ; i < (int)str.size() ; i++)
        cout << setw(2) << setfill('0') << hex << (((int)str[i])&255) << ' ';
    cout << endl;
}
void named_node_map::property_op(property_mode mode, value const &id, value &x) {
  int index;
  if (id.is_int()) {
    index = id.get_int();
  } else {
    this->native_object_base::property_op(mode, id, x);
    return;
  }

  if (index < 0 || std::size_t(index) >= impl_.getLength())
    throw exception("Out of bounds on NamedNodeMap", "RangeError");

  switch (mode) {
  case property_get:
    x = item(index);
  default: break;
  };
}
Exemple #17
0
void LLCCEP::IRGenerator::insertMov(LLCCEP::value out, value in)
{
	IR_GENERATOR_OK;

	::std::fprintf(output, "mov %s, %s\n", out.getMnemonic().c_str(),
  	               in.getMnemonic().c_str());	
	
	IR_GENERATOR_OK;
}
Exemple #18
0
void ValueObjectStreamOut::toValue(value &v)
{
   int offset = (int)&data[0];
   int len = data.size();

   value::global("Module").call<void>("unrealize", v, offset, len, value::null() );
   if (count)
      v.set("handles", handleArray);
}
Exemple #19
0
	static PostingJoinOperatorConfiguration get( value const &v )
	{
		PostingJoinOperatorConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.name = v.get<std::string>( "name" );
		c.description = v.get<std::string>( "description" );
		return c;
	}
Exemple #20
0
void object::delete_property(value const &id) {
  if (is_null())
    throw exception("Could not delete property (object is null)");
  local_root_scope scope;
  string name = id.to_string();
  jsval dummy;
  if (!JS_DeleteUCProperty2(Impl::current_context(), get(),
                            (jschar*)name.data(), name.length(), &dummy))
    throw exception("Could not delete property");
}
Exemple #21
0
	static MetadataDefiniton get( value const &v )
	{
		MetadataDefiniton m;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		m.name = v.get<std::string>( "name" );
		m.type = v.get<std::string>( "type" );
		return m;
	}
Exemple #22
0
 /// Appends an indirect branch instruction to the active label scope.
 instruction goto_(value const & target, array_ref<label> const & labels)
 {
   // Note: no update to the current label.
   llvm::IRBuilder<> & bldr = current_builder();
   llvm::IndirectBrInst * rv = SPRITE_APICALL(
       bldr.CreateIndirectBr(target.ptr(), labels.size())
     );
   for(label const & l : labels)
     rv->addDestination(l.ptr());
   return instruction(rv);
 }
	static DocumentGetRequest get( value const &v )
	{
		DocumentGetRequest d;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		// TODO: should we also accept int, float? how can we fall back?
		d.docid = v.get<std::string>( "docid", "" );		
		
		return d;
	}
Exemple #24
0
	static SummarizerFunctionConfiguration get( value const &v )
	{
		SummarizerFunctionConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.name = v.get<std::string>( "name" );
		c.description = v.get<std::string>( "description" );
		c.parameter = v.get<std::vector<FunctionParameter> >( "parameter" );
		return c;
	}
Exemple #25
0
	static ServiceConfiguration get( value const &v )
	{
		ServiceConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.weighting_functions = v.get<std::vector<WeightingFunctionConfiguration> >( "weighting_functions", std::vector<WeightingFunctionConfiguration>( ) );
		c.summarizer_functions = v.get<std::vector<SummarizerFunctionConfiguration> >( "summarizer_functions", std::vector<SummarizerFunctionConfiguration>( ) );
		c.posting_join_operators = v.get<std::vector<PostingJoinOperatorConfiguration> >( "posting_join_operators", std::vector<PostingJoinOperatorConfiguration>( ) );
		return c;
	}
Exemple #26
0
	static StorageConfiguration get( value const &v )
	{
		StorageConfiguration c;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}		
		c.metadata = v.get<std::vector<struct MetadataDefiniton> >( "metadata", std::vector<struct MetadataDefiniton>( ) );
		c.attributes = v.get<std::vector<std::string> >( "attributes", std::vector<std::string>( ) );
		c.types = v.get<std::vector<std::string> >( "types", std::vector<std::string>( ) );
		return c;
	}
Exemple #27
0
value object::set_property(value const &id, value const &v_) {
  if (is_null())
    throw exception("Could not set property (object is null)");
  local_root_scope scope;
  value v = v_;
  string name = id.to_string();
  if (!JS_SetUCProperty(Impl::current_context(), get(),
                        (jschar*)name.data(), name.length(),
                        Impl::get_jsvalp(v)))
    throw exception("Could not set property");
  return v;
}
Exemple #28
0
bool object::has_property(value const &id) const {
  if (is_null())
    throw exception("Could not check property (object is null)");
  local_root_scope scope;
  string name = id.to_string();
  JSBool foundp;
  if (!JS_HasUCProperty(Impl::current_context(), get_const(),
                        (jschar*)name.data(), name.length(),
                        &foundp))
    throw exception("Could not check property");
  return foundp;
}
Exemple #29
0
 bool dtree::num_equal::test(const value& val) const
 {
   if(val.empty())
     return (as_number==0);
   else
     {
       if(val.is<std::string>())
         return (val.as<std::string>()==as_string);
       else
         return (val.as<unsigned int>()==as_number);
     }
 }
Exemple #30
0
value object::get_property(value const &id) const {
  if (is_null())
    throw exception("Could not get property (object is null)");
  value result;
  local_root_scope scope;
  string name = id.to_string();
  if (!JS_GetUCProperty(Impl::current_context(), get_const(),
                        (jschar*)name.data(), name.length(),
                        Impl::get_jsvalp(result)))
    throw exception("Could not get property");
  return result;
}