add __nonzero__, respect lockf() return value

This commit is contained in:
David Rose 2009-08-05 21:50:58 +00:00
parent 661af56d60
commit 9f9316ff81
3 changed files with 29 additions and 3 deletions

View File

@ -572,6 +572,23 @@ compare_to(const Filename &other) const {
}
////////////////////////////////////////////////////////////////////
// Function: Filename::__nonzero__
// Access: Published
// Description: Returns true if the Filename is valid (not empty),
// or false if it is an empty string.
//
// This implements the Python equivalent to operator
// bool. Defining an actual operator bool method for
// C++ use would work too, but it seems to cause too
// many ambiguities for the C++ compiler, so we use this
// Python-only approach instead.
////////////////////////////////////////////////////////////////////
INLINE bool Filename::
__nonzero__() const {
return !_filename.empty();
}
////////////////////////////////////////////////////////////////////
// Function: Filename::output
// Access: Published

View File

@ -1559,7 +1559,7 @@ get_file_size() const {
bool Filename::
resolve_filename(const DSearchPath &searchpath,
const string &default_extension) {
string found;
Filename found;
if (is_local()) {
found = searchpath.find_file(*this);
@ -2586,7 +2586,11 @@ atomic_compare_and_exchange_contents(string &orig_contents,
orig_contents = string();
lockf(fd, F_LOCK, 0);
if (lockf(fd, F_LOCK, 0) != 0) {
perror(os_specific.c_str());
close(fd);
return false;
}
size_t bytes_read = read(fd, buf, buf_size);
while (bytes_read > 0) {
@ -2699,7 +2703,11 @@ atomic_read_contents(string &contents) const {
contents = string();
lockf(fd, F_LOCK, 0);
if (lockf(fd, F_LOCK, 0) != 0) {
perror(os_specific.c_str());
close(fd);
return false;
}
size_t bytes_read = read(fd, buf, buf_size);
while (bytes_read > 0) {

View File

@ -204,6 +204,7 @@ PUBLISHED:
INLINE bool operator != (const string &other) const;
INLINE bool operator < (const string &other) const;
INLINE int compare_to(const Filename &other) const;
INLINE bool __nonzero__() const;
INLINE void output(ostream &out) const;