示例#1
0
文件: File.cpp 项目: mfichman/jogo
File::Iterator::Iterator(const std::string& file) :
#ifdef WINDOWS
    handle_(FindFirstFile((file+"\\*").c_str(), &data_)) {
#else
    handle_(opendir(file.c_str())),
    entry_(handle_ ? readdir((DIR*)handle_) : 0) {
#endif
}

File::Iterator::~Iterator() {
#ifdef WINDOWS
    FindClose(handle_);
#else
    if (handle_) { closedir((DIR*)handle_); }
#endif
}

const File::Iterator& File::Iterator::operator++() {
#ifdef WINDOWS
    if (!FindNextFile(handle_, &data_)) {
        FindClose(handle_);
        handle_ = INVALID_HANDLE_VALUE;
    }
#else
    entry_ = handle_ ? readdir((DIR*)handle_) : 0;
#endif
    return *this;
}

std::string File::Iterator::operator*() const {
#ifdef WINDOWS
    return std::string(data_.cFileName);
#else
    return std::string(((dirent*)entry_)->d_name);
#endif
}

File::Iterator::operator bool() const {
#ifdef WINDOWS
    return handle_ != INVALID_HANDLE_VALUE;
#else
    return entry_ != 0;
#endif
}

void File::unlink(std::string const& name) {
#ifdef WINDOWS
    DeleteFile(name.c_str());
#else
    ::unlink(name.c_str());
#endif
}
示例#2
0
	// call()
	//
	Object *AddInFunction::call( Interpreter *interpreter, Scope *scope, List *parameters, const std::string &callScope )
	{

		return entry_( interpreter, scope, parameters );
	}