kspread
bitops.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "BitOpsModule.h"
00024 #include "FunctionModuleRegistry.h"
00025 #include "Functions.h"
00026 #include "ValueCalc.h"
00027 #include "ValueConverter.h"
00028
00029 #include <KGenericFactory>
00030 #include <KLocale>
00031
00032 using namespace KSpread;
00033
00034
00035 Value func_bitand (valVector args, ValueCalc *calc, FuncExtra *);
00036 Value func_bitor (valVector args, ValueCalc *calc, FuncExtra *);
00037 Value func_bitxor (valVector args, ValueCalc *calc, FuncExtra *);
00038 Value func_bitlshift (valVector args, ValueCalc *calc, FuncExtra *);
00039 Value func_bitrshift (valVector args, ValueCalc *calc, FuncExtra *);
00040
00041 #ifndef KSPREAD_UNIT_TEST // Do not create/export the plugin in unit tests.
00042 K_PLUGIN_FACTORY(BitOpsModulePluginFactory,
00043 registerPlugin<BitOpsModule>();
00044 )
00045 K_EXPORT_PLUGIN(BitOpsModulePluginFactory("BitOpsModule"))
00046 #endif
00047
00048 BitOpsModule::BitOpsModule(QObject* parent, const QVariantList&)
00049 : FunctionModule(parent, "bitops", i18n("Bit Operation Functions"))
00050 {
00051 }
00052
00053 QString BitOpsModule::descriptionFileName() const
00054 {
00055 return QString("bitops.xml");
00056 }
00057
00058 void BitOpsModule::registerFunctions()
00059 {
00060 FunctionRepository* repo = FunctionRepository::self();
00061 Function *f;
00062
00063 f = new Function ("BITAND", func_bitand);
00064 f->setParamCount (2);
00065 repo->add (f);
00066 f = new Function ("BITOR", func_bitor);
00067 f->setParamCount (2);
00068 repo->add (f);
00069 f = new Function ("BITXOR", func_bitxor);
00070 f->setParamCount (2);
00071 repo->add (f);
00072 f = new Function ("BITLSHIFT", func_bitlshift);
00073 f->setParamCount (2);
00074 repo->add (f);
00075 f = new Function ("BITRSHIFT", func_bitrshift);
00076 f->setParamCount (2);
00077 repo->add (f);
00078 }
00079
00080 void BitOpsModule::removeFunctions()
00081 {
00082
00083 FunctionRepository::self()->remove("Bit Operations");
00084 }
00085
00086
00087
00088 Value func_bitand (valVector args, ValueCalc *, FuncExtra *)
00089 {
00090 const quint64 x = args[0].asInteger();
00091 const quint64 y = args[1].asInteger();
00092 return Value( static_cast<qint64>( x & y ) );
00093 }
00094
00095
00096 Value func_bitor (valVector args, ValueCalc *, FuncExtra *)
00097 {
00098 const quint64 x = args[0].asInteger();
00099 const quint64 y = args[1].asInteger();
00100 return Value( static_cast<qint64>( x | y ) );
00101 }
00102
00103
00104 Value func_bitxor (valVector args, ValueCalc *, FuncExtra *)
00105 {
00106 const quint64 x = args[0].asInteger();
00107 const quint64 y = args[1].asInteger();
00108 return Value( static_cast<qint64>( x ^ y ) );
00109 }
00110
00111
00112 Value func_bitlshift (valVector args, ValueCalc *, FuncExtra *)
00113 {
00114 const quint64 x = args[0].asInteger();
00115 const int numshift = args[1].asInteger();
00116 if ( numshift == 0 )
00117 return Value( static_cast<qint64>( x ) );
00118 else if ( numshift > 0 )
00119 return Value( static_cast<qint64>( x << numshift ) );
00120 else
00121 return Value( static_cast<qint64>( x >> ( -1 * numshift ) ) );
00122 }
00123
00124
00125 Value func_bitrshift (valVector args, ValueCalc *, FuncExtra *)
00126 {
00127 const quint64 x = args[0].asInteger();
00128 const int numshift = args[1].asInteger();
00129 if ( numshift == 0 )
00130 return Value( static_cast<qint64>( x ) );
00131 else if ( numshift > 0 )
00132 return Value( static_cast<qint64>( x >> numshift ) );
00133 else
00134 return Value( static_cast<qint64>( x << ( -1 * numshift ) ) );
00135 }
00136
00137 #include "BitOpsModule.moc"
|