Commit 82275df6 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Sara Golemon

folly: File explicit ctor

Summary: explicit ctor

Test Plan: contbuild

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1134033

Blame Revision: D1133938
parent afa85fd0
......@@ -38,15 +38,12 @@ class File {
* Create a File object from an existing file descriptor.
* Takes ownership of the file descriptor if ownsFd is true.
*/
/* implicit */ File(int fd,
bool ownsFd = false);
explicit File(int fd, bool ownsFd = false);
/**
* Open and create a file object. Throws on error.
*/
/* implicit */ File(const char* name,
int flags = O_RDONLY,
mode_t mode = 0644);
explicit File(const char* name, int flags = O_RDONLY, mode_t mode = 0644);
~File();
......
/*
* Copyright 2013 Facebook, Inc.
* Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -44,6 +44,12 @@ MemoryMapping::MemoryMapping(File file, off_t offset, off_t length)
init(std::move(file), offset, length, PROT_READ, false);
}
MemoryMapping::MemoryMapping(const char* name, off_t offset, off_t length)
: MemoryMapping(File(name), offset, length) { }
MemoryMapping::MemoryMapping(int fd, off_t offset, off_t length)
: MemoryMapping(File(fd), offset, length) { }
void MemoryMapping::init(File file,
off_t offset, off_t length,
int prot,
......
/*
* Copyright 2013 Facebook, Inc.
* Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -56,6 +56,14 @@ class MemoryMapping : boost::noncopyable {
off_t offset=0,
off_t length=-1);
explicit MemoryMapping(const char* name,
off_t offset=0,
off_t length=-1);
explicit MemoryMapping(int fd,
off_t offset=0,
off_t length=-1);
virtual ~MemoryMapping();
/**
......
......@@ -121,6 +121,7 @@ class FileWriter : public Operator<FileWriter> {
};
} // !detail
/**
* Generator which reads lines from a file.
* Note: This produces StringPieces which reference temporary strings which are
......@@ -135,4 +136,10 @@ inline auto byLine(File file, char delim = '\n')
| resplit(delim);
}
inline auto byLine(int fd, char delim = '\n')
-> decltype(byLine(File(fd), delim)) { return byLine(File(fd), delim); }
inline auto byLine(const char* f, char delim = '\n')
-> decltype(byLine(File(f), delim)) { return byLine(File(f), delim); }
}} // !folly::gen
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment