?? paco.h
字號:
//=======================================================================// paco.h//-----------------------------------------------------------------------// This file is part of the package paco// Copyright (C) 2004-2007 David Rosal <david.3r@gmail.com>// For more information visit http://paco.sourceforge.net//=======================================================================#ifndef LIBPACO_PACO_H#define LIBPACO_PACO_H#include <stdexcept>#include <iosfwd>#include <sstream>namespace Paco{ // Types and constants //-------------------- int const HUMAN_READABLE = -1; int const BYTE = 1; int const KILOBYTE = 1024; int const MEGABYTE = 1048576; typedef enum { NO_SORT = 0, SORT_NAME = 1, SORT_SIZE = 2, // alias for SORT_SIZE_INST SORT_SIZE_INST = 2, SORT_SIZE_MISS = 3, SORT_FILES_INST = 4, SORT_FILES_MISS = 5, SORT_DATE = 6 } SortType; // Exceptions //----------- class X : public std::runtime_error { public: X(std::string const& msg); }; class XErrno : public std::runtime_error { public: XErrno(std::string const& msg); }; // Global free functions and classes //---------------------------------- // A safer std::{i,o}fstream template<typename T> // T = std::{i,o}fstream class FileStream : public T { public: FileStream(std::string const& path) : T(path.c_str()) { if (!this) throw XErrno(path); this->exceptions(std::ios::badbit); } }; extern std::string sizeStr(int unit, float size); extern std::string sizeStr(int unit, long size); extern bool inPaths(std::string const&, std::string const&); template <typename T> // T = {int,long,unsigned,...} T str2num(std::string const& s) { std::istringstream is(s); T t; is >> t; return t; } // // Apply a function to an STL container // (from "Thinking in C++ vol. 2") // // const, 1 argument, any type of return value template <typename Seq, typename T, typename R, typename A> void apply(Seq& s, R (T::*f)(A) const, A a) { for (typename Seq::iterator it = s.begin(); it != s.end(); ++it) ((*it)->*f)(a); } // non-const, 1 argument, any type of return value template <typename Seq, typename T, typename R, typename A> void apply(Seq& s, R (T::*f)(A), A a) { for (typename Seq::iterator it = s.begin(); it != s.end(); ++it) ((*it)->*f)(a); } // const, 1 reference argument, any type of return value template <typename Seq, typename T, typename R, typename A> void apply(Seq& s, R (T::*f)(A&) const, A& a) { for (typename Seq::iterator it = s.begin(); it != s.end(); ++it) ((*it)->*f)(a); } // non-const, 1 reference argument, any type of return value template <typename Seq, typename T, typename R, typename A> void apply(Seq& s, R (T::*f)(A&), A& a) { for (typename Seq::iterator it = s.begin(); it != s.end(); ++it) ((*it)->*f)(a); }} // namespace Paco#endif // LIBPACO_PACO_H
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -