Example #1
0
type EmptyMapType::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new EmptyMapType);
}
Example #2
0
/**
 * Read part of a 512 byte block from an SD card.
 *
 * \param[in] block Logical block to be read.
 * \param[in] offset Number of bytes to skip at start of block
 * \param[out] dst Pointer to the location that will receive the data.
 * \param[in] count Number of bytes to read
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
uint8_t Sd2Card::readData(uint32_t block,
        uint16_t offset, uint16_t count, uint8_t* dst) {
  uint16_t n;
  if (count == 0) return true;
  if ((count + offset) > 512) {
    goto fail;
  }
  if (!inBlock_ || block != block_ || offset < offset_) {
    block_ = block;
    // use address if not SDHC card
    if (type()!= SD_CARD_TYPE_SDHC) block <<= 9;
    if (cardCommand(CMD17, block)) {
      error(SD_CARD_ERROR_CMD17);
      goto fail;
    }
    if (!waitStartBlock()) {
      goto fail;
    }
    offset_ = 0;
    inBlock_ = 1;
  }

#ifdef OPTIMIZE_HARDWARE_SPI
  // start first spi transfer
  SPDR = 0XFF;

  // skip data before offset
  for (;offset_ < offset; offset_++) {
    while (!(SPSR & (1 << SPIF)))
      ;
    SPDR = 0XFF;
  }
  // transfer data
  n = count - 1;
  for (uint16_t i = 0; i < n; i++) {
    while (!(SPSR & (1 << SPIF)))
      ;
    dst[i] = SPDR;
    SPDR = 0XFF;
  }
  // wait for last byte
  while (!(SPSR & (1 << SPIF)))
    ;
  dst[n] = SPDR;

#else  // OPTIMIZE_HARDWARE_SPI
#ifdef ESP8266
  // skip data before offset
  SPI.transferBytes(NULL, NULL, offset_);

  // transfer data
  SPI.transferBytes(NULL, dst, count);

#else
  // skip data before offset
  for (;offset_ < offset; offset_++) {
    spiRec();
  }
  // transfer data
  for (uint16_t i = 0; i < count; i++) {
    dst[i] = spiRec();
  }
#endif
#endif  // OPTIMIZE_HARDWARE_SPI

  offset_ += count;
  if (!partialBlockRead_ || offset_ >= 512) {
    // read rest of data, checksum and set chip select high
    readEnd();
  }
  return true;

 fail:
  chipSelectHigh();
  return false;
}
Example #3
0
 void l_function::dump_all_function()
 {
     
     std::cout   << "function ( args:"
     << m_args_size
     << ", up value: "
     << m_up_val_size
     << ", consts: "
     << m_costants.size()
     << ", bytecode: "
     << m_commands.size()
     << " )\n\n";
     
     
     size_t id_consts = 0;
     std::string type ("unknow");
     std::string value("none");
     
     
     for(l_variable& variable : m_costants)
     {
         switch (variable.m_type)
         {
             case l_variable::INT: type = "int"; value = std::to_string(variable.m_value.m_i); break;
             case l_variable::FLOAT: type = "float"; value = std::to_string(variable.m_value.m_f); break;
             case l_variable::STRING: type = "string"; value = variable.string()->str(); break;
             case l_variable::FUNCTION: type = "function"; value = std::to_string(variable.m_value.m_i);  break;
             case l_variable::CFUNCTION: type = "c-function"; value = std::to_string((unsigned long)variable.m_value.m_pcfun);  break;
             case l_variable::OBJECT: type = "object"; value = std::to_string((unsigned long)variable.m_value.m_pobj); break;
                 
             default: break;
         }
         
         
         std::cout
         << "const["
         << id_consts++
         << "]: type: "
         << type
         << ", value: "
         << compiler_utilities::compile_string(value,false)
         << "\n";
     }
     std::cout<< " \n";
     
     //constants
     const int spaces = 20;
     //..
     size_t last = 0;
     size_t line = 0;
     
     for(auto& cmd : m_commands)
     {
         
         if(cmd.m_line > last)
         {
             last = cmd.m_line;
             std::cout<< std::to_string(cmd.m_line) << "\t";
         }
         else
         {
             std::cout<< " \t";
         }
         
         std::cout
         <<  line++
         <<  "\t"
         <<  l_op_code_str[cmd.m_op_code];
         
         //cmd len
         size_t len = std::strlen(l_op_code_str[cmd.m_op_code]);
         for(int i=0; i< (spaces-len); ++i) std::cout << " ";
         
         //..
         std::cout  <<  cmd.m_arg;
         
         //print var name
         if(  cmd.m_op_code == L_GET_GLOBAL
            ||cmd.m_op_code == L_GET_LOCAL
         // ||cmd.m_op_code == L_GET_AT_VAL
            ||cmd.m_op_code == L_GET_UP_VALUE
            ||cmd.m_op_code == L_SET_GLOBAL
            ||cmd.m_op_code == L_SET_LOCAL
         // ||cmd.m_op_code == L_SET_AT_VAL
            ||cmd.m_op_code == L_SET_UP_VALUE)
         {
             std::cout << "\t;" << m_costants[cmd.m_arg].to_string();
         }
         else if ( cmd.m_op_code == L_PUSHK )
         {
             std::cout << "\t;" <<  compiler_utilities::compile_string( m_costants[cmd.m_arg].to_string(), false );
         }
         
         //end line
         std::cout << std::endl;
     }
 }
Example #4
0
/**
 * copy constructor - generic
 *
 * If the rhs is not an EVB_GLOM_INFO item, we'll throw a bad_cast.
 *
 * @param rhs - CRingItem reference from which we will construct.
 */
CGlomParameters::CGlomParameters(const CRingItem& rhs) throw(std::bad_cast) :
    CRingItem(rhs)
{
    if (type() != EVB_GLOM_INFO) throw std::bad_cast();        
}
Example #5
0
/**
 * TODO: Refactor this function into smaller functions for better readability.
 *
 * This function is the entry point for the whole extraction process. The goal of the extraction
 * step is to filter and convert the OSM geometry to something more fitting for routing.
 * That includes:
 *  - extracting turn restrictions
 *  - splitting ways into (directional!) edge segments
 *  - checking if nodes are barriers or traffic signal
 *  - discarding all tag information: All relevant type information for nodes/ways
 *    is extracted at this point.
 *
 * The result of this process are the following files:
 *  .names : Names of all streets, stored as long consecutive string with prefix sum based index
 *  .osrm  : Nodes and edges in a intermediate format that easy to digest for osrm-prepare
 *  .restrictions : Turn restrictions that are used my osrm-prepare to construct the edge-expanded graph
 *
 */
