Beispiel #1
0
void HeartbeatInvoker::invoke(const InvokeRequest& req) {
	_invokeId = req.invokeid;
	_event.invokeid = _invokeId;
	std::string intervalStr;
	double interval = 0;
	unsigned long intervalMs = 0;
	InvokeRequest::params_t::const_iterator paramIter = req.params.begin();
	while(paramIter != req.params.end()) {
		if (iequals(paramIter->first, "interval")) {
			intervalStr = paramIter->second.atom;
			NumAttr intervalAttr(paramIter->second.atom);
			interval = strTo<double>(intervalAttr.value);
			if (false) {
			} else if (iequals(intervalAttr.unit, "s")) {
				intervalMs = interval * 1000;
			} else if (iequals(intervalAttr.unit, "ms")) {
				intervalMs = interval;
			} else {
				intervalMs = interval;
			}
		}
		if (iequals(paramIter->first, "eventname")) {
			_event.name = paramIter->second.atom;
		}
		paramIter++;
	}
	if (_event.name.length() == 0)
		_event.name = std::string("heartbeat." + intervalStr);

	if (intervalMs > 0) {
		HeartbeatDispatcher::getInstance()->addEvent(toStr(this), HeartbeatInvoker::dispatch, intervalMs, this, true);
	}
}
Beispiel #2
0
//
// W_GetIWADInfo
//
// Helper function that returns a pointer to the appropriate entry of
// doomwadnames for a given file name if it is an IWAD.
// Returns NULL if the given file name is not an IWAD.
//
static const gamewadinfo_t* W_GetIWADInfo(const std::string& filename, const std::string& hash)
{
	if (filename.empty())
		return NULL;

	// find our match if there is one
	for (size_t i = 0; !doomwadnames[i].name.empty(); i++)
	{
		if (!hash.empty())
		{
			// hash comparison
			for (size_t j = 0; !doomwadnames[i].hash[j].empty(); j++)
			{
				// the hash is always right! even if the name is wrong..
				if (iequals(hash, doomwadnames[i].hash[j]))
					return &doomwadnames[i];
			}
		}
		else
		{
			std::string base_filename, base_iwadname;
			M_ExtractFileBase(filename, base_filename);
			M_ExtractFileBase(doomwadnames[i].name, base_iwadname);

			if (iequals(filename, doomwadnames[i].name) ||
				iequals(base_filename, base_iwadname))
				return &doomwadnames[i];
		}
	}

	return NULL;
}
Beispiel #3
0
	inline bool lexical_cast(const char * str)
	{
		Assert(str != NULL);
		if (iequals(str, "true") || iequals(str, "yes") || equals(str, "1")) {
			return true;
		}
		return false;
	}
