[Groonga-commit] groonga/grnxx at 757a72c [new_data_types] Add String::clone().

Zurück zum Archiv-Index

susumu.yata null+****@clear*****
Thu Nov 27 21:18:40 JST 2014


susumu.yata	2014-11-27 21:18:40 +0900 (Thu, 27 Nov 2014)

  New Revision: 757a72cac9c7dc03ae7acba9dcf4f8ad8b03f361
  https://github.com/groonga/grnxx/commit/757a72cac9c7dc03ae7acba9dcf4f8ad8b03f361

  Message:
    Add String::clone().

  Modified files:
    include/grnxx/string.hpp
    lib/grnxx/string.cpp

  Modified: include/grnxx/string.hpp (+6 -0)
===================================================================
--- include/grnxx/string.hpp    2014-11-27 21:10:32 +0900 (cb26266)
+++ include/grnxx/string.hpp    2014-11-27 21:18:40 +0900 (e311988)
@@ -79,6 +79,12 @@ class String {
     return capacity_ != 0;
   }
 
+  // Create a clone instance of "this".
+  //
+  // On success, returns the instance.
+  // On failure, throws an exception.
+  String clone() const;
+
   // Instanciate the string.
   //
   // On success, returns a reference to "this".

  Modified: lib/grnxx/string.cpp (+6 -0)
===================================================================
--- lib/grnxx/string.cpp    2014-11-27 21:10:32 +0900 (7e74c34)
+++ lib/grnxx/string.cpp    2014-11-27 21:18:40 +0900 (1d6cfc3)
@@ -47,6 +47,12 @@ String::String(size_t size, char byte)
   capacity_ = size;
 }
 
+String String::clone() const {
+  String clone(size_);
+  std::memcpy(clone.buffer_, data_, size_);
+  return clone;
+}
+
 String &String::instantiate() {
   if (is_empty() || is_instance()) {
     // Nothing to do.
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index