int extractor::run(const ExtractorConfig &extractor_config)
{
    try
    {
        LogPolicy::GetInstance().Unmute();
        TIMER_START(extracting);

        const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();
        const auto number_of_threads =
            std::min(recommended_num_threads, extractor_config.requested_num_threads);
        tbb::task_scheduler_init init(number_of_threads);

        SimpleLogger().Write() << "Input file: " << extractor_config.input_path.filename().string();
        SimpleLogger().Write() << "Profile: " << extractor_config.profile_path.filename().string();
        SimpleLogger().Write() << "Threads: " << number_of_threads;

        // setup scripting environment
        ScriptingEnvironment scripting_environment(extractor_config.profile_path.string().c_str());

        ExtractionContainers extraction_containers;
        auto extractor_callbacks = osrm::make_unique<ExtractorCallbacks>(extraction_containers);

        const osmium::io::File input_file(extractor_config.input_path.string());
        osmium::io::Reader reader(input_file);
        const osmium::io::Header header = reader.header();

        std::atomic<unsigned> number_of_nodes{0};
        std::atomic<unsigned> number_of_ways{0};
        std::atomic<unsigned> number_of_relations{0};
        std::atomic<unsigned> number_of_others{0};

        SimpleLogger().Write() << "Parsing in progress..";
        TIMER_START(parsing);

        std::string generator = header.get("generator");
        if (generator.empty())
        {
            generator = "unknown tool";
        }
        SimpleLogger().Write() << "input file generated by " << generator;

        // write .timestamp data file
        std::string timestamp = header.get("osmosis_replication_timestamp");
        if (timestamp.empty())
        {
            timestamp = "n/a";
        }
        SimpleLogger().Write() << "timestamp: " << timestamp;

        boost::filesystem::ofstream timestamp_out(extractor_config.timestamp_file_name);
        timestamp_out.write(timestamp.c_str(), timestamp.length());
        timestamp_out.close();

        // initialize vectors holding parsed objects
        tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes;
        tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> resulting_ways;
        tbb::concurrent_vector<mapbox::util::optional<InputRestrictionContainer>>
            resulting_restrictions;

        // setup restriction parser
        const RestrictionParser restriction_parser(scripting_environment.get_lua_state());

        while (const osmium::memory::Buffer buffer = reader.read())
        {
            // create a vector of iterators into the buffer
            std::vector<osmium::memory::Buffer::const_iterator> osm_elements;
            for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter)
            {
                osm_elements.push_back(iter);
            }

            // clear resulting vectors
            resulting_nodes.clear();
            resulting_ways.clear();
            resulting_restrictions.clear();

            // parse OSM entities in parallel, store in resulting vectors
            tbb::parallel_for(
                tbb::blocked_range<std::size_t>(0, osm_elements.size()),
                [&](const tbb::blocked_range<std::size_t> &range)
                {
                    ExtractionNode result_node;
                    ExtractionWay result_way;
                    lua_State *local_state = scripting_environment.get_lua_state();

                    for (auto x = range.begin(); x != range.end(); ++x)
                    {
                        const auto entity = osm_elements[x];

                        switch (entity->type())
                        {
                        case osmium::item_type::node:
                            result_node.clear();
                            ++number_of_nodes;
                            luabind::call_function<void>(
                                local_state, "node_function",
                                boost::cref(static_cast<const osmium::Node &>(*entity)),
                                boost::ref(result_node));
                            resulting_nodes.push_back(std::make_pair(x, result_node));
                            break;
                        case osmium::item_type::way:
                            result_way.clear();
                            ++number_of_ways;
                            luabind::call_function<void>(
                                local_state, "way_function",
                                boost::cref(static_cast<const osmium::Way &>(*entity)),
                                boost::ref(result_way));
                            resulting_ways.push_back(std::make_pair(x, result_way));
                            break;
                        case osmium::item_type::relation:
                            ++number_of_relations;
                            resulting_restrictions.push_back(restriction_parser.TryParse(
                                static_cast<const osmium::Relation &>(*entity)));
                            break;
                        default:
                            ++number_of_others;
                            break;
                        }
                    }
                });

            // put parsed objects thru extractor callbacks
            for (const auto &result : resulting_nodes)
            {
                extractor_callbacks->ProcessNode(
                    static_cast<const osmium::Node &>(*(osm_elements[result.first])),
                    result.second);
            }
            for (const auto &result : resulting_ways)
            {
                extractor_callbacks->ProcessWay(
                    static_cast<const osmium::Way &>(*(osm_elements[result.first])), result.second);
            }
            for (const auto &result : resulting_restrictions)
            {
                extractor_callbacks->ProcessRestriction(result);
            }
        }
        TIMER_STOP(parsing);
        SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";

        SimpleLogger().Write() << "Raw input contains " << number_of_nodes.load() << " nodes, "
                               << number_of_ways.load() << " ways, and "
                               << number_of_relations.load() << " relations, and "
                               << number_of_others.load() << " unknown entities";

        extractor_callbacks.reset();

        if (extraction_containers.all_edges_list.empty())
        {
            SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
            return 1;
        }

        extraction_containers.PrepareData(extractor_config.output_file_name,
                                          extractor_config.restriction_file_name);
        TIMER_STOP(extracting);
        SimpleLogger().Write() << "extraction finished after " << TIMER_SEC(extracting) << "s";
        SimpleLogger().Write() << "To prepare the data for routing, run: "
                               << "./osrm-prepare " << extractor_config.output_file_name
                               << std::endl;
    }
    catch (std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << e.what();
        return 1;
    }
    return 0;
}
Example #6
0
Machine::Machine(const Config& c)
    :p_elements()
    ,p_trace(NULL)
    ,p_info()
{
    std::string type(c.get<std::string>("sim_type"));

    info_mutex_t::scoped_lock G(info_mutex);

    p_state_infos_t::iterator it = p_state_infos.find(type);
    if(it==p_state_infos.end()) {
        std::ostringstream msg;
        msg<<"Unsupport sim_type '"<<type<<"'";
        throw key_error(msg.str());
    }

    p_info = it->second;

    typedef Config::vector_t elements_t;
    elements_t Es(c.get<elements_t>("elements"));

    p_elements_t result;
    result.reserve(Es.size());

    size_t idx=0;
    for(elements_t::iterator it=Es.begin(), end=Es.end(); it!=end; ++it)
    {
        const Config& EC = *it;

        const std::string& etype(EC.get<std::string>("type"));

        state_info::elements_t::iterator eit = p_info.elements.find(etype);
        if(eit==p_info.elements.end())
            throw key_error(etype);

        element_builder_t* builder = eit->second;

        ElementVoid *E;
        try{
            E = builder->build(EC);
        }catch(key_error& e){
            std::ostringstream strm;
            strm<<"Error while initializing element "<<idx<<" '"<<EC.get<std::string>("name", "<invalid>")
               <<"' : missing required parameter '"<<e.what()<<"'";
            throw key_error(strm.str());

        }catch(std::exception& e){
            std::ostringstream strm;
            strm<<"Error while constructing element "<<idx<<" '"<<EC.get<std::string>("name", "<invalid>")
               <<"' : "<<e.what();
            throw std::runtime_error(strm.str());
        }

        *const_cast<size_t*>(&E->index) = idx++; // ugly

        result.push_back(E);
    }

    G.unlock();

    p_elements.swap(result);
}
Example #7
0
void OrderLineEdit::sParse()
{
  bool oldvalid = _valid;
  if (! _parsed)
  {
    QString stripped = text().trimmed().toUpper();
    if (stripped.length() == 0)
    {
      _parsed = true;
      setId(-1);
    }
    else
    {
      QString oldExtraClause = _extraClause;

      XSqlQuery countQ;
      countQ.prepare("SELECT COUNT(*) AS count FROM orderhead WHERE (TRUE) " +
		      _numClause +
		      (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		      QString(";"));
      countQ.bindValue(":number", text());
      countQ.exec();
      if (countQ.first())
      {
	int result = countQ.value("count").toInt();
	if (result <= 0)
	{
	  _id = -1;
	  XLineEdit::clear();
	}
	else if (result == 1)
	{
	  XSqlQuery numQ;
	  numQ.prepare(_query + _numClause +
		      (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		      QString(";"));
	  numQ.bindValue(":number", text());
	  numQ.exec();
	  if (numQ.first())
	  {
	    _valid = true;
	    setId(numQ.value("id").toInt(), numQ.value("name").toString());
	    _description	= numQ.value("description").toString();
	    _from		= numQ.value("orderhead_from").toString();
	    _to		= numQ.value("orderhead_to").toString();
	  }
	  else if (numQ.lastError().type() != QSqlError::NoError)
	    QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
					  .arg(__FILE__)
					  .arg(__LINE__),
				  numQ.lastError().databaseText());
	}
	else
	{
	  _extraClause += "AND (orderhead_number=" + text() + ")";
          sEllipses();
	  _extraClause += "AND (orderhead_type='" + type() + "')";
	}
      }
      else if (countQ.lastError().type() != QSqlError::NoError)
      {
	QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				      .arg(__FILE__)
				      .arg(__LINE__),
			      countQ.lastError().databaseText());
      }

      _extraClause = oldExtraClause;
    }
  }

  _parsed = true;
  if (_valid != oldvalid)
    emit valid(_valid);
  emit parsed();
  emit numberChanged(text(), _name);
}
Example #8
0
bool GField::canCompare(IGCMPObject* pOther)
{
    return type() == pOther->type();
}
Example #9
0
void StructuredScript::Storage::Memory::assign(IAny::Ptr object, IStorage *storage, IExceptionManager *exception, INode *expr){
	auto value = value_.lock();
	if (attributes_ != nullptr){//Validate access
		if (value != nullptr && !Query::Object::isUndefined(value) && (attributes_->hasAttribute(""))){
			Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
				"Cannot modify object!", expr)));

			return;
		}
	}

	auto states = MemoryState(type_->states());
	if ((states.isConstant() || states.isFinal()) && value != nullptr && !Query::Object::isUndefined(value)){//Cannot assign to a const | final memory
		Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
			"Cannot modify memory!", expr)));

		return;
	}

	object = object->base();
	if (object == nullptr || Query::Object::isUndefined(object) || Query::Object::isExpansion(object) || Query::Object::isExpanded(object)){
		Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
			"Cannot assign an invalid object!", expr)));

		return;
	}

	auto type = object->type();
	if (type == nullptr){//Expected type
		Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
			"Expected type of object during assignment!", expr)));

		return;
	}

	bool mustCast;
	if (type_ != nullptr){//Validate assignment
		auto compatibleType = type_->getCompatibleType(type);
		if (compatibleType == nullptr){//Incompatible types -- use type as is
			if (states.isReference() && !states.isRValReference()){//Compatible type required
				Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
					"Incompatible types!", expr)));

				return;
			}

			mustCast = true;
			compatibleType = type_;
		}
		else
			mustCast = false;

		if (states.isReference()){//Get reference
			auto memory = object->memory();
			if (states.isRValReference()){//Value | Reference
				if (mustCast){
					object = object->cast(compatibleType->base(), storage, exception, expr);
					if (Query::ExceptionManager::has(exception))
						return;
				}
				else if (memory != nullptr){
					auto objectType = memory->type();
					auto objectStates = MemoryState((objectType == nullptr) ? MemoryState::STATE_NONE : objectType->states());
					if (!objectStates.isRValReference()){//Only get reference if object is not an rvalue reference
						object = PrimitiveFactory::createReference(memory->ptr());
						dynamic_cast<IDeclaredType *>(type_.get())->states((states -= MemoryState::STATE_RVALUE).states());
					}
				}
			}
			else if (memory == nullptr){//Reference requires an lvalue
				Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
					"Cannot get reference of an rvalue!", expr)));

				return;
			}
			else//Reference
				object = PrimitiveFactory::createReference(memory->ptr());
		}
		else if (!compatibleType->isAny()){//Cast object to compatible type
			object = object->cast(compatibleType->base(), storage, exception, expr);
			if (Query::ExceptionManager::has(exception))
				return;

			if (object == nullptr){//Failed to do conversion
				Query::ExceptionManager::set(exception, PrimitiveFactory::createString(Query::ExceptionManager::combine(
					"Incompatible types!", expr)));

				return;
			}
		}

		if (object->memory() != nullptr)//Create object copy
			object = object->clone(storage, exception, expr);

		if (Query::ExceptionManager::has(exception))
			return;
	}

	assign(object);
}
Example #10
0
type Enum::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new Enum(symbols));
}
Example #11
0
type IntType::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new IntType(min, max));
}
Example #12
0
type TypeVar::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new TypeVar(name));
}
Example #13
0
type SymbolType::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new SymbolType);
}
Example #14
0
type PseudoTypeAny::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new PseudoTypeAny);
}
Example #15
0
    void load(Archive& ar, boost::exception_ptr& e, unsigned int)
    {
        hpx::util::exception_type type(hpx::util::unknown_exception);
        std::string what;
        int err_value = hpx::success;
        std::string err_message;

        boost::uint32_t throw_locality_ = 0;
        std::string throw_hostname_;
        boost::int64_t throw_pid_ = -1;
        std::size_t throw_shepherd_ = 0;
        std::size_t throw_thread_id_ = 0;
        std::string throw_thread_name_;
        std::string throw_function_;
        std::string throw_file_;
        std::string throw_back_trace_;
        int throw_line_ = 0;
        std::string throw_env_;
        std::string throw_config_;
        std::string throw_state_;
        std::string throw_auxinfo_;

        ar & type & what & throw_function_ & throw_file_ & throw_line_
           & throw_locality_ & throw_hostname_ & throw_pid_ & throw_shepherd_
           & throw_thread_id_ & throw_thread_name_ & throw_back_trace_
           & throw_env_ & throw_config_ & throw_state_ & throw_auxinfo_;

        if (hpx::util::hpx_exception == type) {
            ar & err_value;
        }
        else if (hpx::util::boost_system_error == type) {
            ar & err_value & err_message;
        }

        switch (type) {
        default:
        case hpx::util::std_exception:
        case hpx::util::unknown_exception:
            e = hpx::detail::construct_exception(
                    hpx::detail::std_exception(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        // standard exceptions
        case hpx::util::std_runtime_error:
            e = hpx::detail::construct_exception(
                    std::runtime_error(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_invalid_argument:
            e = hpx::detail::construct_exception(
                    std::invalid_argument(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_out_of_range:
            e = hpx::detail::construct_exception(
                    std::out_of_range(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_logic_error:
            e = hpx::detail::construct_exception(
                    std::logic_error(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_bad_alloc:
            e = hpx::detail::construct_exception(
                    hpx::detail::bad_alloc(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_bad_cast:
            e = hpx::detail::construct_exception(
                    hpx::detail::bad_cast(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        case hpx::util::std_bad_typeid:
            e = hpx::detail::construct_exception(hpx::detail::bad_typeid(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;
        case hpx::util::std_bad_exception:
            e = hpx::detail::construct_exception(
                    hpx::detail::bad_exception(what),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        // boost exceptions
        case hpx::util::boost_exception:
            HPX_ASSERT(false);    // shouldn't happen
            break;

        // boost::system::system_error
        case hpx::util::boost_system_error:
            e = hpx::detail::construct_exception(
                    boost::system::system_error(err_value,
#ifndef BOOST_SYSTEM_NO_DEPRECATED
                        boost::system::get_system_category()
#else
                        boost::system::system_category()
#endif
                      , err_message
                    )
                  , throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        // hpx::exception
        case hpx::util::hpx_exception:
            e = hpx::detail::construct_exception(
                    hpx::exception(static_cast<hpx::error>(err_value),
                        what, hpx::rethrow),
                    throw_function_, throw_file_, throw_line_, throw_back_trace_,
                    throw_locality_, throw_hostname_, throw_pid_,
                    throw_shepherd_, throw_thread_id_, throw_thread_name_,
                    throw_env_, throw_config_, throw_state_, throw_auxinfo_);
            break;

        // hpx::thread_interrupted
        case hpx::util::hpx_thread_interrupted_exception:
            e = hpx::detail::construct_lightweight_exception(
                hpx::thread_interrupted());
            break;
        }
    }
 /// Returns the type number for the element at position `pos`.
 inline uint16_t type_nr(size_t pos) const noexcept {
   return type(pos).first;
 }
Example #17
0
    void save(Archive& ar, boost::exception_ptr const& ep, unsigned int)
    {
        hpx::util::exception_type type(hpx::util::unknown_exception);
        std::string what;
        int err_value = hpx::success;
        std::string err_message;

        boost::uint32_t throw_locality_ = 0;
        std::string throw_hostname_;
        boost::int64_t throw_pid_ = -1;
        std::size_t throw_shepherd_ = 0;
        std::size_t throw_thread_id_ = 0;
        std::string throw_thread_name_;
        std::string throw_function_;
        std::string throw_file_;
        std::string throw_back_trace_;
        int throw_line_ = 0;
        std::string throw_env_;
        std::string throw_config_;
        std::string throw_state_;
        std::string throw_auxinfo_;

        // retrieve information related to boost::exception
        try {
            boost::rethrow_exception(ep);
        }
        catch (boost::exception const& e) {
            char const* const* func =
                boost::get_error_info<boost::throw_function>(e);
            if (func) {
                throw_function_ = *func;
            }
            else {
                std::string const* s =
                    boost::get_error_info<hpx::detail::throw_function>(e);
                if (s)
                    throw_function_ = *s;
            }

            char const* const* file =
                boost::get_error_info<boost::throw_file>(e);
            if (file) {
                throw_file_ = *file;
            }
            else {
                std::string const* s =
                    boost::get_error_info<hpx::detail::throw_file>(e);
                if (s)
                    throw_file_ = *s;
            }

            int const* line =
                boost::get_error_info<boost::throw_line>(e);
            if (line)
                throw_line_ = *line;

            boost::uint32_t const* locality =
                boost::get_error_info<hpx::detail::throw_locality>(e);
            if (locality)
                throw_locality_ = *locality;

            std::string const* hostname_ =
                boost::get_error_info<hpx::detail::throw_hostname>(e);
            if (hostname_)
                throw_hostname_ = *hostname_;

            boost::int64_t const* pid_ =
                boost::get_error_info<hpx::detail::throw_pid>(e);
            if (pid_)
                throw_pid_ = *pid_;

            std::size_t const* shepherd =
                boost::get_error_info<hpx::detail::throw_shepherd>(e);
            if (shepherd)
                throw_shepherd_ = *shepherd;

            std::size_t const* thread_id =
                boost::get_error_info<hpx::detail::throw_thread_id>(e);
            if (thread_id)
                throw_thread_id_ = *thread_id;

            std::string const* thread_name =
                boost::get_error_info<hpx::detail::throw_thread_name>(e);
            if (thread_name)
                throw_thread_name_ = *thread_name;

            std::string const* back_trace =
                boost::get_error_info<hpx::detail::throw_stacktrace>(e);
            if (back_trace)
                throw_back_trace_ = *back_trace;

            std::string const* env_ =
                boost::get_error_info<hpx::detail::throw_env>(e);
            if (env_)
                throw_env_ = *env_;

            std::string const* config_ =
                boost::get_error_info<hpx::detail::throw_config>(e);
            if (config_)
                throw_config_ = *config_;

            std::string const* state_ =
                boost::get_error_info<hpx::detail::throw_state>(e);
            if (state_)
                throw_state_ = *state_;

            std::string const* auxinfo_ =
                boost::get_error_info<hpx::detail::throw_auxinfo>(e);
            if (auxinfo_)
                throw_auxinfo_ = *auxinfo_;
        }

        // figure out concrete underlying exception type
        try {
            boost::rethrow_exception(ep);
        }
        catch (hpx::thread_interrupted const&) {
            type = hpx::util::hpx_thread_interrupted_exception;
            what = "hpx::thread_interrupted";
            err_value = hpx::thread_cancelled;
        }
        catch (hpx::exception const& e) {
            type = hpx::util::hpx_exception;
            what = e.what();
            err_value = e.get_error();
        }
        catch (boost::system::system_error const& e) {
            type = hpx::util::boost_system_error;
            what = e.what();
            err_value = e.code().value();
            err_message = e.code().message();
        }
        catch (std::runtime_error const& e) {
            type = hpx::util::std_runtime_error;
            what = e.what();
        }
        catch (std::invalid_argument const& e) {
            type = hpx::util::std_invalid_argument;
            what = e.what();
        }
        catch (std::out_of_range const& e) {
            type = hpx::util::std_out_of_range;
            what = e.what();
        }
        catch (std::logic_error const& e) {
            type = hpx::util::std_logic_error;
            what = e.what();
        }
        catch (std::bad_alloc const& e) {
            type = hpx::util::std_bad_alloc;
            what = e.what();
        }
        catch (std::bad_cast const& e) {
            type = hpx::util::std_bad_cast;
            what = e.what();
        }
        catch (std::bad_typeid const& e) {
            type = hpx::util::std_bad_typeid;
            what = e.what();
        }
        catch (std::bad_exception const& e) {
            type = hpx::util::std_bad_exception;
            what = e.what();
        }
        catch (std::exception const& e) {
            type = hpx::util::std_exception;
            what = e.what();
        }
        catch (boost::exception const& e) {
            type = hpx::util::boost_exception;
            what = boost::diagnostic_information(e);
        }
        catch (...) {
            type = hpx::util::unknown_exception;
            what = "unknown exception";
        }

        ar & type & what & throw_function_ & throw_file_ & throw_line_
           & throw_locality_ & throw_hostname_ & throw_pid_ & throw_shepherd_
           & throw_thread_id_ & throw_thread_name_ & throw_back_trace_
           & throw_env_ & throw_config_ & throw_state_ & throw_auxinfo_;

        if (hpx::util::hpx_exception == type) {
            ar & err_value;
        }
        else if (hpx::util::boost_system_error == type) {
            ar & err_value & err_message;
        }
    }
dogen::formatters::file class_header_formatter_stitch(
    formatters::entity_formatting_assistant& fa,
    const formattables::class_info& c) {

    {
        auto sbf(fa.make_scoped_boilerplate_formatter());
        {
            auto snf(fa.make_scoped_namespace_formatter());
            fa.stream() << std::endl;
            fa.comment(c.documentation());
            if (c.parents().empty()) {
                fa.stream() << "class " << c.name() << " " << fa.make_final_keyword_text(c) << "{" << std::endl;
            } else if (c.parents().size() == 1) {
                fa.stream() << "class " << c.name() << " " << fa.make_final_keyword_text(c) << ": public " << c.parents().front().qualified_name() << " {" << std::endl;
            } else {
                dogen::formatters::sequence_formatter sf(c.parents().size());
                for (const auto p : c.parents()) {
                    fa.stream() << "    public " << p.qualified_name() << sf.postfix() << std::endl;
                    sf.next();
                }
            }
            fa.stream() << "public:" << std::endl;
            /*
             * Compiler generated constructors and destructors.
             */
            if (!c.requires_manual_default_constructor())
                fa.stream() << "    " << c.name() << "() = default;" << std::endl;
            fa.stream() << "    " << c.name() << "(const " << c.name() << "&) = default;" << std::endl;
            if (!c.requires_manual_move_constructor())
                fa.stream() << "    " << c.name() << "(" << c.name() << "&&) = default;" << std::endl;
            if (!c.is_parent() && c.parents().empty())
                fa.stream() << "    ~" << c.name() << "() = default;" << std::endl;
            if (c.is_immutable())
                fa.stream() << "    " << c.name() << "& operator=(const " << c.name() << "&) = delete;" << std::endl;
            else if (c.all_properties().empty())
                fa.stream() << "    " << c.name() << "& operator=(const " << c.name() << "&) = default;" << std::endl;
            fa.stream() << std::endl;
            /*
             * Manually generated default constructor.
             */
            if (c.requires_manual_default_constructor()) {
                fa.stream() << "public:" << std::endl;
                fa.stream() << "    " << c.name() << "();" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Manually generated destructor.
             *
             * according to MEC++, item 33, base classes should always be
             * abstract. this avoids all sorts of tricky problems with
             * assignment and swap.
             *
             * incidentally, this also fixes some strange clang errors:
             * undefined reference to `vtable.
             */
            if (c.is_parent()) {
                fa.stream() << "    virtual ~" << c.name() << "() noexcept = 0;" << std::endl;
                fa.stream() << std::endl;
            } else if (c.parents().size() != 0) {
                fa.stream() << "    virtual ~" << c.name() << "() noexcept { }" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Manually generated move constructor.
             */
            if (c.requires_manual_move_constructor()) {
                fa.stream() << "public:" << std::endl;
                fa.stream() << "    " << c.name() << "(" << c.name() << "&& rhs);" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Manually generated complete constructor.
             */
            if (!fa.is_complete_constructor_disabled() && !c.all_properties().empty()) {
                fa.stream() << "public:" << std::endl;
                const auto prop_count(c.all_properties().size());
                if (prop_count == 1) {
                    const auto p(*c.all_properties().begin());
                    fa.stream() << "    explicit " << c.name() << "(const " << p.type().complete_name() << fa.make_by_ref_text(p) << " " << p.name() << ");" << std::endl;
                } else {
                    fa.stream() << "    " << c.name() << "(" << std::endl;
                    dogen::formatters::sequence_formatter sf(prop_count);
                    sf.postfix_configuration().last(");");
                    for (const auto& p : c.all_properties()) {
                        fa.stream() << "        const " << p.type().complete_name() << fa.make_by_ref_text(p) << " " << p.name() << sf.postfix() << std::endl;
                        sf.next();
                    }
                }
                fa.stream() << std::endl;
            }

            /*
             * Friends
             */
            if (fa.is_serialization_enabled()) {
                fa.stream() << "private:" << std::endl;
                fa.stream() << "    template<typename Archive>" << std::endl;
                fa.stream() << "    friend void boost::serialization::save(Archive& ar, const " << c.name() << "& v, unsigned int version);" << std::endl;
                fa.stream() << std::endl;
                fa.stream() << "    template<typename Archive>" << std::endl;
                fa.stream() << "    friend void boost::serialization::load(Archive& ar, " << c.name() << "& v, unsigned int version);" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Visitation.
             */
            if (c.is_visitable()) {
                fa.stream() << "public:" << std::endl;
                fa.stream() << "    virtual void accept(const " << c.name() << "_visitor& v) const = 0;" << std::endl;
                fa.stream() << "    virtual void accept(" << c.name() << "_visitor& v) const = 0;" << std::endl;
                fa.stream() << "    virtual void accept(const " << c.name() << "_visitor& v) = 0;" << std::endl;
                fa.stream() << "    virtual void accept(" << c.name() << "_visitor& v) = 0;" << std::endl;
                fa.stream() << std::endl;
            } else if (c.is_original_parent_visitable() && !c.is_parent()) {
                fa.stream() << "public:" << std::endl;
                fa.stream() << "    virtual void accept(const " << c.original_parent_name() << "_visitor& v) const override {" << std::endl;
                fa.stream() << "        v.visit(*this);" << std::endl;
                fa.stream() << "    }" << std::endl;
                fa.stream() << std::endl;
                fa.stream() << "    virtual void accept(" << c.original_parent_name() << "_visitor& v) const override {" << std::endl;
                fa.stream() << "        v.visit(*this);" << std::endl;
                fa.stream() << "    }" << std::endl;
                fa.stream() << std::endl;
                fa.stream() << "    virtual void accept(const " << c.original_parent_name() << "_visitor& v) override {" << std::endl;
                fa.stream() << "        v.visit(*this);" << std::endl;
                fa.stream() << "    }" << std::endl;
                fa.stream() << std::endl;
                fa.stream() << "    virtual void accept(" << c.original_parent_name() << "_visitor& v) override {" << std::endl;
                fa.stream() << "        v.visit(*this);" << std::endl;
                fa.stream() << "    }" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Streaming
             */
            if (fa.is_io_enabled()) {
                if (c.is_parent()) {
                    fa.stream() << "public:" << std::endl;
                    fa.stream() << "    virtual void to_stream(std::ostream& s) const;" << std::endl;
                    fa.stream() << std::endl;
                } else if (!c.parents().empty()) {
                    fa.stream() << "public:" << std::endl;
                    fa.stream() << "    void to_stream(std::ostream& s) const override;" << std::endl;
                    fa.stream() << std::endl;
                }
            }

            /*
             * Getters and setters.
             */
            if (!c.properties().empty()) {
                fa.stream() << "public:" << std::endl;
                for (const auto p : c.properties()) {
                    fa.comment_start_method_group(p.documentation(), !p.is_immutable());

                    if (p.type().is_primitive() || p.type().is_enumeration()) {
                        fa.stream() << "    " << p.type().complete_name() << " " << p.name() << "() const;" << std::endl;
                        if (p.is_immutable()) {
                            fa.stream() << std::endl;
                            continue;
                        }
                        fa.stream() << "    " << fa.make_setter_return_type(c.name(), p) << " " << p.name() << "(const " << p.type().complete_name() << fa.make_by_ref_text(p) << " v);" << std::endl;
                    } else {
                        fa.stream() << "    const " << p.type().complete_name() << "& " << p.name() << "() const;" << std::endl;
                        if (p.is_immutable()) {
                            fa.stream() << std::endl;
                            continue;
                        }
                        fa.stream() << "    " << p.type().complete_name() << fa.make_by_ref_text(p) << " " << p.name() << "();" << std::endl;
                        fa.stream() << "    " << fa.make_setter_return_type(c.name(), p) << " " << p.name() << "(const " << p.type().complete_name() << fa.make_by_ref_text(p) << " v);" << std::endl;
                        fa.stream() << "    " << fa.make_setter_return_type(c.name(), p) << " " << p.name() << "(const " << p.type().complete_name() << "&& v);" << std::endl;
                    }
                    fa.comment_end_method_group(p.documentation(), !p.is_immutable());
                    fa.stream() << std::endl;
                }
            }

            /*
             * Equality.
             *
             * Equality is only public in leaf classes - MEC++-33.
             */
            if (c.is_parent()) {
                fa.stream() << "protected:" << std::endl;
                fa.stream() << "    bool compare(const " << c.name() << "& rhs) const;" << std::endl;
            } else {
                fa.stream() << "public:" << std::endl;
                fa.stream() << "    bool operator==(const " << c.name() << "& rhs) const;" << std::endl;
                fa.stream() << "    bool operator!=(const " << c.name() << "& rhs) const {" << std::endl;
                fa.stream() << "        return !this->operator==(rhs);" << std::endl;
                fa.stream() << "    }" << std::endl;
                fa.stream() << std::endl;
            }

            if (c.is_parent() || !c.parents().empty()) {
                fa.stream() << "public:" << std::endl;
                if (c.is_parent() && c.parents().empty()) {
                    fa.stream() << "    virtual bool equals(const " << c.name() << "& other) const = 0;" << std::endl;
                } else if (c.is_parent()) {
                    fa.stream() << "    virtual bool equals(const " << c.original_parent_name_qualified() << "& other) const = 0;" << std::endl;
                } else if (!c.parents().empty()) {
                    fa.stream() << "    bool equals(const " << c.original_parent_name_qualified() << "& other) const override;" << std::endl;
                }
                fa.stream() << std::endl;
            }

            /*
             * Swap and assignment.
             *
             * Swap and assignment are only public in leaf classes - MEC++-33
             */
            if ((!c.all_properties().empty() || c.is_parent()) && !c.is_immutable()) {
                if (c.is_parent()) {
                    fa.stream() << "protected:" << std::endl;
                } else {
                    fa.stream() << "public:" << std::endl;
                }
                fa.stream() << "    void swap(" << c.name() << "& other) noexcept;" << std::endl;
                if (!c.is_parent() && !c.is_immutable()) {
                    fa.stream() << "    " << c.name() << "& operator=(" << c.name() << " other);" << std::endl;
                }
                fa.stream() << std::endl;
            }

            /*
             * Member variables.
             */
            if (!c.properties().empty()) {
                fa.stream() << "private:" << std::endl;
                for (const auto& p : c.properties()) {
                    fa.stream() << "    " << p.type().complete_name() << " " << fa.make_member_variable_name(p) << ";" << std::endl;
                }
            }
            fa.stream() << "};" << std::endl;
            fa.stream() << std::endl;
            /*
             * Destructor implementation.
             */
            if (c.is_parent()) {
                fa.stream() << "inline " << c.name() << "::~" << c.name() << "() noexcept { }" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Global inserter operator implementation
             */
            if (fa.is_io_enabled() && fa.is_io_integrated()) {
                fa.stream() << "    std::ostream& operator<<(std::ostream& s, const " << c.name() << "& v);" << std::endl;
                fa.stream() << std::endl;
            }

            /*
             * Global equality operator implementation.
             */
            if (c.is_parent()) {
                fa.stream() << "inline bool operator==(const " << c.name() << "& lhs, const " << c.name() << "& rhs) {" << std::endl;
                fa.stream() << "    return lhs.equals(rhs);" << std::endl;
                fa.stream() << "}" << std::endl;
                fa.stream() << std::endl;
            }
        }

        if (!c.all_properties().empty() && !c.is_parent() && !c.is_immutable()) {
            fa.stream() << std::endl;
            fa.stream() << "namespace std {" << std::endl;
            fa.stream() << std::endl;
            fa.stream() << "template<>" << std::endl;
            fa.stream() << "inline void swap(" << std::endl;
            fa.stream() << "    " << c.qualified_name() << "& lhs," << std::endl;
            fa.stream() << "    " << c.qualified_name() << "& rhs) {" << std::endl;
            fa.stream() << "    lhs.swap(rhs);" << std::endl;
            fa.stream() << "}" << std::endl;
            fa.stream() << std::endl;
            fa.stream() << "}" << std::endl;
        } // snf
        fa.stream() << std::endl;
    } // sbf
    return fa.make_file();
}
Example #19
0
void OrderCluster::sRefresh()
{
  VirtualCluster::sRefresh();

  _grid->removeWidget(_fromLit);
  _grid->removeWidget(_toLit);
  _grid->removeWidget(_from);
  _grid->removeWidget(_to);

  if (type() == "PO")
  {
    _grid->addWidget(_fromLit,	2, 1);
    _grid->addWidget(_from,	2, 2, 1, -1);
    _grid->addWidget(_toLit,	2, 0);
    _grid->addWidget(_to,	2, 0);

    _fromLit->setText("Vendor:");
    _toLit->setText("");
  }
  else if (type() == "RA")
  {
    _grid->addWidget(_fromLit,	2, 1);
    _grid->addWidget(_from,	2, 2, 1, -1);
    _grid->addWidget(_toLit,	2, 0);
    _grid->addWidget(_to,	2, 0);

    _fromLit->setText("Customer:");
    _toLit->setText("");
  }
  else if (type() == "SO")
  {
    _grid->addWidget(_fromLit,	2, 0);
    _grid->addWidget(_from,	2, 0);
    _grid->addWidget(_toLit,	2, 1);
    _grid->addWidget(_to,	2, 2, 1, -1);

    _fromLit->setText("");
    _toLit->setText("Customer:");
  }
  else if (type() == "TO")
  {
    _grid->addWidget(_fromLit,	2, 1);
    _grid->addWidget(_from,	2, 2);
    _grid->addWidget(_toLit,	2, 3);
    _grid->addWidget(_to,	2, 4);

    _fromLit->setText(tr("From:"));
    _toLit->setText(tr("To:"));
  }
  else
  {
    _grid->addWidget(_fromLit,	2, 1);
    _grid->addWidget(_from,	2, 2);
    _grid->addWidget(_toLit,	2, 3);
    _grid->addWidget(_to,	2, 4);

    _fromLit->setText("");
    _toLit->setText("");
  }

  _from->setText(((OrderLineEdit*)_number)->from());
  _to->setText(((OrderLineEdit*)_number)->to());
}
Example #20
0
 /** @brief Set whether this layer is actually shared by other nets
  *         If ShareInParallel() is true and using more than one GPU and the
  *         net has TRAIN phase, then is_shared should be set true.
  */
 inline void SetShared(bool is_shared) {
   CHECK(ShareInParallel() || !is_shared)
       << type() << "Layer does not support sharing.";
   is_shared_ = is_shared;
 }
Example #21
0
void OrderLineEdit::silentSetId(const int pId)
{
  if (pId == -1)
    XLineEdit::clear();
  else
  {
    QString oldExtraClause = _extraClause;

    XSqlQuery countQ;
    countQ.prepare("SELECT COUNT(*) AS count FROM orderhead WHERE (TRUE) " + _idClause +
		    (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		    QString(";"));
    countQ.bindValue(":id", pId);
    countQ.exec();
    if (countQ.first())
    {
      int result = countQ.value("count").toInt();
      if (result <= 0)
      {
	_id = -1;
	XLineEdit::clear();
      }
      else if (result == 1)
	_id = pId;
      else
      {
	_extraClause += "AND (orderhead_id=" + QString::number(pId) + ")";
        sEllipses();
	_extraClause += "AND (orderhead_type='" + type() + "')";
      }
    }
    else if (countQ.lastError().type() != QSqlError::NoError)
    {
      QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				    .arg(__FILE__)
				    .arg(__LINE__),
			    countQ.lastError().databaseText());
    }

    if (_id > 0)
    {
      XSqlQuery idQ;
      idQ.prepare(_query + _idClause +
		  (_extraClause.isEmpty() || !_strict ? "" : " AND " + _extraClause) +
		  QString(";"));
      idQ.bindValue(":id", pId);
      idQ.exec();
      if (idQ.first())
      {
	_id = pId;
	_valid = true;
	setText(idQ.value("number").toString());
	_name		= idQ.value("name").toString();
	_description	= idQ.value("description").toString();
	_from		= idQ.value("orderhead_from").toString();
	_to		= idQ.value("orderhead_to").toString();
      }
      else if (idQ.lastError().type() != QSqlError::NoError)
	QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
				      .arg(__FILE__)
				      .arg(__LINE__),
			      idQ.lastError().databaseText());
    }
  }

  _parsed = TRUE;
  emit parsed();
}
/*!
    Returns true if this feedback has the same parameters as the feedback
    \a feedback, otherwise returns false.
*/
bool HbAbstractFeedback::operator==(const HbAbstractFeedback &feedback) const
{
    return (d->cRect == feedback.rect()
            && d->cWindow == feedback.window()
            && type() == feedback.type());
}
Example #23
0
bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
{
    bool    bStatic = false;
    int     mProtect = PR_PUBLIC;
    bool    bSynchro = false;

    while (IsOfType(p, ID_SEP)) ;

    CBotTypResult   type( -1 );

    if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true;
    CBotToken*      pBase = p;

    if ( IsOfType(p, ID_STATIC) ) bStatic = true;
    if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
    if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
    if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
    if ( IsOfType(p, ID_STATIC) ) bStatic = true;

//  CBotClass* pClass = NULL;
    type = TypeParam(p, pStack);        // type of the result

    if ( type.Eq(-1) )
    {
        pStack->SetError(TX_NOTYP, p);
        return false;
    }

    while (pStack->IsOk()) 
    {
        CBotToken*  pp = p;
        IsOfType(p, ID_NOT);    // skips ~ eventual (destructor)

        if (IsOfType(p, TokenTypVar))
        {
            CBotInstr* limites = NULL;
            while ( IsOfType( p, ID_OPBRK ) )   // a table?
            {
                CBotInstr* i = NULL;

                if ( p->GetType() != ID_CLBRK )
                    i = CBotExpression::Compile( p, pStack );           // expression for the value
                else
                    i = new CBotEmpty();                            // special if not a formula

                type = CBotTypResult(CBotTypArrayPointer, type);

                if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
                {
                    pStack->SetError(TX_CLBRK, p->GetStart());
                    return false;
                }

/*              CBotVar* pv = pStack->GetVar();
                if ( pv->GetType()>= CBotTypBoolean )
                {
                    pStack->SetError(TX_BADTYPE, p->GetStart());
                    return false;
                }*/

                if (limites == NULL) limites = i;
                else limites->AddNext3(i);
            }

            if ( p->GetType() == ID_OPENPAR )
            {
                if ( !bSecond )
                {
                    p = pBase;
                    CBotFunction* f = 
                    CBotFunction::Compile1(p, pStack, this);

                    if ( f == NULL ) return false;

                    if (m_pMethod == NULL) m_pMethod = f;
                    else m_pMethod->AddNext(f);
                }
                else
                {
                    // return a method precompiled in pass 1
                    CBotFunction*   pf = m_pMethod;
                    CBotFunction*   prev = NULL;
                    while ( pf != NULL ) 
                    {
                        if (pf->GetName() == pp->GetString()) break;
                        prev = pf;
                        pf = pf->Next();
                    }

                    bool bConstructor = (pp->GetString() == GetName());
                    CBotCStack* pile = pStack->TokenStack(NULL, true);

                    // make "this" known
                    CBotToken TokenThis(CBotString("this"), CBotString());
                    CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
                    pThis->SetUniqNum(-2);
                    pile->AddVar(pThis);

                    if ( m_pParent )
                    {
                        // makes "super" known
                        CBotToken TokenSuper(CBotString("super"), CBotString());
                        CBotVar* pThis = CBotVar::Create(&TokenSuper, CBotTypResult( CBotTypClass, m_pParent ) );
                        pThis->SetUniqNum(-3);
                        pile->AddVar(pThis);
                    }

//                  int num = 1;
                    CBotClass*  my = this;
                    while (my != NULL)
                    {
                        // places a copy of variables of a class (this) on a stack
                        CBotVar* pv = my->m_pVar;
                        while (pv != NULL)
                        {
                            CBotVar* pcopy = CBotVar::Create(pv);
                            pcopy->SetInit(!bConstructor || pv->IsStatic());
                            pcopy->SetUniqNum(pv->GetUniqNum());
                            pile->AddVar(pcopy);
                            pv = pv->GetNext();
                        }
                        my = my->m_pParent;
                    }

                    // compiles a method
                    p = pBase;
                    CBotFunction* f = 
                    CBotFunction::Compile(p, pile, NULL/*, false*/);

                    if ( f != NULL )
                    {
                        f->m_pProg = pStack->GetBotCall();
                        f->m_bSynchro = bSynchro;
                        // replaces the element in the chain
                        f->m_next = pf->m_next;
                        pf->m_next = NULL;
                        delete pf;
                        if (prev == NULL) m_pMethod = f;
                        else prev->m_next = f;
                    }
                    pStack->Return(NULL, pile);
                }

                return pStack->IsOk();
            }

            // definition of an element
            if (type.Eq(0))
            {
                pStack->SetError(TX_ENDOF, p);
                return false;
            }

            CBotInstr* i = NULL;
            if ( IsOfType(p, ID_ASS ) )
            {
                if ( type.Eq(CBotTypArrayPointer) )
                {
                    i = CBotListArray::Compile(p, pStack, type.GetTypElem());
                }
                else
                {
                    // it has an assignmet to calculate
                    i = CBotTwoOpExpr::Compile(p, pStack);
                }
                if ( !pStack->IsOk() ) return false;
            }


            if ( !bSecond )
            {
                CBotVar*    pv = CBotVar::Create(pp->GetString(), type);
                pv -> SetStatic( bStatic );
                pv -> SetPrivate( mProtect );

                AddItem( pv );

                pv->m_InitExpr = i;
                pv->m_LimExpr = limites;


                if ( pv->IsStatic() && pv->m_InitExpr != NULL )
                {
                    CBotStack* pile = CBotStack::FirstStack();              // independent stack
                    while(pile->IsOk() && !pv->m_InitExpr->Execute(pile));  // evaluates the expression without timer
                    pv->SetVal( pile->GetVar() ) ;
                    pile->Delete();
                }
            }
            else
                delete i;

            if ( IsOfType(p, ID_COMMA) ) continue;
            if ( IsOfType(p, ID_SEP) ) break;
        }
        pStack->SetError(TX_ENDOF, p);
    }
    return pStack->IsOk();
}
Example #24
0
//
// Convert one type to another.
//
// Returns the node representing the conversion, which could be the same
// node passed in if no conversion was needed.
//
// Return 0 if a conversion can't be done.
//
TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TIntermTyped* node)
{
    //
    // Does the base type allow operation?
    //
    switch (node->getBasicType()) {
    case EbtVoid:
    case EbtSampler1D:
    case EbtSampler2D:
    case EbtSampler3D:
    case EbtSamplerCube:
    case EbtSampler1DShadow:
    case EbtSampler2DShadow:
    case EbtSamplerRect:        // ARB_texture_rectangle
    case EbtSamplerRectShadow:  // ARB_texture_rectangle
        return 0;
    default: break;
    }

    //
    // Otherwise, if types are identical, no problem
    //
    if (type == node->getType())
        return node;

    //
    // If one's a structure, then no conversions.
    //
    if (type.getStruct() || node->getType().getStruct())
        return 0;

    //
    // If one's an array, then no conversions.
    //
    if (type.isArray() || node->getType().isArray())
        return 0;

    TBasicType promoteTo;
    
    switch (op) {
    //
    // Explicit conversions
    //
    case EOpConstructBool:
        promoteTo = EbtBool;
        break;
    case EOpConstructFloat:
        promoteTo = EbtFloat;
        break;
    case EOpConstructInt:
        promoteTo = EbtInt;
        break;
    default:
        //
        // implicit conversions were removed from the language.
        //
        if (type.getBasicType() != node->getType().getBasicType())
            return 0;
        //
        // Size and structure could still differ, but that's
        // handled by operator promotion.
        //
        return node;
    }
    
    if (node->getAsConstantUnion()) {

        return (promoteConstantUnion(promoteTo, node->getAsConstantUnion()));
    } else {
    
        //
        // Add a new newNode for the conversion.
        //
        TIntermUnary* newNode = 0;

        TOperator newOp = EOpNull;
        switch (promoteTo) {
        case EbtFloat:
            switch (node->getBasicType()) {
            case EbtInt:   newOp = EOpConvIntToFloat;  break;
            case EbtBool:  newOp = EOpConvBoolToFloat; break;
            default: 
                infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
                return 0;
            }
            break;
        case EbtBool:
            switch (node->getBasicType()) {
            case EbtInt:   newOp = EOpConvIntToBool;   break;
            case EbtFloat: newOp = EOpConvFloatToBool; break;
            default: 
                infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
                return 0;
            }
            break;
        case EbtInt:
            switch (node->getBasicType()) {
            case EbtBool:   newOp = EOpConvBoolToInt;  break;
            case EbtFloat:  newOp = EOpConvFloatToInt; break;
            default: 
                infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
                return 0;
            }
            break;
        default: 
            infoSink.info.message(EPrefixInternalError, "Bad promotion type", node->getLine());
            return 0;
        }

        TType type(promoteTo, EvqTemporary, node->getNominalSize(), node->isMatrix(), node->isArray());
        newNode = new TIntermUnary(newOp, type);
        newNode->setLine(node->getLine());
        newNode->setOperand(node);

        return newNode;
    }
}
Example #25
0
uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
#endif
  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;
  chipSelectPin_ = chipSelectPin;
  // 16-bit init start time allows over a minute
  uint16_t t0 = (uint16_t)millis();
  uint32_t arg;

  // set pin modes
  pinMode(chipSelectPin_, OUTPUT);
  digitalWrite(chipSelectPin_, HIGH);
#ifndef USE_SPI_LIB
  pinMode(SPI_MISO_PIN, INPUT);
  pinMode(SPI_MOSI_PIN, OUTPUT);
  pinMode(SPI_SCK_PIN, OUTPUT);
#endif

#ifndef SOFTWARE_SPI
#ifndef USE_SPI_LIB
  // SS must be in output mode even it is not chip select
  pinMode(SS_PIN, OUTPUT);
  digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin
  // Enable SPI, Master, clock rate f_osc/128
  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);
  // clear double speed
  SPSR &= ~(1 << SPI2X);
#else // USE_SPI_LIB
  SPI.begin();
  settings = SPISettings(250000, MSBFIRST, SPI_MODE0);
#endif // USE_SPI_LIB
#endif // SOFTWARE_SPI

  // must supply min of 74 clock cycles with CS high.
#ifdef USE_SPI_LIB
  SPI.beginTransaction(settings);
#endif
  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);
#ifdef USE_SPI_LIB
  SPI.endTransaction();
#endif

  chipSelectLow();

  // command to go idle in SPI mode
  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
    if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }
  // check SD version
  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {
    type(SD_CARD_TYPE_SD1);
  } else {
    // only need last byte of r7 response
    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
    if (status_ != 0XAA) {
      error(SD_CARD_ERROR_CMD8);
      goto fail;
    }
    type(SD_CARD_TYPE_SD2);
  }
  // initialize card and send host supports SDHC if SD2
  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;

  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
    // check for timeout
    if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {
      error(SD_CARD_ERROR_ACMD41);
      goto fail;
    }
  }
  // if SD2 read OCR register to check for SDHC card
  if (type() == SD_CARD_TYPE_SD2) {
    if (cardCommand(CMD58, 0)) {
      error(SD_CARD_ERROR_CMD58);
      goto fail;
    }
    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);
    // discard rest of ocr - contains allowed voltage range
    for (uint8_t i = 0; i < 3; i++) spiRec();
  }
  chipSelectHigh();

#ifndef SOFTWARE_SPI
  return setSckRate(sckRateID);
#else  // SOFTWARE_SPI
  return true;
#endif  // SOFTWARE_SPI

 fail:
  chipSelectHigh();
  return false;
}
Example #26
0
    bool startElement(const QString &namespaceURI,
                      const QString &localName,
                      const QString &qName,
                      const QXmlAttributes &attributes)
    {
        // add to elements stack:
        m_elementStack.append(new ElementData(qName.utf8()));

        // First we need a node.
        if (DBUS("node"))
        {
            CONDITION(!m_currentNode.isEmpty(), "Node inside a node.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QCString("Anonymous node found."));

            m_currentNode = attributes.value(idx).utf8();
            // A node is actually of little interest, so do nothing here.
            return true;
        }

        // Then we need an interface.
        if (DBUS("interface"))
        {
            // We need a nodeName for interfaces:
            CONDITION(m_currentNode.isEmpty(), "Interface without a node.");
            CONDITION(m_currentInterface, "Interface within another interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Interface without a name found."));

            // A interface is roughly equivalent to a class:
            m_currentInterface = createEntry();

            m_currentInterface->section = Entry::CLASS_SEC;
            m_currentInterface->spec |= Entry::Interface;
            m_currentInterface->type = "Interface";
            m_currentInterface->name = substitute(attributes.value(idx).utf8(), ".", "::");

            openScopes(m_currentInterface);

            return true;
        }

        if (DBUS("method") || DBUS("signal"))
        {
            // We need a interfaceName for methods and signals:
            CONDITION(!m_currentInterface, "Method or signal found outside a interface.");
            CONDITION(m_currentMethod, "Method or signal found inside another method or signal.");
            CONDITION(m_currentProperty, "Methor or signal found inside a property.");
            CONDITION(!m_structStack.isEmpty(), "Method or signal found inside a struct.");
            CONDITION(m_currentEnum, "Methor or signal found inside a enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Method or signal without a name found."));

            m_currentMethod = createEntry();

            m_currentMethod->section = Entry::FUNCTION_SEC;
            m_currentMethod->name = attributes.value(idx).utf8();
            m_currentMethod->mtype = Method;
            m_currentMethod->type = "void";

            if (DBUS("signal"))
            { m_currentMethod->mtype = Signal; }
        }

        if (DBUS("arg"))
        {
            // We need a method for arguments:
            CONDITION(!m_currentMethod, "Argument found outside a method or signal.");
            CONDITION(m_currentArgument, "Argument found inside another argument.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Argument without a name found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Argument without a type found."));

            const int direction_idx(indexOf(attributes, "direction"));

            if ((m_currentMethod->mtype == Signal &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in") ||
                (m_currentMethod->mtype == Method &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in" &&
                 attributes.value(direction_idx) != "out"))
            {
                m_errorString = "Invalid direction found.";
                return false;
            }

            m_currentArgument = new Argument;
            m_currentArgument->type = getType(attributes).utf8();
            m_currentArgument->name = attributes.value(name_idx).utf8();
            if (direction_idx >= 0)
            { m_currentArgument->attrib = attributes.value(direction_idx).utf8(); }
            else
            {
                if (m_currentMethod->mtype == Signal)
                { m_currentArgument->attrib = "in"; }
                else
                { m_currentArgument->attrib = "out"; }
            }
        }

        if (DBUS("property"))
        {
            CONDITION(m_currentMethod, "Property found inside a method or signal.");
            CONDITION(!m_currentInterface, "Property found outside an interface.");
            CONDITION(m_currentProperty, "Property found inside another property.");
            CONDITION(!m_structStack.isEmpty(), "Property found inside a struct.");
            CONDITION(m_currentEnum, "Property found inside a enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous property found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Property without a type found."));

            const int access_idx(indexOf(attributes, "access"));
            COND_DOC_ERROR(access_idx < 0, QString("Property without a access attribute found."));
            COND_DOC_ERROR(attributes.value(access_idx) != "read" &&
                           attributes.value(access_idx) != "write" &&
                           attributes.value(access_idx) != "readwrite",
                           QString("Property with invalid access attribute \"%1\" found.").
                           arg(attributes.value(access_idx)));

            m_currentProperty = createEntry();

            m_currentProperty->section = Entry::FUNCTION_SEC;

            if (attributes.value(access_idx) == "read" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Readable; }

            if (attributes.value(access_idx) == "write" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Writable; }

            m_currentProperty->name = attributes.value(name_idx).utf8();
            m_currentProperty->mtype = Property;
            m_currentProperty->type = getType(attributes).utf8();
        }

        if (EXTENSION("namespace"))
        {
            CONDITION(m_currentNode.isEmpty(), "Namespace found outside a node.");
            CONDITION(m_currentInterface, "Namespace found inside an interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous namespace found."));

            m_namespaceStack.append(openNamespace(attributes.value(idx)));
            openScopes(m_namespaceStack.getLast());
        }

        if (EXTENSION("struct"))
        {
            CONDITION(m_currentMethod, "Struct found inside a method or signal.");
            CONDITION(m_currentProperty, "Struct found inside a property.");
            CONDITION(m_currentEnum, "Struct found inside an enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous struct found."));

            Entry * current_struct = createEntry();
            current_struct->section = Entry::CLASS_SEC;
            current_struct->spec = Entry::Struct;
            current_struct->name = attributes.value(idx).utf8();

            openScopes(current_struct);

            current_struct->type = current_struct->name + " struct";

            m_structStack.append(new StructData(current_struct));
        }

        if (EXTENSION("member"))
        {
            CONDITION(m_structStack.isEmpty(), "Member found outside of struct.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous member found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Member without a type found."));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
            m_currentEntry->name = attributes.value(name_idx).utf8();
            m_currentEntry->type = getType(attributes).utf8();

            QString type(getDBusType(m_currentEntry->type));
            m_structStack.getLast()->type.append(type.utf8());
        }

        if (EXTENSION("enum") || EXTENSION("flagset"))
        {
            CONDITION(m_currentMethod, "Enum found inside a method or signal.");
            CONDITION(m_currentProperty, "Enum found inside a property.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous enum found."));

            const int type_idx(indexOf(attributes, "type"));
            QString type = "u";
            if (type_idx >= 0)
            { type = attributes.value(type_idx); }
            if (type != "y" && type != "q" && type != "u" && type != "t")
            { DOC_ERROR(QString("Invalid enum type \"%1\" found.").arg(type)); }

            m_currentEnum = createEntry();
            m_currentEnum->section = Entry::ENUM_SEC;
            m_currentEnum->name = attributes.value(name_idx).utf8();

            openScopes(m_currentEnum);

            m_currentEnum->type = m_currentEntry->name + " enum";

            addNamedType(type.utf8());
        }

        if (EXTENSION("value"))
        {
            CONDITION(!m_currentEnum, "Value found outside an enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous value found."));

            const int value_idx(indexOf(attributes, "value"));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
            m_currentEntry->name = attributes.value(name_idx).utf8();
            m_currentEntry->type = m_currentEnum->name; // "@"; // enum marker!
            if (value_idx >= 0)
            { m_currentEntry->initializer = attributes.value(value_idx).utf8(); }
        }

        return true;
    }
Example #27
0
MethodBind *godot_icall_Object_ClassDB_get_method(MonoString *p_type, MonoString *p_method) {
	StringName type(GDMonoMarshal::mono_string_to_godot(p_type));
	StringName method(GDMonoMarshal::mono_string_to_godot(p_method));
	return ClassDB::get_method(type, method);
}
Example #28
0
bool TextBase::edit(EditData& ed)
      {
      TextEditData* ted = static_cast<TextEditData*>(ed.getData(this));
      TextCursor* _cursor = &ted->cursor;

      // do nothing on Shift, it messes up IME on Windows. See #64046
      if (ed.key == Qt::Key_Shift)
            return false;
      QString s         = ed.s;
      bool ctrlPressed  = ed.modifiers & Qt::ControlModifier;
      bool shiftPressed = ed.modifiers & Qt::ShiftModifier;

      QTextCursor::MoveMode mm = shiftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;

      bool wasHex = false;
      if (hexState >= 0) {
            if (ed.modifiers == (Qt::ControlModifier | Qt::ShiftModifier | Qt::KeypadModifier)) {
                  switch (ed.key) {
                        case Qt::Key_0:
                        case Qt::Key_1:
                        case Qt::Key_2:
                        case Qt::Key_3:
                        case Qt::Key_4:
                        case Qt::Key_5:
                        case Qt::Key_6:
                        case Qt::Key_7:
                        case Qt::Key_8:
                        case Qt::Key_9:
                              s = QChar::fromLatin1(ed.key);
                              ++hexState;
                              wasHex = true;
                              break;
                        default:
                              break;
                        }
                  }
            else if (ed.modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) {
                  switch (ed.key) {
                        case Qt::Key_A:
                        case Qt::Key_B:
                        case Qt::Key_C:
                        case Qt::Key_D:
                        case Qt::Key_E:
                        case Qt::Key_F:
                              s = QChar::fromLatin1(ed.key);
                              ++hexState;
                              wasHex = true;
                              break;
                        default:
                              break;
                        }
                  }
            }

      if (!wasHex) {
//printf("======%x\n", s.isEmpty() ? -1 : s[0].unicode());

            switch (ed.key) {
                  case Qt::Key_Z:         // happens when the undo stack is empty
                        if (ed.modifiers == Qt::ControlModifier)
                              return true;
                        break;

                  case Qt::Key_Enter:
                  case Qt::Key_Return:
                        deleteSelectedText(ed);
                        score()->undo(new SplitText(_cursor), &ed);
                        return true;

                  case Qt::Key_Delete:
                        if (!deleteSelectedText(ed))
                              score()->undo(new RemoveText(_cursor, QString(_cursor->currentCharacter())), &ed);
                        return true;

                  case Qt::Key_Backspace:
                        if (!deleteSelectedText(ed)) {
                              if (_cursor->column() == 0 && _cursor->row() != 0)
                                    score()->undo(new JoinText(_cursor), &ed);
                              else {
                                    if (!_cursor->movePosition(QTextCursor::Left))
                                          return false;
                                    score()->undo(new RemoveText(_cursor, QString(_cursor->currentCharacter())), &ed);
                                    }
                              }
                        return true;

                  case Qt::Key_Left:
                        if (!_cursor->movePosition(ctrlPressed ? QTextCursor::WordLeft : QTextCursor::Left, mm) && type() == ElementType::LYRICS)
                              return false;
                        s.clear();
                        break;

                  case Qt::Key_Right:
                        if (!_cursor->movePosition(ctrlPressed ? QTextCursor::NextWord : QTextCursor::Right, mm) && type() == ElementType::LYRICS)
                              return false;
                        s.clear();
                        break;

                  case Qt::Key_Up:
#if defined(Q_OS_MAC)
                        if (!_cursor->movePosition(QTextCursor::Up, mm))
                              _cursor->movePosition(QTextCursor::StartOfLine, mm);
#else
                        _cursor->movePosition(QTextCursor::Up, mm);
#endif
                        s.clear();
                        break;

                  case Qt::Key_Down:
#if defined(Q_OS_MAC)
                        if (!_cursor->movePosition(QTextCursor::Down, mm))
                              _cursor->movePosition(QTextCursor::EndOfLine, mm);
#else
                        _cursor->movePosition(QTextCursor::Down, mm);
#endif
                        s.clear();
                        break;

                  case Qt::Key_Home:
                        if (ctrlPressed)
                              _cursor->movePosition(QTextCursor::Start, mm);
                        else
                              _cursor->movePosition(QTextCursor::StartOfLine, mm);

                        s.clear();
                        break;

                  case Qt::Key_End:
                        if (ctrlPressed)
                              _cursor->movePosition(QTextCursor::End, mm);
                        else
                              _cursor->movePosition(QTextCursor::EndOfLine, mm);

                        s.clear();
                        break;

                  case Qt::Key_Tab:
                        s = " ";
                        ed.modifiers = 0;
                        break;

                  case Qt::Key_Space:
                        if (ed.modifiers & CONTROL_MODIFIER) {
                              s = QString(QChar(0xa0)); // non-breaking space
                              }
                        else {
                              if (isFingering() && ed.view) {
                                    score()->endCmd();
                                    ed.view->textTab(ed.modifiers & Qt::ShiftModifier);
                                    return true;
                                    }
                              s = " ";
                              }
                        ed.modifiers = 0;
                        break;

                  case Qt::Key_Minus:
                        if (ed.modifiers == 0)
                              s = "-";
                        break;

                  case Qt::Key_Underscore:
                        if (ed.modifiers == 0)
                              s = "_";
                        break;

                  case Qt::Key_A:
                        if (ctrlPressed) {
                              selectAll(_cursor);
                              s.clear();
                        }
                        break;
                  default:
                        break;
                  }
            if (ctrlPressed && shiftPressed) {
                  switch (ed.key) {
                        case Qt::Key_U:
                              if (hexState == -1) {
                                    hexState = 0;
                                    s = "u";
                                    }
                              break;
                        case Qt::Key_B:
                              insertSym(ed, SymId::accidentalFlat);
                              return true;
                        case Qt::Key_NumberSign:
                              insertSym(ed, SymId::accidentalSharp);
                              return true;
                        case Qt::Key_H:
                              insertSym(ed, SymId::accidentalNatural);
                              return true;
                        case Qt::Key_Space:
                              insertSym(ed, SymId::space);
                              return true;
                        case Qt::Key_F:
                              insertSym(ed, SymId::dynamicForte);
                              return true;
                        case Qt::Key_M:
                              insertSym(ed, SymId::dynamicMezzo);
                              return true;
                        case Qt::Key_N:
                              insertSym(ed, SymId::dynamicNiente);
                              return true;
                        case Qt::Key_P:
                              insertSym(ed, SymId::dynamicPiano);
                              return true;
                        case Qt::Key_S:
                              insertSym(ed, SymId::dynamicSforzando);
                              return true;
                        case Qt::Key_R:
                              insertSym(ed, SymId::dynamicRinforzando);
                              return true;
                        case Qt::Key_Z:
                              // Ctrl+Z is normally "undo"
                              // but this code gets hit even if you are also holding Shift
                              // so Shift+Ctrl+Z works
                              insertSym(ed, SymId::dynamicZ);
                              return true;
                        }
                  }
            }
      if (!s.isEmpty()) {
            deleteSelectedText(ed);
            score()->undo(new InsertText(_cursor, s), &ed);
            }
      return true;
      }
GeometricDistribution::GeometricDistribution(std::shared_ptr<detail::UncertaintyDescription_Impl> impl)
  : UncertaintyDescription(impl)
{
  OS_ASSERT(type() == GeometricDistribution::type());
}
Example #30
0
type SetType::clone_and_bind_params(string_v &formal, type_v &actual)
{
  return type(new SetType(elem_type->clone_and_bind_params(formal, actual), nonempty));
}