/**
* The constructor needs to scan the whole PTX file to find out the bounding box. Unluckily.
* TODO: during the scan all the points are read and transformed. Afterwards, during loading
* the points are read again and transformed again. It should be nice to save the
* transformed points in a temporary file. That would mean a LAS file or something similar.
* Unuseful. It's better to convert the PTX to LAS files.
* TODO: it seems theat the PTXPointReader is asked to produce the bounding box more than once.
* Maybe it should be saved somewhere. Chez moi, scanning 14m points needs 90 secs. The
* process speed of the PTX file is about 1m points every 50 secs.
*/
PTXPointReader::PTXPointReader(string path) {
    this->path = path;

    if (fs::is_directory(path)) {
        // if directory is specified, find all ptx files inside directory

        for (fs::directory_iterator it(path); it != fs::directory_iterator(); it++) {
            fs::path filepath = it->path();
            if (fs::is_regular_file(filepath)) {
                if (iequals(fs::extension(filepath), ".ptx")) {
                    files.push_back(filepath.string());
                }
            }
        }
    } else {
        files.push_back(path);
    }

    // open first file
    this->currentFile = files.begin();
    this->stream = new fstream(*(this->currentFile), ios::in);
    this->currentChunk = 0;
    skipline(*this->stream);
    loadChunk(this->stream, this->currentChunk, this->tr);
}
Beispiel #5
0
static UString findSubDirectory_internal(const UString &directory, const UString &subDirectory,
		bool caseInsensitive) {

	try {
		path dirPath(directory.c_str());
		path subDirPath(subDirectory.c_str());

		// Iterator over the directory's contents
		directory_iterator itEnd;
		for (directory_iterator itDir(dirPath); itDir != itEnd; ++itDir) {
			if (is_directory(itDir->status())) {
				// It's a directory. Check if it's the one we're looking for

				if (caseInsensitive) {
					if (iequals(itDir->path().filename(), subDirectory.c_str()))
						return itDir->path().string();
				} else {
					if (equals(itDir->path().filename(), subDirectory.c_str()))
						return itDir->path().string();
				}
			}
		}
	} catch (...) {
	}

	return "";
}
Beispiel #6
0
void CaseInsensitiveHashTable<T>::add_index(T* entry) {
  size_t h = fnv1a_hash_lower(entry->name) & index_mask_;

  if (index_[h] == NULL) {
    index_[h] = entry;
  } else {
    // Use linear probing to find an open bucket
    size_t start = h;
    while (index_[h] != NULL && !iequals(entry->name, index_[h]->name)) {
      h = (h + 1) & index_mask_;
      if (h == start) {
        return;
      }
    }
    if (index_[h] == NULL) {
      index_[h] = entry;
    } else {
      T* curr = index_[h];
      while (curr->next != NULL) {
        curr = curr->next;
      }
      curr->next = entry;
    }
  }
}
Beispiel #7
0
void FFMPEGInvoker::process(const SendRequest& req) {

    std::string context;
    Event::getParam(req.params, "context", context);
    if (_encoders.find(context) == _encoders.end()) {
        return;
    }

    EncodingContext* ctx = _encoders[context];
    tthread::lock_guard<tthread::recursive_mutex> lock(ctx->mutex);

    // finish encoding and return
    if(iequals(req.name, "render.end")) {
        finish(ctx, req);
        delete _encoders[context];
        _encoders.erase(context);
    }

    Data image;
    Event::getParam(req.params, "frame", image);
    if (image.empty()) {
        return;
    }

    std::string format = "bmp";
    Event::getParam(req.params, "format", format);

    writeVideoFrame(ctx, ctx->formatCtx, ctx->videoStream, image.binary);
    ctx->frame->pts += av_rescale_q(1, ctx->videoStream->codec->time_base, ctx->videoStream->time_base);

}
Globals::Globals(TiXmlElement *root)
    :
    nodeCounter(-1),
    linkCounter(-1),
    speciesCounter(-1)
{
    cout << "Populating sigmoid table...";
    for (int a=0; a<6001; a++)
    {
        signedSigmoidTable[a] = ((1 / (1+exp(-((a-3000)/1000.0)))) - 0.5)*2.0;
        unsignedSigmoidTable[a] = 1 / (1+exp(-((a-3000)/1000.0)));
    }
    cout << "done!\n";

    TiXmlAttribute *firstAttribute = root->FirstAttribute();

    while (firstAttribute)
    {
        if (iequals(firstAttribute->Name(),"NodeCounter"))
        {
            nodeCounter = firstAttribute->IntValue();
        }
        else if (iequals(firstAttribute->Name(),"LinkCounter"))
        {
            linkCounter = firstAttribute->IntValue();
        }
        else if (iequals(firstAttribute->Name(),"SpeciesCounter"))
        {
            speciesCounter = firstAttribute->IntValue();
        }
        else
        {
            addParameter( firstAttribute->Name() , firstAttribute->DoubleValue());
        }

        firstAttribute = firstAttribute->Next();
    }

    if (nodeCounter==-1 || linkCounter==-1 || speciesCounter==-1)
    {
        throw CREATE_LOCATEDEXCEPTION_INFO("MALFORMED XML!");
    }

    cacheParameters();

    initRandom();
}
Beispiel #9
0
BufferRef HttpRequest::requestHeader(const std::string& name) const
{
	for (auto& i: requestHeaders)
		if (iequals(i.name, name))
			return i.value;

	return BufferRef();
}
Beispiel #10
0
void book_author_search()
{
	cout << "Enter the book's author:" << endl;
	string name;
	cin.clear();
	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	getline(cin, name);
	Category *tmp1 = beginning;
	Book *tmp;
	vector <Book *> list;

	system("CLS");
	cout << "Searching..." << endl;

	int i = 0;

	while (tmp1 != NULL)
	{
		tmp = tmp1->getHead();

		while (tmp != NULL)
		{
			if (iequals(tmp->getAuthor(), name))
			{
				list.push_back(tmp);
				i++;
				cout << "Result no." << i << endl;
				tmp->print();
			}
			tmp = tmp->getNext();
		}
		tmp1 = tmp1->getNext();
	}

	if (i == 0)
	{
		system("CLS");
		cout << "No such ID was found." << endl;
		cout << "Please try again" << endl;
	}

	else
	{
		cout << "Which of the results do you want to manage? (enter a number)" << endl;

		stahp();
		int ch;
		cin >> ch;
		ch--;
		if (ch > 49 || list[ch] == NULL)
		{
			cout << "Invalid response. Please start again." << endl;
		}

		else
			book_menu(list[ch]);
	}
}
Beispiel #11
0
bool HttpConnection::onMessageHeader(const BufferRef& name, const BufferRef& value)
{
	if (request_->isFinished()) {
		// this can happen when the request has failed some checks and thus,
		// a client error message has been sent already.
		// we need to "parse" the remaining content anyways.
		TRACE("onMessageHeader() skip \"%s\": \"%s\"", name.str().c_str(), value.str().c_str());
		return true;
	}

	TRACE("onMessageHeader() \"%s\": \"%s\"", name.str().c_str(), value.str().c_str());

	if (iequals(name, "Host")) {
		auto i = value.find(':');
		if (i != BufferRef::npos)
			request_->hostname = value.ref(0, i);
		else
			request_->hostname = value;
		TRACE(" -- hostname set to \"%s\"", request_->hostname.str().c_str());
	} else if (iequals(name, "Connection")) {
		if (iequals(value, "close"))
			setShouldKeepAlive(false);
		else if (iequals(value, "keep-alive"))
			setShouldKeepAlive(true);
	}

	// limit the size of a single request header
	if (name.size() + value.size() > worker().server().maxRequestHeaderSize()) {
		TRACE("header too long. got %ld / %ld", name.size() + value.size(), worker().server().maxRequestHeaderSize());
		request_->status = HttpError::RequestEntityTooLarge;
		request_->finish();
		return false;
	}

	// limit the number of request headers
	if (request_->requestHeaders.size() > worker().server().maxRequestHeaderCount()) {
		TRACE("header count exceeded. got %ld / %ld", request_->requestHeaders.size(), worker().server().maxRequestHeaderCount());
		request_->status = HttpError::RequestEntityTooLarge;
		request_->finish();
		return false;
	}

	request_->requestHeaders.push_back(HttpRequestHeader(name, value));
	return true;
}
Beispiel #12
0
XPathFunction<std::string>*
XPathFunctionResolver::resolveFunction(const std::string& namespace_uri,
                                       const std::string& name,
                                       const std::vector<XPathExpression<std::string> >& argExprs) const {
    if (iequals(name, "in")) {
        return new XPathFunctionIn(1, -1, argExprs, _interpreter);
    }
    return _xpathFuncRes.resolveFunction(namespace_uri, name, argExprs);
}
Beispiel #13
0
xcc_units::t_unit_data_entry* xcc_units::get_id(const string& s)
{
	for (auto& ud : unit_data)
	{
		if (ud.flags & ud_flags_in_use && iequals(ud.short_name, s))
			return &ud;
	}
	assert(false);
	return NULL;
}
Beispiel #14
0
void FetchElement::enterElement(const Arabica::DOM::Element<std::string>& node) {
	if (!HAS_ATTR(node, "src") && !HAS_ATTR(node, "srcexpr")) {
		LOG(ERROR) << "Fetch element requires src or srcexpr";
		return;
	}
	if (HAS_ATTR(node, "srcexpr") && !_interpreter->getDataModel()) {
		LOG(ERROR) << "Fetch element with srcexpr requires datamodel";
		return;
	}
	_source = (HAS_ATTR(node, "src") ? ATTR(node, "src") : _interpreter->getDataModel().evalAsString(ATTR(node, "srcexpr")));

	if (!HAS_ATTR(node, "callback") && !HAS_ATTR(node, "callbackexpr")) {
		LOG(ERROR) << "Fetch element requires callback or callbackexpr";
		return;
	}
	if (HAS_ATTR(node, "callbackexpr") && !_interpreter->getDataModel()) {
		LOG(ERROR) << "Fetch element with callbackexpr requires datamodel";
		return;
	}
	_callback = (HAS_ATTR(node, "callback") ? ATTR(node, "callback") : _interpreter->getDataModel().evalAsString(ATTR(node, "callbackexpr")));

	_type = (HAS_ATTR(node, "type") ? ATTR(node, "type") : "text");
	if (!iequals(_type, "text") &&
	        !iequals(_type, "url") &&
	        !iequals(_type, "json") &&
	        !iequals(_type, "xml")) {
		LOG(ERROR) << "Fetch element type attribute not one of text, url, json, xml.";
		return;
	}

	_targetUrl = URL(_source);
	if (!_targetUrl.isAbsolute()) {
		if (!_targetUrl.toAbsolute(_interpreter->getBaseURL(node))) {
			LOG(ERROR) << "Cannot transform " << _source << " into absolute URL";
			return;
		}
	}

	_targetUrl.addMonitor(this);
	URLFetcher::fetchURL(_targetUrl);

}
void MChannelRuleMapList::Add(const StringView& strMapName)
{
	for (int i = 0; i < MMATCH_MAP_MAX; i++)
	{
		if (iequals(strMapName, g_MapDesc[i].szMapName))
		{
			Add(i);
			return;
		}
	}
}
Beispiel #16
0
bool FullMatch(const std::string& a, const std::string& b, bool icase)
{
    if (icase)
        {
            return a == b? true : false;
        }
    else
        {
            return iequals(a,b);
        }
}
Beispiel #17
0
void FetchElement::downloadCompleted(const URL& url) {
	Event event;
	event.name = _callback;

	std::string content = url.getInContent();
	std::map<std::string, std::string> headerFields = url.getInHeaderFields();

	if (false) {
	} else if (iequals(_type, "text")) {
		event.data.atom = content;
		event.data.type = Data::VERBATIM;
	} else if (iequals(_type, "url")) {
	} else if (iequals(_type, "json")) {
		event.data = Data::fromJSON(content);
	} else if (iequals(_type, "xml")) {
		event = Event::fromXML(content);
	}

	_interpreter->receive(event);

}
    GeneticNodeGene* GeneticIndividual::getNode(const string &name)
    {
        for(int a=0;a<(int)nodes.size();a++)
        {
            if(iequals(nodes[a].getName(),name))
            {
                return &nodes[a];
            }
        }

        return NULL;
    }
