LCOV - code coverage report
Current view: top level - xenolith/platform - XLViewCommandLine.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 81 0.0 %
Date: 2024-05-12 00:16:13 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLViewCommandLine.h"
      24             : 
      25             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      26             : 
      27           0 : Value ViewCommandLineData::encode() const {
      28           0 :         Value ret;
      29           0 :         ret.setString(bundleName, "bundleName");
      30           0 :         ret.setString(applicationName, "applicationName");
      31           0 :         ret.setString(applicationVersion, "applicationVersion");
      32           0 :         ret.setString(userLanguage, "userLanguage");
      33           0 :         if (!launchUrl.empty()) {
      34           0 :                 ret.setString(userLanguage, "userLanguage");
      35             :         }
      36           0 :         ret.setValue(Value({Value(screenSize.width), Value(screenSize.height)}), "screenSize");
      37           0 :         ret.setValue(Value({Value(viewDecoration.top), Value(viewDecoration.right),
      38           0 :                 Value(viewDecoration.bottom), Value(viewDecoration.left)}), "viewDecoration");
      39           0 :         ret.setDouble(density, "density");
      40           0 :         if (isPhone) {
      41           0 :                 ret.setBool(isPhone, "isPhone");
      42             :         }
      43           0 :         if (isFixed) {
      44           0 :                 ret.setBool(isFixed, "isFixed");
      45             :         }
      46           0 :         if (renderdoc) {
      47           0 :                 ret.setBool(renderdoc, "renderdoc");
      48             :         }
      49           0 :         if (!validation) {
      50           0 :                 ret.setBool(validation, "validation");
      51             :         }
      52           0 :         if (verbose) {
      53           0 :                 ret.setBool(verbose, "verbose");
      54             :         }
      55           0 :         if (help) {
      56           0 :                 ret.setBool(help, "help");
      57             :         }
      58           0 :         return ret;
      59           0 : }
      60             : 
      61           0 : int parseViewCommandLineSwitch(ViewCommandLineData &ret, char c, const char *str) {
      62           0 :         if (c == 'h') {
      63           0 :                 ret.help = true;
      64           0 :         } else if (c == 'v') {
      65           0 :                 ret.verbose = true;
      66             :         }
      67           0 :         return 1;
      68             : }
      69             : 
      70           0 : int parseViewCommandLineString(ViewCommandLineData &ret, const StringView &str, int argc, const char * argv[]) {
      71           0 :         if (str == "help") {
      72           0 :                 ret.help = true;
      73           0 :         } else if (str == "verbose") {
      74           0 :                 ret.verbose = true;
      75           0 :         } else if (str.starts_with("w=")) {
      76           0 :                 auto s = str.sub(2).readInteger().get(0);
      77           0 :                 if (s > 0) {
      78           0 :                         ret.screenSize.width = s;
      79             :                 }
      80           0 :         } else if (str.starts_with("h=")) {
      81           0 :                 auto s = str.sub(2).readInteger().get(0);
      82           0 :                 if (s > 0) {
      83           0 :                         ret.screenSize.height = s;
      84             :                 }
      85           0 :         } else if (str.starts_with("d=")) {
      86           0 :                 auto s = str.sub(2).readDouble().get(0.0);
      87           0 :                 if (s > 0) {
      88           0 :                         ret.density = s;
      89             :                 }
      90           0 :         } else if (str.starts_with("l=")) {
      91           0 :                 ret.userLanguage = str.sub(2).str<Interface>();
      92           0 :         } else if (str.starts_with("locale=")) {
      93           0 :                 ret.userLanguage = str.sub("locale="_len).str<Interface>();
      94           0 :         } else if (str == "phone") {
      95           0 :                 ret.isPhone = true;
      96           0 :         } else if (str.starts_with("bundle=")) {
      97           0 :                 ret.bundleName = str.sub("bundle="_len).str<Interface>();
      98           0 :         } else if (str == "fixed") {
      99           0 :                 ret.isFixed = true;
     100           0 :         } else if (str == "renderdoc") {
     101           0 :                 ret.renderdoc = true;
     102           0 :         } else if (str == "novalidation") {
     103           0 :                 ret.validation = false;
     104           0 :         } else if (str.starts_with("decor=")) {
     105           0 :                 auto values = str.sub(6);
     106           0 :                 float f[4] = { nan(), nan(), nan(), nan() };
     107           0 :                 uint32_t i = 0;
     108           0 :                 values.split<StringView::Chars<','>>([&] (StringView val) {
     109           0 :                         if (i < 4) {
     110           0 :                                 f[i] = val.readFloat().get(nan());
     111             :                         }
     112           0 :                         ++ i;
     113           0 :                 });
     114           0 :                 if (!isnan(f[0])) {
     115           0 :                         if (isnan(f[1])) {
     116           0 :                                 f[1] = f[0];
     117             :                         }
     118           0 :                         if (isnan(f[2])) {
     119           0 :                                 f[2] = f[0];
     120             :                         }
     121           0 :                         if (isnan(f[3])) {
     122           0 :                                 f[3] = f[1];
     123             :                         }
     124           0 :                         ret.viewDecoration = Padding(f[0], f[1], f[2], f[3]);
     125             :                 }
     126             :         }
     127           0 :         return 1;
     128             : }
     129             : 
     130             : }

Generated by: LCOV version 1.14