I'll find a solution for the 'dirList problem', Abdel.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21884 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-30 20:57:53 +00:00
parent ff381ed2fa
commit 5c4a20fe04
12 changed files with 212 additions and 65 deletions

124
development/attic/cow_ptr.h Normal file
View File

@ -0,0 +1,124 @@
// -*- C++ -*-
/**
* \file cow_ptr.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* A pointer with copy-on-write semantics
*
* The original version of this class was written by Yonat Sharon
* and is freely available at http://ootips.org/yonat/
*
* I modified it to use boost::shared_ptr internally, rather than use his
* home-grown equivalent.
*/
#ifndef COW_PTR_H
#define COW_PTR_H
#include <boost/shared_ptr.hpp>
namespace lyx {
namespace support {
template <typename T>
class cow_ptr {
public:
explicit cow_ptr(T * = 0);
cow_ptr(cow_ptr const &);
cow_ptr & operator=(cow_ptr const &);
T const & operator*() const;
T const * operator->() const;
T const * get() const;
T & operator*();
T * operator->();
T * get();
private:
boost::shared_ptr<T> ptr_;
void copy();
};
template <typename T>
cow_ptr<T>::cow_ptr(T * p)
: ptr_(p)
{}
template <typename T>
cow_ptr<T>::cow_ptr(cow_ptr const & other)
: ptr_(other.ptr_)
{}
template <typename T>
cow_ptr<T> & cow_ptr<T>::operator=(cow_ptr const & other)
{
if (&other != this)
ptr_ = other.ptr_;
return *this;
}
template <typename T>
T const & cow_ptr<T>::operator*() const
{
return *ptr_;
}
template <typename T>
T const * cow_ptr<T>::operator->() const
{
return ptr_.get();
}
template <typename T>
T const * cow_ptr<T>::get() const
{
return ptr_.get();
}
template <typename T>
T & cow_ptr<T>::operator*()
{
copy();
return *ptr_;
}
template <typename T>
T * cow_ptr<T>::operator->()
{
copy();
return ptr_.get();
}
template <typename T>
T * cow_ptr<T>::get()
{
copy();
return ptr_.get();
}
template <typename T>
void cow_ptr<T>::copy()
{
if (!ptr_.unique())
ptr_ = boost::shared_ptr<T>(new T(*ptr_.get()));
}
} // namespace support
} // namespace lyx
#endif // NOT COW_PTR_H

View File

@ -20,11 +20,12 @@ t=0
#for i in `find ../../src/support -name '*.cpp'` ; do
#for i in `find ../../src/graphics -name '*.cpp'` ; do
#for i in `find ../../src/graphics -name '*.cpp'` ; do
#for i in ../../src/*.cpp ; do
#for i in `find ../../src/support/chdir.cpp` ; do
for i in `find ../.. -name '*.cpp'` ; do
#echo $i
#echo "g++ $inc -DQT_NO_STL -E $i"
#g++ $inc -DQT_NO_STL -E $i > tmp/`basename $i`
g++ $inc -DQT_NO_STL -E $i > t
l=`g++ $inc -DQT_NO_STL -E $i | wc -l`
f=`cat $i | wc -l`
s=$[s + l]

View File

@ -519,8 +519,8 @@ bool Converters::move(string const & fmt,
string const to_base = removeExtension(to.absFilename());
string const to_extension = getExtension(to.absFilename());
vector<FileName> const files = FileName(path).dirList(
getExtension(from.absFilename()));
vector<FileName> const files =
support::dirList(FileName(path), getExtension(from.absFilename()));
for (vector<FileName>::const_iterator it = files.begin();
it != files.end(); ++it) {
string const from2 = it->absFilename();

View File

@ -15,6 +15,7 @@
#include "support/FileName.h"
#include <string>
#include <vector>
/**

View File

@ -15,6 +15,7 @@
#include "support/FileName.h"
#include <map>
#include <string>
#include <vector>
namespace lyx {

View File

@ -11,10 +11,10 @@
#include <config.h>
#include "support/debug.h"
#include "LyX.h"
#include "support/gettext.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/os.h"
#include <iostream>
@ -33,6 +33,8 @@ int main(int argc, char * argv[])
// early as possible.
lyx::lyxerr.setStream(std::cerr);
LYXERR0("acssdc");
lyx::support::os::init(argc, argv);
// initialize for internationalized version *EK*

View File

@ -268,7 +268,7 @@ static bool rmdir(QFileInfo const & fi)
QDir dir(fi.absoluteFilePath());
QFileInfoList list = dir.entryInfoList();
bool global_success = true;
for (int i = 0; i < list.size(); ++i) {
for (int i = 0; i != list.size(); ++i) {
if (list.at(i).fileName() == ".")
continue;
if (list.at(i).fileName() == "..")
@ -313,16 +313,15 @@ bool FileName::createDirectory(int permission) const
}
std::vector<FileName> FileName::dirList(std::string const & ext)
std::vector<FileName> dirList(FileName const & dirname, std::string const & ext)
{
std::vector<FileName> dirlist;
if (!exists() || !isDirectory()) {
lyxerr << "FileName::dirList(): Directory \"" << absFilename()
<< "\" does not exist!" << endl;
if (!dirname.isDirectory()) {
LYXERR0("Directory '" << dirname << "' does not exist!");
return dirlist;
}
QDir dir(d->fi.absoluteFilePath());
QDir dir(dirname.d->fi.absoluteFilePath());
if (!ext.empty()) {
QString filter;
@ -332,17 +331,16 @@ std::vector<FileName> FileName::dirList(std::string const & ext)
default: filter = "*." + toqstr(ext);
}
dir.setNameFilters(QStringList(filter));
LYXERR(Debug::FILES, "FileName::dirList(): filtering on extension "
<< fromqstr(filter) << " is requested." << endl);
LYXERR(Debug::FILES, "filtering on extension "
<< fromqstr(filter) << " is requested.");
}
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
for (int i = 0; i != list.size(); ++i) {
FileName fi;
fi.d->fi = list.at(i);
dirlist.push_back(fi);
LYXERR(Debug::FILES, "FileName::dirList(): found file "
<< fi.absFilename() << endl);
LYXERR(Debug::FILES, "found file " << fi);
}
return dirlist;
@ -641,20 +639,20 @@ void DocFileName::erase()
}
string const DocFileName::relFilename(string const & path) const
string DocFileName::relFilename(string const & path) const
{
// FIXME UNICODE
return to_utf8(makeRelPath(qstring_to_ucs4(d->fi.absoluteFilePath()), from_utf8(path)));
}
string const DocFileName::outputFilename(string const & path) const
string DocFileName::outputFilename(string const & path) const
{
return save_abs_path_ ? absFilename() : relFilename(path);
}
string const DocFileName::mangledFilename(std::string const & dir) const
string DocFileName::mangledFilename(std::string const & dir) const
{
// We need to make sure that every DocFileName instance for a given
// filename returns the same mangled name.
@ -726,7 +724,7 @@ bool DocFileName::isZipped() const
}
string const DocFileName::unzippedFilename() const
string DocFileName::unzippedFilename() const
{
return unzippedFileName(absFilename());
}

View File

@ -15,14 +15,11 @@
#include "support/strfwd.h"
#include <ctime>
#include <string>
#include <vector>
namespace lyx {
namespace support {
/**
* Class for storing file names.
* The file name may be empty. If it is not empty it is an absolute path.
@ -101,10 +98,6 @@ public:
/// Creates directory. Returns true on success
bool createDirectory(int permissions) const;
/// \return list files in a directory having optional extension ext..
std::vector<FileName> dirList(
std::string const & ext = std::string());
/// Get the contents of a file as a huge std::string
std::string fileContents() const;
/**
@ -119,7 +112,7 @@ public:
* If oldname does not have an extension, it is appended.
* If the extension is empty, any extension is removed from the name.
*/
void changeExtension(std::string const & extension);
void changeExtension(std::string const & extension);
/** Guess the file format name (as in Format::name()) from contents.
Normally you don't want to use this directly, but rather
@ -134,7 +127,7 @@ public:
/// (securely) create a temporary file in the given dir with the given mask
/// \p mask must be in filesystem encoding
static FileName tempName(FileName const & dir = FileName(),
std::string const & mask = std::string());
std::string const & mask = empty_string());
/// filename without path
std::string onlyFileName() const;
@ -143,7 +136,7 @@ public:
/// used for display in the Gui
docstring displayName(int threshold = 1000) const;
private:
//private:
friend class DocFileName;
///
struct Private;
@ -184,9 +177,9 @@ public:
bool saveAbsPath() const { return save_abs_path_; }
/// \param buffer_path if empty, uses `pwd`
std::string const relFilename(std::string const & buffer_path = std::string()) const;
std::string relFilename(std::string const & buffer_path = empty_string()) const;
/// \param buf_path if empty, uses `pwd`
std::string const outputFilename(std::string const & buf_path = std::string()) const;
std::string outputFilename(std::string const & buf_path = empty_string()) const;
/** @returns a mangled representation of the absolute file name
* suitable for use in the temp dir when, for example, converting
@ -208,13 +201,13 @@ public:
* Only the mangled file name is returned. It is not prepended
* with @c dir.
*/
std::string const
mangledFilename(std::string const & dir = std::string()) const;
std::string
mangledFilename(std::string const & dir = empty_string()) const;
/// \return true if the file is compressed.
bool isZipped() const;
/// \return the absolute file name without its .gz, .z, .Z extension
std::string const unzippedFilename() const;
std::string unzippedFilename() const;
private:
bool save_abs_path_;

View File

@ -275,6 +275,10 @@ typedef std::pair<int, std::string> cmd_ret;
cmd_ret const runCommand(std::string const & cmd);
/// \return list files in a directory having optional extension ext..
std::vector<FileName> dirList(FileName const & dir,
std::string const & ext = empty_string());
} // namespace support
} // namespace lyx

View File

@ -42,6 +42,22 @@ using std::toupper;
namespace lyx {
// Using this allows us to have docstring default arguments in headers
// without #include "support/docstring" there.
docstring const & empty_docstring()
{
static docstring s;
return s;
}
// Using this allows us to have std::string default arguments in headers
// without #include <string>
std::string const & empty_string()
{
static std::string s;
return s;
}
/**
* Convert a QChar into a UCS4 character.
* This is a hack (it does only make sense for the common part of the UCS4
@ -232,73 +248,77 @@ int compare_ascii_no_case(docstring const & s, docstring const & s2)
bool isStrInt(string const & str)
{
if (str.empty()) return false;
if (str.empty())
return false;
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
if (tmpstr.empty()) return false;
if (tmpstr.empty())
return false;
string::const_iterator cit = tmpstr.begin();
if ((*cit) == '-') ++cit;
if ((*cit) == '-')
++cit;
string::const_iterator end = tmpstr.end();
for (; cit != end; ++cit) {
if (!isdigit((*cit))) return false;
}
for (; cit != end; ++cit)
if (!isdigit((*cit)))
return false;
return true;
}
bool isStrUnsignedInt(string const & str)
{
if (str.empty()) return false;
if (str.empty())
return false;
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
if (tmpstr.empty()) return false;
if (tmpstr.empty())
return false;
string::const_iterator cit = tmpstr.begin();
string::const_iterator end = tmpstr.end();
for (; cit != end; ++cit) {
if (!isdigit((*cit))) return false;
}
for (; cit != end; ++cit)
if (!isdigit((*cit)))
return false;
return true;
}
bool isStrDbl(string const & str)
{
if (str.empty()) return false;
if (str.empty())
return false;
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
if (tmpstr.empty()) return false;
// if (1 < tmpstr.count('.')) return false;
if (tmpstr.empty())
return false;
// if (tmpstr.count('.') > 1) return false;
string::const_iterator cit = tmpstr.begin();
bool found_dot(false);
if ((*cit) == '-') ++cit;
bool found_dot = false;
if (*cit == '-')
++cit;
string::const_iterator end = tmpstr.end();
for (; cit != end; ++cit) {
if (!isdigit((*cit))
&& '.' != (*cit)) {
if (!isdigit(*cit) && *cit != '.')
return false;
}
if ('.' == (*cit)) {
if (found_dot) {
if (found_dot)
return false;
} else {
found_dot = true;
}
found_dot = true;
}
}
return true;
}
namespace {
inline
bool isHexChar(char_type c)
static bool isHexChar(char_type c)
{
return c == '0' ||
c == '1' ||
@ -318,8 +338,6 @@ bool isHexChar(char_type c)
c == 'f' || c == 'F';
}
} // anon namespace
bool isHex(docstring const & str)
{
@ -567,7 +585,8 @@ string const token(string const & a, char delim, int n)
docstring const token(docstring const & a, char_type delim, int n)
{
if (a.empty()) return docstring();
if (a.empty())
return docstring();
size_t k = 0;
size_t i = 0;

View File

@ -19,6 +19,7 @@
#include "support/docstring.h"
#include <cstring>
#include <string>
#include <vector>

View File

@ -67,6 +67,9 @@ typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream;
extern odocstream & operator<<(odocstream &, char);
#endif
docstring const & empty_docstring();
std::string const & empty_string();
} // namespace lyx
#endif