folly: File explicit ctor
authorLucian Grijincu <lucian@fb.com>
Tue, 28 Jan 2014 23:43:20 +0000 (15:43 -0800)
committerSara Golemon <sgolemon@fb.com>
Thu, 6 Feb 2014 19:50:13 +0000 (11:50 -0800)
Summary: explicit ctor

Test Plan: contbuild

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1134033

Blame Revision: D1133938

folly/File.h
folly/MemoryMapping.cpp
folly/MemoryMapping.h
folly/experimental/FileGen-inl.h

index 1c6793fa72346dda229e739c40d34de914a5a88d..39136d4a5228fbcce72dd46ab71001b89f33a3e9 100644 (file)
@@ -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();
 
index a6f6dd97432d370d8815aeeee14e7d063096dd96..e08cea90ae729d5faf7980700b160fde67925bd4 100644 (file)
@@ -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,
index 3a355892ed01397808a43e1ee9248ca95a941ac8..85f804dadd006d5cbf746ccd2f773949fa0d6712 100644 (file)
@@ -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();
 
   /**
index 79f8a1dde4e4b9ca67146cd8d68415f5bf1ce492..c3a7f94bf7f5a0f47ccf0cba80a99ebdb27b9891 100644 (file)
@@ -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