コード例 #1
0
ファイル: Name.cpp プロジェクト: PuerkitoBio/locic
	bool Name::operator<(const Name& name) const{
		if (size() != name.size()) return size() < name.size();
		for (std::size_t i = 0; i < size(); i++) {
			if (at(i) != name.at(i)) {
				return at(i) < name.at(i);
			}
		}
		return false;
	}
コード例 #2
0
ファイル: strategy.cpp プロジェクト: cawka/NFD
Name
Strategy::makeInstanceName(const Name& input, const Name& strategyName)
{
  BOOST_ASSERT(strategyName.at(-1).isVersion());

  bool hasVersion = std::any_of(input.rbegin(), input.rend(),
                                [] (const name::Component& comp) { return comp.isVersion(); });
  return hasVersion ? input : Name(input).append(strategyName.at(-1));
}
コード例 #3
0
ファイル: Name.cpp プロジェクト: PuerkitoBio/locic
	Name::Name(const Name& prefix, const Name& suffix)
	: isAbsolute_(prefix.isAbsolute()) {
		list_.reserve(prefix.size() + suffix.size());
		for(std::size_t i = 0; i < prefix.size(); i++){
			list_.push_back(prefix.at(i));
		}
		for(std::size_t i = 0; i < suffix.size(); i++){
			list_.push_back(suffix.at(i));
		}
	}
コード例 #4
0
ファイル: Name.cpp プロジェクト: PuerkitoBio/locic
	Name::Name(const Name& name, size_t substrSize)
	: isAbsolute_(name.isAbsolute()) {
		assert(substrSize <= name.size());
		list_.reserve(substrSize);
		for(std::size_t i = 0; i < substrSize; i++){
			list_.push_back(name.at(i));
		}
	}
コード例 #5
0
ファイル: tracer.cpp プロジェクト: shockjiang/ndn-tools
void
Tracer::onReceive(const Name& name)
{
    if (m_options.shouldPrintTimestamp) {
        std::cout << time::toIsoString(time::system_clock::now())  << " - ";
    }

    std::cout << "interest received: seq=" << name.at(-1).toUri() << std::endl;
}
コード例 #6
0
ファイル: Name.cpp プロジェクト: PuerkitoBio/locic
	bool Name::isPrefixOf(const Name& name) const{
		if(size() >= name.size()) return false;
		for(std::size_t i = 0; i < size(); i++){
			if(at(i) != name.at(i)){
				return false;
			}
		}
		return true;
	}
コード例 #7
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performInnerAliasSearch(AST::Alias& alias, const Name& name) {
			if (name.size() != 1 || name.isAbsolute()) return SearchResult::None();
			
			const auto iterator = alias.namedTemplateVariables().find(name.at(0));
			if (iterator != alias.namedTemplateVariables().end()) {
				return SearchResult::TemplateVar(*(iterator->second));
			}
			
			return SearchResult::None();
		}
コード例 #8
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performInnerCatchClauseSearch(AST::CatchClause* catchClause, const Name& name) {
			if (name.size() != 1 || name.isAbsolute()) return SearchResult::None();
			
			const auto iterator = catchClause->namedVariables().find(name.at(0));
			if (iterator != catchClause->namedVariables().end()) {
				return SearchResult::Var(*(iterator->second));
			}
			
			return SearchResult::None();
		}
コード例 #9
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performInnerTypeInstanceSearch(AST::TypeInstance& typeInstance, const Name& name) {
			if (name.size() != 1 || name.isAbsolute()) return SearchResult::None();
			
			const auto iterator = typeInstance.namedTemplateVariables().find(name.at(0));
			if (iterator != typeInstance.namedTemplateVariables().end()) {
				return SearchResult::TemplateVar(*(iterator->second));
			}
			
			return SearchResult::None();
		}
コード例 #10
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performInnerFunctionSearch(AST::Function& function, const Name& name) {
			if (name.size() != 1 || name.isAbsolute()) return SearchResult::None();
			
			// Search template variables.
			{
				const auto iterator = function.namedTemplateVariables().find(name.at(0));
				if (iterator != function.namedTemplateVariables().end()) {
					return SearchResult::TemplateVar(*(iterator->second));
				}
			}
			
			// Search parameter variables.
			{
				const auto iterator = function.namedVariables().find(name.at(0));
				if (iterator != function.namedVariables().end()) {
					return SearchResult::Var(*(iterator->second));
				}
			}
			
			return SearchResult::None();
		}
