From: Lucian Grijincu Date: Tue, 28 Jan 2014 23:43:20 +0000 (-0800) Subject: folly: File explicit ctor X-Git-Tag: v0.22.0~720 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=82275df6fc89e0c86556c73d49858b40a5691b78;p=folly.git folly: File explicit ctor Summary: explicit ctor Test Plan: contbuild Reviewed By: andrei.alexandrescu@fb.com FB internal diff: D1134033 Blame Revision: D1133938 --- diff --git a/folly/File.h b/folly/File.h index 1c6793fa..39136d4a 100644 --- a/folly/File.h +++ b/folly/File.h @@ -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(); diff --git a/folly/MemoryMapping.cpp b/folly/MemoryMapping.cpp index a6f6dd97..e08cea90 100644 --- a/folly/MemoryMapping.cpp +++ b/folly/MemoryMapping.cpp @@ -1,5 +1,5 @@ /* - * 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, diff --git a/folly/MemoryMapping.h b/folly/MemoryMapping.h index 3a355892..85f804da 100644 --- a/folly/MemoryMapping.h +++ b/folly/MemoryMapping.h @@ -1,5 +1,5 @@ /* - * 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(); /** diff --git a/folly/experimental/FileGen-inl.h b/folly/experimental/FileGen-inl.h index 79f8a1dd..c3a7f94b 100644 --- a/folly/experimental/FileGen-inl.h +++ b/folly/experimental/FileGen-inl.h @@ -121,6 +121,7 @@ class FileWriter : public Operator { }; } // !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