Beispiel #19
0
void TileData::loadFromFile(string line, FormattedFileIterator &iter)
{
	while(!equals(line, "|"))
	{
		if(iequals(TileDataPropertyNames[FOOD_VALUE], line))
		{
			setFoodValue(lexical_cast<float>(*iter)); ++iter;
		}
		else if(iequals(TileDataPropertyNames[REGROWTH_VALUE], line))
		{
			setRegrowthRate(lexical_cast<float>(*iter)); ++iter;
		}
		else if(iequals(TileDataPropertyNames[MAX_FOOD_VALUE], line))
		{
			setMaxFoodValue(lexical_cast<float>(*iter)); ++iter;
		}
		
		line = *iter;
		++iter;
	}
}
Beispiel #20
0
// default "info" if unrecognized
el::Level
Logging::getLLfromString(std::string const& levelName)
{
    if (iequals(levelName, "trace"))
    {
        return el::Level::Trace;
    }

    if (iequals(levelName, "debug"))
    {
        return el::Level::Debug;
    }

    if (iequals(levelName, "warning"))
    {
        return el::Level::Warning;
    }

    if (iequals(levelName, "fatal"))
    {
        return el::Level::Fatal;
    }

    if (iequals(levelName, "error"))
    {
        return el::Level::Error;
    }

    if (iequals(levelName, "none"))
    {
        return el::Level::Unknown;
    }

    return el::Level::Info;
}
  void ExperimentRun::createPopulation(string populationString)
  {
    cout<<"createPopulation: "<<populationString<<endl;

    if (iequals(populationString,""))
      {
        int popSize = (int)NEAT::Globals::getSingleton()->getParameterValue("PopulationSize");
        population = shared_ptr<NEAT::GeneticPopulation>(experiments[currentSubExperiment]->createInitialPopulation(popSize));
      }
    else
      {					
        population = shared_ptr<NEAT::GeneticPopulation>(new NEAT::GeneticPopulation(populationString));
      }
  }
DevicePtr ColladaBodyLoaderImpl::createSensor(DaeSensor* sensor)
{
    DevicePtr device;
    if (sensor->type.size() <= 0) {
        device = new RateGyroSensor;
    } else 
        if (iequals(sensor->type, "base_force6d")) {
            device = new ForceSensor;
        } else
            if (iequals(sensor->type, "base_imu")) {
                device = new AccelerationSensor;
            } else 
                if (iequals(sensor->type, "base_pinhole_camera")) {
                    device = new Camera;
                    Camera* camera = static_cast<Camera*>(device.get());
                    camera->setResolution(sensor->imageDimensions[0], sensor->imageDimensions[1]);
                    camera->setNearDistance(sensor->focalLength);
                    camera->setFieldOfView (sensor->focalLength);
                } else {
                    throwException((format(_("invalid sensor-type:%1%")) % sensor->type).str());
                }      

    return device;
}
Beispiel #23
0
bool CAR_DKW_o::SetAsFixed(const TDenseVector &v, const std::string &which_one)
{
        TIndex local_fixed_index;
        int offset;
        if (iequals(which_one, std::string("delta_options")) )
        {
                offset = CAR_DKW::NumberParameters();
                local_fixed_index = FixedVariableParameter(delta_options, v, offset);
                FixedIndex.UniqMerge(local_fixed_index);
                if_variable_index_set = false;
                return true;
        }
        else
                return CAR_DKW::SetAsFixed(v, which_one);
}
Beispiel #24
0
/** callback, invoked on every successfully parsed response header.
 *
 * We will pass this header directly to the client's response,
 * if that is NOT a connection-level header.
 */
bool HttpProxy::ProxyConnection::onMessageHeader(const BufferRef& name, const BufferRef& value)
{
	TRACE("ProxyConnection(%p).onHeader('%s', '%s')", (void*)this, name.str().c_str(), value.str().c_str());

	// XXX do not allow origin's connection-level response headers to be passed to the client.
	if (iequals(name, "Connection"))
		goto skip;

	if (iequals(name, "Transfer-Encoding"))
		goto skip;

	if (cloak_ && iequals(name, "Server")) {
		TRACE("skipping \"Server\"-header");
		goto skip;
	}

	request_->responseHeaders.push_back(name.str(), value.str());
	return true;

skip:
	TRACE("skip (connection-)level header");

	return true;
}
bool InterpreterDraft6::isWithinParallel(const Node<std::string>& transition) {
	if (isTargetless(transition))
		return false;

	Node<std::string> source;
	if (HAS_ATTR(transition, "type") && iequals(ATTR(transition, "type"), "internal")) {
		source = getSourceState(transition);
	} else {
		source = getSourceState(transition).getParentNode();
	}
	NodeSet<std::string> targets = getTargetStates(transition);
	targets.push_back(source);

	Node<std::string> lcpa = findLCPA(targets);
	return lcpa;
}
Beispiel #26
0
void cat_name_search()
{
    cout << "Enter the category's name:" << endl;
	string name;
	cin >> name;
	Category *tmp = beginning;
	vector <Category *> list;
	int ch, i = 0;

	system("CLS");
	cout << "Searching..." << endl;

		while (tmp != NULL)
		{
			if (iequals(tmp->getName(), name))
			{
				list.push_back(tmp);
				i++;
				cout << "Result no." << i << endl;
				tmp->print();
			}
			tmp = tmp->getNext();
		}

	if (i == 0)
	{
		system("CLS");
		cout << "No such name was found." << endl;
		cout << "Please try again." << endl;
	}

	else
	{

		cout << "Which of the categories do you want to manage? (enter a number)" << endl;


		cin >> ch;
		ch--;
		if (ch > 49 || list[ch] == NULL)
		{
			cout << "Invalid response. Please start again." << endl;
		}
		else
			cat_menu(list[ch]);
	}
}
Beispiel #27
0
cvar_t *cvar_t::FindCVar (const char *var_name, cvar_t **prev)
{
	cvar_t *var;

	if (var_name == NULL)
		return NULL;

	var = ad.GetCVars();
	*prev = NULL;
	while (var)
	{
		if (iequals(var->m_Name, var_name))
			break;
		*prev = var;
		var = var->m_Next;
	}
	return var;
}
bool MChannelRuleMapList::Exist(const StringView& pszMapName, bool bOnlyDuel)
{
	for (auto itor = m_Set.begin(); itor != m_Set.end(); ++itor)
	{
		int id = (*itor);

		if ((id >= 0) && (id < MMATCH_MAP_MAX))
		{
			if (iequals(pszMapName, g_MapDesc[id].szMapName))
			{
				if ( !bOnlyDuel && g_MapDesc[id].bOnlyDuelMap)
					return false;

				return true;
			}
		}
	}

	return false;
}
Beispiel #29
0
size_t CaseInsensitiveHashTable<T>::get_indices(StringRef name, IndexVec* result) const {
  result->clear();
  bool is_case_sensitive = false;

  if (name.size() > 0 && name.front() == '"' && name.back() == '"') {
    is_case_sensitive = true;
    name = name.substr(1, name.size() - 2);
  }

  size_t h = fnv1a_hash_lower(name) & index_mask_;

  size_t start = h;
  while (index_[h] != NULL && !iequals(name, index_[h]->name)) {
    h = (h + 1) & index_mask_;
    if (h == start) {
      return 0;
    }
  }

  const T* entry = index_[h];

  if (entry == NULL) {
    return 0;
  }

  if (!is_case_sensitive) {
    while (entry != NULL) {
      result->push_back(entry->index);
      entry = entry->next;
    }
  } else {
    while (entry != NULL) {
      if (name.equals(entry->name)) {
        result->push_back(entry->index);
      }
      entry = entry->next;
    }
  }

  return result->size();
}
Beispiel #30
0
void XPathDataModel::assign(const NodeSet<std::string>& key,
                            const std::string& value,
                            const Element<std::string>& assignElem) {
    if (key.size() == 0)
        return;
    for (size_t i = 0; i < key.size(); i++) {
        Node<std::string> node = key[i];
        switch (node.getNodeType()) {
        case Node_base::ATTRIBUTE_NODE: {
            Attr<std::string> attr(node);
            attr.setValue(value);
            break;
        }
        case Node_base::TEXT_NODE: {
            Text<std::string> text(node);
            text.setNodeValue(value);
            break;
        }
        case Node_base::ELEMENT_NODE: {
            Element<std::string> element(node);
            if (HAS_ATTR(assignElem, "type") && iequals(ATTR(assignElem, "type"), "addattribute")) {
                // addattribute: Add an attribute with the name specified by 'attr'
                // and value specified by 'expr' to the node specified by 'location'.
                if (!HAS_ATTR(assignElem, "attr"))
                    ERROR_EXECUTION_THROW("Assign element is missing 'attr'");
                element.setAttribute(ATTR(assignElem, "attr"), value);
            } else {
                /// test 547
                while(element.hasChildNodes())
                    element.removeChild(element.getChildNodes().item(0));
                Text<std::string> text = _doc.createTextNode(value);
                element.appendChild(text);
            }
            break;
        }
        default:
            ERROR_EXECUTION_THROW("Unsupported node type with assign");
            break;
        }
    }
}