コード例 #11
0
ファイル: Name.cpp プロジェクト: PuerkitoBio/locic
	Name::Name(const Name& prefix, const String& suffix)
	: isAbsolute_(prefix.isAbsolute()) {
		list_.reserve(prefix.size() + 1);
		for (std::size_t i = 0; i < prefix.size(); i++) {
			list_.push_back(prefix.at(i));
		}
		
		// No member of a name can be an empty string.
		if (suffix.size() > 0) {
			list_.push_back(suffix);
		}
	}
コード例 #12
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performTypeInstanceSearch(AST::TypeInstance& typeInstance, const Name& name, size_t pos) {
			const auto size = name.size() - pos;
			
			if (size == 0) return SearchResult::TypeInstance(typeInstance);
			
			const auto canonicalName = CanonicalizeMethodName(name.at(pos));
			const auto function = typeInstance.findFunction(canonicalName);
			if (function != nullptr && function->isStaticMethod()) {
				return performFunctionSearch(*function, name, pos + 1);
			}
			
			return SearchResult::None();
		}
コード例 #13
0
ファイル: name.cpp プロジェクト: WeiqiJust/NDN-total
bool
Name::equals(const Name& name) const
{
  if (size() != name.size())
    return false;

  for (size_t i = 0; i < size(); ++i) {
    if (at(i) != name.at(i))
      return false;
  }

  return true;
}
コード例 #14
0
ファイル: name.cpp プロジェクト: WeiqiJust/NDN-total
bool
Name::isPrefixOf(const Name& name) const
{
  // This name is longer than the name we are checking against.
  if (size() > name.size())
    return false;

  // Check if at least one of given components doesn't match.
  for (size_t i = 0; i < size(); ++i) {
    if (at(i) != name.at(i))
      return false;
  }

  return true;
}
コード例 #15
0
ファイル: name.cpp プロジェクト: named-data-ndnSIM/ndn-cxx
int
Name::compare(size_t pos1, size_t count1, const Name& other, size_t pos2, size_t count2) const
{
  count1 = std::min(count1, this->size() - pos1);
  count2 = std::min(count2, other.size() - pos2);
  size_t count = std::min(count1, count2);

  for (size_t i = 0; i < count; ++i) {
    int comp = this->at(pos1 + i).compare(other.at(pos2 + i));
    if (comp != 0) { // i-th component differs
      return comp;
    }
  }
  // [pos1, pos1+count) of this Name equals [pos2, pos2+count) of other Name
  return count1 - count2;
}
コード例 #16
0
ファイル: NameSearch.cpp プロジェクト: scrossuk/locic
		SearchResult performNamespaceSearch(AST::Namespace& nameSpace, const Name& name, size_t pos) {
			const auto size = name.size() - pos;
			
			if (size == 0) return SearchResult::None();
			
			const auto iterator = nameSpace.items().find(name.at(pos));
			if (iterator != nameSpace.items().end()) {
				const auto& item = iterator->second;
				if (item.isFunction()) {
					return performFunctionSearch(item.function(), name, pos + 1);
				} else if (item.isNamespace()) {
					return performNamespaceSearch(item.nameSpace(), name, pos + 1);
				} else if (item.isAlias()) {
					return performAliasSearch(item.alias(), name, pos + 1);
				} else if (item.isTypeInstance()) {
					return performTypeInstanceSearch(item.typeInstance(), name, pos + 1);
				}
			}
			
			return SearchResult::None();
		}
コード例 #17
0
ファイル: name.cpp プロジェクト: WeiqiJust/NDN-total
int
Name::compare(const Name& other) const
{
  for (size_t i = 0; i < size() && i < other.size(); ++i) {
    int comparison = at(i).compare(other.at(i));
    if (comparison == 0)
      // The components at this index are equal, so check the next components.
      continue;

    // Otherwise, the result is based on the components at this index.
    return comparison;
  }

  // The components up to min(this.size(), other.size()) are equal, so the shorter name is less.
  if (size() < other.size())
    return -1;
  else if (size() > other.size())
    return 1;
  else
    return 0;
}