"Fossies" - the Fresh Open Source Software Archive

Member "RPerl-5.002000/lib/rperloperations.h" (28 Nov 2019, 2936 Bytes) of package /linux/misc/RPerl-5.002000.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rperloperations.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.000000_vs_5.002000.

    1 #ifndef __CPP__INCLUDED__rperloperations_h
    2 #define __CPP__INCLUDED__rperloperations_h 0.005_000
    3 
    4 #include <rperltypes_mode.h>
    5 #include <RPerl/HelperFunctions.cpp>  // -> HelperFunctions.h
    6 #include <RPerl/Operation/Expression/Operator/Named/Keys.cpp>  // -> Keys.h
    7 
    8 # ifdef __PERL__TYPES
    9 
   10 // NEED ADD CODE
   11 
   12 # elif defined __CPP__TYPES
   13 
   14 // [[[ EXPRESSIONS ]]]
   15 
   16 // DEV NOTE, CORRELATION #rp020: upon adding new named op file lib/RPerl/Operation/Expression/Operator/Named*/* also add in Named*.pm and rperloperations.*
   17 #define abs std::abs  // DEV NOTE, CORRELATION #rp110: C++ std::abs is the most versatile choice of C++ operator, and is equivalent to Perl abs
   18 #define sin std::sin
   19 #define cos std::cos
   20 #define exp std::exp
   21 #define log std::log
   22 #define sqrt std::sqrt
   23 #define atan2 std::atan2
   24 
   25 // DEV NOTE, CORRELATION #rp070: "logical and" && operator behaves differently in Perl vs C++, accepts strings so must use double-negation trick to convert to boolean, returns operand on right if operator evaluates to true; use ANDl instead of && in C++
   26 #define ANDl(x,y) (!!x) ? ((!!y) ? y : 0): 0
   27 
   28 // DEV NOTE, CORRELATION #rp071: "logical or" || operator behaves differently in Perl vs C++, accepts strings so must use double-negation trick to convert to boolean, returns operand on left if operator evaluates to true; use ORl instead of || in C++
   29 #define ORl(x,y) (!!x) ? x : ((!!y) ? y : 0)
   30 
   31 // array operations
   32 #define scalar(array) array.size()
   33 
   34 // hash operations
   35 #define exists(hash,key) ((bool) hash.count(key))
   36 //#define exists_ref(hashref,key) hashref.NEED_DEREF_BEFORE.count(key)
   37 
   38 // [[[ STATEMENTS ]]]
   39 
   40 #define print cout <<  // DEV NOTE, CORRELATION #rp100: C++ cout w/ double-less-than << input list separators is equivalent to Perl print w/ comma separators
   41 #define prerr cerr <<  // DEV NOTE, CORRELATION #rp101: C++ cerr w/ double-less-than << input list separators is equivalent to Perl print {*STDERR} w/ comma separators
   42 
   43 // BEGIN die OPERATOR
   44 // DEV NOTE: prefer #rp102a solution because the generated C++ looks closer to the original Perl input; commas instead of double-less-thans, no inline exit()
   45 // DEV NOTE, CORRELATION #rp102: renamed from Perl die to C++ Die to avoid error redefining Perl's embed.h die
   46 // DEV NOTE, CORRELATION #rp102a: C++ cerr w/ recursive variadic template and exit() is equivalent to Perl die, DISABLED
   47 void Die(){};
   48 template<typename First, typename ...Rest>
   49 void Die(First && first, Rest && ...rest) {
   50     cerr << std::forward<First>(first);
   51     Die(std::forward<Rest>(rest)...);  // ERROR all-lowercase die(): this recursive call causes an unknown SIGSEGV segfault in libperl.so
   52     exit(1);
   53 }
   54 // DEV NOTE, CORRELATION #rp102b: C++ cerr w/ inlined exit() is equivalent to Perl die
   55 //#define die cerr <<  // ERROR all-lowercase die(): warning: "die" redefined    /usr/lib/perl/5.XX/CORE/embed.h    # define die Perl_die_nocontext
   56 //#define Die cerr <<
   57 // END die OPERATOR
   58 
   59 # endif
   60 
   61 #endif