LCOV - code coverage report
Current view: top level - gi - value.h (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 70.0 % 10 7
Test Date: 2024-04-20 17:42:51 Functions: 80.0 % 5 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2008 litl, LLC
       4                 :             : 
       5                 :             : #ifndef GI_VALUE_H_
       6                 :             : #define GI_VALUE_H_
       7                 :             : 
       8                 :             : #include <config.h>
       9                 :             : 
      10                 :             : #include <utility>  // for move, swap
      11                 :             : #include <vector>   // for vector
      12                 :             : 
      13                 :             : #include <glib-object.h>
      14                 :             : 
      15                 :             : #include <js/TypeDecls.h>
      16                 :             : 
      17                 :             : #include "gjs/macros.h"
      18                 :             : 
      19                 :             : namespace Gjs {
      20                 :             : struct AutoGValue : GValue {
      21                 :        1490 :     AutoGValue() : GValue(G_VALUE_INIT) {
      22                 :             :         static_assert(sizeof(AutoGValue) == sizeof(GValue));
      23                 :        1490 :     }
      24                 :        1430 :     explicit AutoGValue(GType gtype) : AutoGValue() {
      25                 :        1430 :         g_value_init(this, gtype);
      26                 :        1430 :     }
      27                 :           0 :     AutoGValue(AutoGValue const& src) : AutoGValue(G_VALUE_TYPE(&src)) {
      28                 :           0 :         g_value_copy(&src, this);
      29                 :           0 :     }
      30                 :             :     AutoGValue& operator=(AutoGValue other) {
      31                 :             :         // We need to cast to GValue here not to make swap to recurse here
      32                 :             :         std::swap(*static_cast<GValue*>(this), *static_cast<GValue*>(&other));
      33                 :             :         return *this;
      34                 :             :     }
      35                 :             :     AutoGValue(AutoGValue&& src) {
      36                 :             :         switch (G_VALUE_TYPE(&src)) {
      37                 :             :             case G_TYPE_NONE:
      38                 :             :             case G_TYPE_CHAR:
      39                 :             :             case G_TYPE_UCHAR:
      40                 :             :             case G_TYPE_BOOLEAN:
      41                 :             :             case G_TYPE_INT:
      42                 :             :             case G_TYPE_UINT:
      43                 :             :             case G_TYPE_LONG:
      44                 :             :             case G_TYPE_ULONG:
      45                 :             :             case G_TYPE_INT64:
      46                 :             :             case G_TYPE_UINT64:
      47                 :             :             case G_TYPE_FLOAT:
      48                 :             :             case G_TYPE_DOUBLE:
      49                 :             :                 *static_cast<GValue*>(this) =
      50                 :             :                     std::move(static_cast<GValue const&&>(src));
      51                 :             :                 break;
      52                 :             :             default:
      53                 :             :                 // We can't safely move in complex cases, so let's just copy
      54                 :             :                 this->steal();
      55                 :             :                 *this = src;
      56                 :             :                 g_value_unset(&src);
      57                 :             :         }
      58                 :             :     }
      59                 :           3 :     void steal() { *static_cast<GValue*>(this) = G_VALUE_INIT; }
      60                 :        1489 :     ~AutoGValue() { g_value_unset(this); }
      61                 :             : };
      62                 :             : }  // namespace Gjs
      63                 :             : 
      64                 :             : using AutoGValueVector = std::vector<Gjs::AutoGValue>;
      65                 :             : 
      66                 :             : GJS_JSAPI_RETURN_CONVENTION
      67                 :             : bool       gjs_value_to_g_value         (JSContext      *context,
      68                 :             :                                          JS::HandleValue value,
      69                 :             :                                          GValue         *gvalue);
      70                 :             : GJS_JSAPI_RETURN_CONVENTION
      71                 :             : bool       gjs_value_to_g_value_no_copy (JSContext      *context,
      72                 :             :                                          JS::HandleValue value,
      73                 :             :                                          GValue         *gvalue);
      74                 :             : 
      75                 :             : GJS_JSAPI_RETURN_CONVENTION
      76                 :             : bool gjs_value_from_g_value(JSContext             *context,
      77                 :             :                             JS::MutableHandleValue value_p,
      78                 :             :                             const GValue          *gvalue);
      79                 :             : 
      80                 :             : 
      81                 :             : #endif  // GI_VALUE_H_
        

Generated by: LCOV version 2.0-1