OSQuantityVector& OSQuantityVector::operator-=(Quantity rQuantity) { if (isTemperature() && rQuantity.isTemperature()) { if (isAbsolute() && rQuantity.isAbsolute()) { // units must be the same, check that exponent on this is 1 std::vector<std::string> bus = m_units.baseUnits(); assert(bus.size() == 1); if (m_units.baseUnitExponent(bus[0]) == 1) { setAsRelative(); rQuantity.setAsRelative(); } } else if (!isAbsolute() && rQuantity.isAbsolute()) { setAsAbsolute(); } else if (isAbsolute() && !rQuantity.isAbsolute()) { rQuantity.setAsAbsolute(); } } if (units() != rQuantity.units()) { LOG_AND_THROW("Cannot subtract OSQuantityVector and Quantity with different units (" << units() << " and " << rQuantity.units() << ")."); } if (scale() != rQuantity.scale()) { rQuantity.setScale(scale().exponent); } double value = rQuantity.value(); for (unsigned i = 0, n = size(); i < n; ++i) { m_values[i] -= value; } return *this; }
expr *modulus(expr *op1, expr *op2) { /* * absolute % absolute = absolute */ expr *res = newExpr(); if (op2->value == 0) { yyerror("modulus by 0"); res->value = op1->value; } else res->value = (op1->value / op2->value) & DMASK; // keep to 36-bits //if (op1->type == eExprAbsolute && op2->type == eExprAbsolute) if (isAbsolute(op1) && isAbsolute(op2)) { res->type = eExprAbsolute; res->lc = op1->lc; } else { if (nPass == 2) yyerror("type error for modulus"); res->type = eExprUnknown; res->lc = op1->lc; } return res; }
OSQuantityVector& OSQuantityVector::operator+=(Quantity rQuantity) { if (isTemperature() && rQuantity.isTemperature()) { if (!isAbsolute() && rQuantity.isAbsolute()) { setAsAbsolute(); } else if (isAbsolute() && !rQuantity.isAbsolute()) { rQuantity.setAsAbsolute(); } } if (units() != rQuantity.units()) { LOG_AND_THROW("Cannot add OSQuantityVector and Quantity with different units (" << units() << " and " << rQuantity.units() << ")."); } if (scale() != rQuantity.scale()) { rQuantity.setScale(scale().exponent); } double value = rQuantity.value(); for (unsigned i = 0, n = size(); i < n; ++i) { m_values[i] += value; } return *this; }
bool Path::resolve(ResolveMode mode, const Path &cwd) { if (mode == MakeAbsolute) { if (isAbsolute()) return true; const Path copy = (cwd.isEmpty() ? Path::pwd() : cwd) + *this; if (copy.exists()) { operator=(copy); return true; } return false; } else { if (!cwd.isEmpty() && !isAbsolute()) { Path copy = cwd + '/' + *this; if (copy.resolve(RealPath)) { operator=(copy); return true; } } { char buffer[PATH_MAX + 2]; if (realpath(constData(), buffer)) { String::operator=(buffer); return true; } } } return false; }
Quantity& Quantity::operator+=(const Quantity& temp) { if (this == &temp) { m_value *= 2.0; return *this; } // copy input reference so we can change its properties Quantity rQuantity(temp); if (isTemperature() && rQuantity.isTemperature()) { if (!isAbsolute() && rQuantity.isAbsolute()) { setAsAbsolute(); } else if (isAbsolute() && !rQuantity.isAbsolute()){ rQuantity.setAsAbsolute(); } } if (m_units != rQuantity.m_units) { LOG_AND_THROW("Cannot add quantities with different units."); } if (scale() != rQuantity.scale()) { Quantity wRQuantity(rQuantity); wRQuantity.setScale(scale().exponent); m_value += wRQuantity.value(); } else { m_value += rQuantity.value(); } return *this; }
expr *multiply(expr *op1, expr *op2) { /* * absolute * absolute = absolute */ expr *res = newExpr(); res->value = (op1->value * op2->value) & DMASK; // keep to 36-bits //if (op1->type == eExprAbsolute && op2->type == eExprAbsolute) if (isAbsolute(op1) && isAbsolute(op2)) { res->type = eExprAbsolute; res->lc = op1->lc; } else { if (nPass == 2) yyerror("type error for multiplication"); res->type = eExprUnknown; res->lc = op1->lc; } return res; }
bool Path::resolve(ResolveMode mode, const Path &cwd, bool *changed) { if (changed) *changed = false; if (startsWith('~')) { wordexp_t exp_result; wordexp(constData(), &exp_result, 0); operator=(exp_result.we_wordv[0]); wordfree(&exp_result); } if (*this == ".") clear(); if (mode == MakeAbsolute) { if (isAbsolute()) return true; const Path copy = (cwd.isEmpty() ? Path::pwd() : cwd.ensureTrailingSlash()) + *this; if (copy.exists()) { if (changed) *changed = true; operator=(copy); return true; } return false; } if (!cwd.isEmpty() && !isAbsolute()) { Path copy = cwd + '/' + *this; if (copy.resolve(RealPath, Path(), changed)) { operator=(copy); return true; } } { char buffer[PATH_MAX + 2]; if (realpath(constData(), buffer)) { if (isDir()) { const int len = strlen(buffer); assert(buffer[len] != '/'); buffer[len] = '/'; buffer[len + 1] = '\0'; } if (changed && strcmp(buffer, constData())) *changed = true; String::operator=(buffer); return true; } } return false; }
bool findIncludeFile (util::String const & inclname, util::String const & name, bool sys, util::String & fullname) { // if absolute then no need to search path bool result = false; if (isAbsolute (name)) { if (exists (name)) { result = true; fullname = name; } } // otherwise search in curent dir if not sys else if (! sys && findInDir (getPath (inclname), name, fullname)) { result = true; } else { // search in path list util::StringVector const & path_set = conf::getOptionValue (conf::opt_incl_path_set); result = std::find_if (path_set.begin (), path_set.end (), FindInDir (name, fullname)) != path_set.end (); } return result; }
void TemperatureUnit_Impl::operator/=(const Unit& rUnit) { Unit_Impl::operator/=(rUnit); OptionalTemperatureUnit rTUnit = rUnit.optionalCast<TemperatureUnit>(); if (!isAbsolute() && rTUnit && rTUnit->isAbsolute()) { setAsAbsolute(); } }
OSQuantityVector& OSQuantityVector::operator+=(OSQuantityVector rVector) { if (this == &rVector) { (*this) *= 2.0; return *this; } if (units() != rVector.units()) { LOG_AND_THROW("Cannot add OSQuantityVectors with different units (" << units() << " and " << rVector.units() << ")."); } unsigned n = size(); if (rVector.size() != n) { LOG_AND_THROW("Cannot add vectors of different sizes."); } if (scale() != rVector.scale()) { rVector.setScale(scale().exponent); } DoubleVector rValues = rVector.values(); for (unsigned i = 0; i < n; ++i) { m_values[i] += rValues[i]; } if (isTemperature() && rVector.isTemperature()) { if (!isAbsolute() && rVector.isAbsolute()) { setAsAbsolute(); } } return *this; }
/** * @brief Set the URL. * * @param url the new URL. * @param relative the doc2 that @p url is relative to, or 0 if @p url is an * absolute URL. */ void doc::seturl(const char * const url, const doc2 * const relative) { delete [] this->url_; this->url_ = 0; if (url) { std::string path; #ifdef _WIN32 // Convert windows path stream to standard URL char *p = (char *)url; for (; *p != '\0'; p++) { if (*p == '\\') { *p = '/'; } } #endif if (relative && !isAbsolute(url)) { path = relative->url_path(); } this->url_ = new char[path.length() + strlen(url) + 1]; strcpy(this->url_, path.c_str()); if (strlen(url) > 2 && url[0] == '.' && url[1] == '/') { strcat(this->url_, url + 2); // skip "./" } else { strcat(this->url_, url); } } }
Quantity& Quantity::operator+=(const Quantity& rQuantity) { if (this == &rQuantity) { m_value *= 2.0; return *this; } if (m_units != rQuantity.m_units) { LOG_AND_THROW("Cannot add quantities with different units."); } if (scale() != rQuantity.scale()) { Quantity wRQuantity(rQuantity); wRQuantity.setScale(scale().exponent); m_value += wRQuantity.value(); } else { m_value += rQuantity.value(); } if (isTemperature() && rQuantity.isTemperature()) { if (!isAbsolute() && rQuantity.isAbsolute()) { setAsAbsolute(); } } return *this; }
// remove any . or .. and make absolute if necessary Path& Path::normalize() { size_t i = 0; bool wasMadeAbsolute = isAbsolute(); while (i < mPaths.size()) { if (mPaths[i] == ".") { mPaths.erase(mPaths.begin()+i); } else if (mPaths[i] == "..") { if (i == 0) { if (wasMadeAbsolute) { // invalid path mPaths.clear(); break; } Path cwd = GetCurrentDir(); cwd.pop(); size_t sz = cwd.mPaths.size(); mPaths.erase(mPaths.begin()+i); mPaths.insert(mPaths.begin(), cwd.mPaths.begin(), cwd.mPaths.end()); i = sz; wasMadeAbsolute = true; } else { mPaths.erase(mPaths.begin()+i); mPaths.erase(mPaths.begin()+i-1); --i; } } else { ++i; } } mFullName = fullname(DIR_SEP); return *this; }
std::string Symbol::toString() const { std::string str; if(isAbsolute()) { str += "::"; } for (size_t i = 0; i < size(); i++) { if (i > 0) { str += "::"; } str += at(i)->name().toString(); const auto& templateArgs = at(i)->templateArguments(); if (!templateArgs->empty()) { str += "<"; for(size_t j = 0; j < templateArgs->size(); j++) { str += templateArgs->at(j)->toString(); } str += ">"; } } return str; }
/** * @brief Set the URL. * * @param url the new URL. * @param relative the doc that @p url is relative to, or 0 if @p url is an * absolute URL. */ void doc::seturl(const char * const url, const doc * const relative) { delete [] url_; url_ = 0; if (url) { const char *path = ""; #ifdef _WIN32 // Convert windows path stream to standard URL char *p = (char *)url; for(;*p != '\0';p++) if(*p == '\\')*p = '/'; #endif if ( relative && ! isAbsolute(url) ) path = relative->url_path(); url_ = new char[strlen(path) + strlen(url) + 1]; strcpy(url_, path); if (strlen(url)>2 && url[0] == '.' && url[1] == '/') strcat(url_, url+2); // skip "./" else strcat(url_, url); } }
String absolute(const String &path, bool writable) { if (path.empty()) { return ""; } if (path.front() == '%') { if (path.compare(0, "%CACHE%"_len, "%CACHE%") == 0) { return filesystem::cachesPath(path.substr(7), true); } else if (path.compare(0, "%DOCUMENTS%"_len, "%DOCUMENTS%") == 0) { return filesystem::documentsPath(path.substr(11), true); } else if (path.compare(0, "%WRITEABLE%"_len, "%WRITEABLE%") == 0) { return filesystem::writablePath(path.substr(11), true); } else if (path.compare(0, "%CURRENT%"_len, "%CURRENT%") == 0) { return filesystem::currentDir(path.substr(9), true); } else if (path.compare(0, "%PLATFORM%:"_len, "%PLATFORM%:") == 0) { return path; } } if (isAbsolute(path)) { return validatePath(path)?path:reconstructPath(path); } if (!writable && !isAboveRoot(path)) { if (validatePath(path)) { return platform::filesystem::_exists(path)?path:filesystem::writablePath(path); } else { auto ret = reconstructPath(path); return platform::filesystem::_exists(ret)?ret:filesystem::writablePath(ret); } } return validatePath(path)?filesystem::writablePath(path):reconstructPath(filesystem::writablePath(path)); }
char *Path::extractRoot( const char *inPathString ) { if( isAbsolute( inPathString ) ){ return stringDuplicate( "/" ); } else { return NULL; } }
/** * Get the absolute path matching the current path. * @return Matching absolute path. */ Path Path::absolute(void) const { if(isAbsolute()) return *this; else if(isHomeRelative()) return home() / Path(buf.substring(1)); else return current() / *this; }
// if path is relative, prepend current directory Path& Path::makeAbsolute() { if (!isAbsolute()) { Path cwd = GetCurrentDir(); mPaths.insert(mPaths.begin(), cwd.mPaths.begin(), cwd.mPaths.end()); mFullName = fullname(DIR_SEP); } return *this; }
filename_t* filename_t::parentDirectory (void) { ___CBTPUSH; char* name; int namelen; int* indices; filename_t* result; if (isRoot ()) { /* / */ result = this; reserve (); } else if (isReflexive ()) { /* . */ namelen = 2; allocateNameAndIndices (&name, namelen, &indices, 1); strcpy (name, ".."); indices[0] = namelen; result = new filename_t (name, indices, 1, 1); } else if (m_indexCount > 1) { /* /a/b, a/b, ../a */ namelen = m_indices[m_indexCount - 2]; allocateNameAndIndices (&name, namelen, &indices, m_indexCount - 1); SUBSTRING (name, m_name, namelen); memcpy (indices, m_indices, sizeof (int) * (m_indexCount - 1)); result = new filename_t (name, indices, m_indexCount - 1, m_parentDirs); } else if (isAbsolute ()) { /* /a */ namelen = 1; allocateNameAndIndices (&name, namelen, &indices, 1); strcpy (name, "/"); indices[0] = namelen; result = new filename_t (name, indices, 1, 0); } else if (m_parentDirs > 0) { /* .. */ namelen = m_indices[0] + 3; allocateNameAndIndices (&name, namelen, &indices, 1); stpcpy (stpcpy (name, m_name), "/.."); indices[0] = namelen; result = new filename_t (name, indices, 1, m_parentDirs + 1); } else { /* a */ namelen = 1; allocateNameAndIndices (&name, namelen, &indices, 1); strcpy (name, "."); indices[0] = namelen; result = new filename_t (name, indices, 1, 0); } ___CBTPOP; return result; }
OSQuantityVector& OSQuantityVector::operator-=(OSQuantityVector rVector) { unsigned n = size(); if (this == &rVector) { clear(); resize(n,0.0); return *this; } if (isTemperature() && rVector.isTemperature()) { if (isAbsolute() && rVector.isAbsolute()) { // units must be the same, check that exponent on this is 1 std::vector<std::string> bus = m_units.baseUnits(); assert(bus.size() == 1); if (m_units.baseUnitExponent(bus[0]) == 1) { setAsRelative(); rVector.setAsRelative(); } } else if (!isAbsolute() && rVector.isAbsolute()) { setAsAbsolute(); } else if (isAbsolute() && !rVector.isAbsolute()) { rVector.setAsAbsolute(); } } if (units() != rVector.units()) { LOG_AND_THROW("Cannot subtract OSQuantityVectors with different units (" << units() << " and " << rVector.units() << ")."); } if (rVector.size() != n) { LOG_AND_THROW("Cannot subtract vectors of different sizes."); } if (scale() != rVector.scale()) { rVector.setScale(scale().exponent); } DoubleVector rValues = rVector.values(); for (unsigned i = 0; i < n; ++i) { m_values[i] -= rValues[i]; } return *this; }
StorageObject * PosixStorageManager::makeStorageObject(const StringC &spec, const StringC &base, Boolean search, Boolean mayRewind, Messenger &mgr, StringC &found) { if (spec.size() == 0) { mgr.message(PosixStorageMessages::invalidFilename, StringMessageArg(spec)); return 0; } descriptorManager_.acquireD(); Boolean absolute = isAbsolute(spec); SearchResultMessageArg sr; for (size_t i = 0; i < searchDirs_.size() + 1; i++) { StringC filename; if (absolute) filename = spec; else if (i == 0) filename = combineDir(extractDir(base), spec); else filename = combineDir(searchDirs_[i - 1], spec); #ifdef SP_WIDE_SYSTEM String<FChar> cfilename(filename); cfilename += FChar(0); #else String<FChar> cfilename = filenameCodingSystem_->convertOut(filename); #endif int fd; do { fd = openFile(cfilename.data()); } while (fd < 0 && errno == EINTR); if (fd >= 0) { found = filename; return new PosixStorageObject(fd, filename, cfilename, mayRewind, &descriptorManager_); } int savedErrno = errno; if (absolute || !search || searchDirs_.size() == 0) { ParentLocationMessenger(mgr).message(PosixStorageMessages::openSystemCall, StringMessageArg(filename), ErrnoMessageArg(savedErrno)); descriptorManager_.releaseD(); return 0; } sr.add(filename, savedErrno); } descriptorManager_.releaseD(); ParentLocationMessenger(mgr).message(PosixStorageMessages::cannotFind, StringMessageArg(spec), sr); return 0; }
Name Name::makeAbsolute(const Name& name) const{ assert(isAbsolute()); assert(!name.empty()); if(name.isAbsolute()) { return name.copy(); } else { return concat(name); } }
Name Symbol::createName() const { Name name = isAbsolute() ? Name::Absolute() : Name::Relative(); for(size_t i = 0; i < list_.size(); i++) { name = name + list_.at(i)->name(); } return name; }
QString Qtilities::Core::QtilitiesFileInfo::actualPath() const { if (isAbsolute()) { return path(); } else if (isRelative()) { if (hasRelativeToPath()) return absoluteToRelativePath(); } return path(); }
UString FilePath::makeAbsolute(const UString &p) { UString absolute; if (isAbsolute(p)) absolute = p; else absolute = boost::filesystem::initial_path().string() + "/" + p.c_str(); return normalize(absolute); }
Quantity& Quantity::operator-=(const Quantity& temp) { if (this == &temp) { m_value = 0.0; return *this; } // copy input reference so we can change its properties Quantity rQuantity(temp); if (isTemperature() && rQuantity.isTemperature()) { if (isAbsolute() && rQuantity.isAbsolute()) { // units must be the same, check that exponent on this is 1 std::vector<std::string> bus = baseUnits(); OS_ASSERT(bus.size() == 1); if (baseUnitExponent(bus[0]) == 1) { setAsRelative(); rQuantity.setAsRelative(); } } else if (!isAbsolute() && rQuantity.isAbsolute()) { setAsAbsolute(); } else if (isAbsolute() && !rQuantity.isAbsolute()) { rQuantity.setAsAbsolute(); } } if (m_units != rQuantity.m_units) { LOG_AND_THROW("Cannot subtract quantities with different units."); } if (scale() != rQuantity.scale()) { Quantity wRQuantity(rQuantity); wRQuantity.setScale(scale().exponent); m_value -= wRQuantity.value(); } else { m_value -= rQuantity.value(); } return *this; }
void CKJVPassageNavigator::reset() { assert(!m_pBibleDatabase.isNull()); if (isAbsolute()) { setPassage(TPhraseTag(CRelIndex(1, 1, 1, 1), m_tagPassage.count())); // Default to Genesis 1:1 [1] } else { setPassage(TPhraseTag(CRelIndex(), m_tagPassage.count())); } ui.widgetPassageReference->clear(); }
Boolean PosixStorageManager::resolveRelative(const StringC &baseId, StringC &specId, Boolean search) const { if (isAbsolute(specId)) return 1; if (!search || searchDirs_.size() == 0) { specId = combineDir(extractDir(baseId), specId); return 1; } return 0; }
String File::normalizePath(const String &filePath) { String path = normalizeSeparators(filePath.trimmed()); if(!isAbsolute(path)) path = Directory::current() + WITCH_DIRECTORY_SEPARATOR + path; while(path.endsWith(WITCH_DIRECTORY_SEPARATOR)) path.resize(-1); return path; }