Пример #1
0
      ScopedTemporaryFlagsChanger(Flags toFlags) {
        count_ = new int[MAXNUM];
        if (! count_) return;

        for (int i = 0;; ++i) {
          count_[i] = 0;

          ModifierFlag flag = getFlag(i);
          if (flag == ModifierFlag::NONE) break;

          // ----------------------------------------
          // reset flag
          while (! makeFlags().isOn(flag)) {
            temporary_increase(flag);
            ++count_[i];
          }
          while (makeFlags().isOn(flag)) {
            temporary_decrease(flag);
            --count_[i];
          }

          // ----------------------------------------
          // set a flag
          if (toFlags.isOn(flag)) {
            temporary_increase(flag);
            ++count_[i];
          }
        }
      }
Пример #2
0
/**
 * Open a random access stream from a file.
 * @param path			Path of the file to open.
 * @param access		Type of access (one of READ, WRITE, READ_WRITE).
 * @return				Opened file.
 * @throws IOException	Thrown if there is an error.
 */
io::RandomAccessStream *System::openRandomFile(
		const sys::Path& path,
		access_t access )
throw(SystemException)
{
	int fd = ::open(&path.toString(), makeFlags(access));
	if(fd < 0)
		throw SystemException(errno, _ << "cannot open \"" << path << "\"");
	else
#		if defined(__unix)  || defined(__APPLE__)
			return new UnixRandomAccessStream(fd);
#		elif defined(__WIN32) || defined(__WIN64)
			return new WinRandomAccessStream(fd);
#		else
#			error "Unsupported on this OS !"
#		endif
};
Пример #3
0
/**
 * Create a random access stream from a file, removing it if it already exists.
 * @param path			Path of the file to open.
 * @param access		Type of access (one of READ, WRITE, READ_WRITE).
 * @return				Opened file.
 * @throws IOException	Thrown if there is an error.
 */
io::RandomAccessStream *System::createRandomFile(
		const sys::Path& path,
		access_t access)
throw(SystemException)
{
	ASSERTP(access != READ, "file creation requires at least a write mode");
	int fd = ::open(&path.toString(), makeFlags(access) | O_CREAT | O_TRUNC, 0666);
	if(fd < 0)
		throw SystemException(errno, _ << "cannot create \"" << path << "\"");
	else
#		if defined(__unix)  || defined(__APPLE__)
			return new UnixRandomAccessStream(fd);
#		elif defined(__WIN32) || defined(__WIN64)
			return new WinRandomAccessStream(fd);
#		else
#			error "Unsupported on this OS !"
#		endif
}
Пример #4
0
/*
    Cast the operand to the specified type

    function cast(type: Type) : Object
 */
static EjsAny *castRegExp(Ejs *ejs, EjsRegExp *rp, EjsType *type)
{
    char    *flags;

    switch (type->sid) {
    case S_Boolean:
        return ESV(true);

    case S_String:
        flags = makeFlags(rp);
        return ejsSprintf(ejs, "/%w/%s", rp->pattern, flags);

    default:
        ejsThrowTypeError(ejs, "Can't cast to this type");
        return 0;
    }
    return 0;
}
Пример #5
0
/*
    Cast the operand to the specified type

    function cast(type: Type) : Object
 */
static EjsAny *castRegExp(Ejs *ejs, EjsRegExp *rp, EjsType *type)
{
    wchar   *pattern;
    char    *flags;
    ssize   len, flen;
    int     i, j;

    switch (type->sid) {
    case S_Boolean:
        return ESV(true);

    case S_String:
        flags = makeFlags(rp);
        len = wlen(rp->pattern);
        flen = wlen(flags);
        pattern = mprAlloc((len * 2 + flen + 1) * sizeof(wchar));
        /*
            Convert to a form that is a valid, parsable as regular expression literal
         */
        pattern[0] = '/';
        for (i = 0, j = 1; i < len; i++) {
            if (rp->pattern[i] == '/') {
                pattern[j++] = '\\';
            }
            pattern[j++] = rp->pattern[i];
        }
        pattern[j++] = '/';
        for (i = 0; i < flen; i++) {
            pattern[j++] = flags[i];
        }
        pattern[j] = 0;
        return ejsCreateStringFromAsc(ejs, pattern);

    default:
        ejsThrowTypeError(ejs, "Cannot cast to this type");
        return 0;
    }
    return 0;
}