Changeset 7813 for trunk


Ignore:
Timestamp:
11/24/11 14:53:36 (8 years ago)
Author:
mario
Message:

added a bit stricter types, and use const reference for strings (instead of copies)

Location:
trunk/legacy/jvmlink/src/main/c++
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkClient.cpp

    r7812 r7813  
    6464// -- Public API methods -- 
    6565 
    66 void JVMLinkClient::startJava(int arg_port, std::string classpath) { 
     66void JVMLinkClient::startJava(int arg_port, const std::string& classpath) { 
    6767        port = arg_port == 0 ? DEFAULT_PORT : arg_port; 
    6868        std::stringstream tmpportstr; 
     
    191191} 
    192192 
    193 JVMLinkObject* JVMLinkClient::getVar(std::string name) { 
     193JVMLinkObject* JVMLinkClient::getVar(const std::string& name) { 
    194194        debug("getVar: requesting " << name); 
    195195        JVMLinkObject* obj = new JVMLinkObject(name); 
     
    231231} 
    232232 
    233 void JVMLinkClient::exec(std::string command) { 
     233void JVMLinkClient::exec(const std::string& command) { 
    234234        debug("exec: " << command); 
    235235        sendInt(EXEC_CMD); 
     
    265265} 
    266266 
    267 void JVMLinkClient::setVar(std::string argname, int obj) { 
     267void JVMLinkClient::setVar(const std::string& argname, int obj) { 
    268268        debug("setVar: " << argname << " = " << obj << " (int)"); 
    269269        JVMLinkObject* jvmObj = new JVMLinkObject(argname, INT_TYPE, &obj); 
     
    272272} 
    273273 
    274 void JVMLinkClient::setVar(std::string argname, int* obj, int length) { 
     274void JVMLinkClient::setVar(const std::string& argname, int* obj, int length) { 
    275275        debug("setVar: " << argname << " (int array)"); 
    276276        JVMLinkObject* jvmObj = new JVMLinkObject(argname, INT_TYPE, length, obj); 
     
    279279} 
    280280 
    281 void JVMLinkClient::setVar(std::string argname, std::string* obj) { 
     281void JVMLinkClient::setVar(const std::string& argname, std::string* obj) { 
    282282        debug("setVar: " << argname << " = " << obj << " (string)"); 
    283283        JVMLinkObject* jvmObj = new JVMLinkObject(argname, STRING_TYPE, obj); 
     
    286286} 
    287287 
    288 void JVMLinkClient::setVar(std::string argname, std::string* obj, int length) { 
     288void JVMLinkClient::setVar(const std::string& argname, std::string* obj, int length) { 
    289289        debug("setVar: " << argname << " (string array)"); 
    290290        JVMLinkObject* jvmObj = new JVMLinkObject(argname, STRING_TYPE, length, obj); 
     
    293293} 
    294294 
    295 void JVMLinkClient::setVar(std::string argname, char obj) { 
     295void JVMLinkClient::setVar(const std::string& argname, char obj) { 
    296296        debug("setVar: " << argname << " = " << obj << " (char)"); 
    297297        JVMLinkObject* jvmObj = new JVMLinkObject(argname, CHAR_TYPE, &obj); 
     
    300300} 
    301301 
    302 void JVMLinkClient::setVar(std::string argname, char* obj, int length) { 
     302void JVMLinkClient::setVar(const std::string& argname, char* obj, int length) { 
    303303        debug("setVar: " << argname << " (char array)"); 
    304304        JVMLinkObject* jvmObj = new JVMLinkObject(argname, CHAR_TYPE, length, obj); 
     
    307307} 
    308308 
    309 void JVMLinkClient::setVar(std::string argname, Byte obj) { 
     309void JVMLinkClient::setVar(const std::string& argname, Byte obj) { 
    310310        debug("setVar: " << argname << " = " << obj.data << " (byte)"); 
    311311        JVMLinkObject* jvmObj = new JVMLinkObject(argname, BYTE_TYPE, &obj); 
     
    314314} 
    315315 
    316 void JVMLinkClient::setVar(std::string argname, Byte* obj, int length) { 
     316void JVMLinkClient::setVar(const std::string& argname, Byte* obj, int length) { 
    317317        debug("setVar: " << argname << " (byte array)"); 
    318318        JVMLinkObject* jvmObj = new JVMLinkObject(argname, BYTE_TYPE, length, obj); 
     
    321321} 
    322322 
    323 void JVMLinkClient::setVar(std::string argname, float obj) { 
     323void JVMLinkClient::setVar(const std::string& argname, float obj) { 
    324324        debug("setVar: " << argname << " = " << obj << " (float)"); 
    325325        JVMLinkObject* jvmObj = new JVMLinkObject(argname, FLOAT_TYPE, &obj); 
     
    328328} 
    329329 
    330 void JVMLinkClient::setVar(std::string argname, float* obj, int length) { 
     330void JVMLinkClient::setVar(const std::string& argname, float* obj, int length) { 
    331331        debug("setVar: " << argname << " (float array)"); 
    332332        JVMLinkObject* jvmObj = new JVMLinkObject(argname, FLOAT_TYPE, length, obj); 
     
    335335} 
    336336 
    337 void JVMLinkClient::setVar(std::string argname, bool obj) { 
     337void JVMLinkClient::setVar(const std::string& argname, bool obj) { 
    338338        debug("setVar: " << argname << " = " << obj << " (bool)"); 
    339339        JVMLinkObject* jvmObj = new JVMLinkObject(argname, BOOL_TYPE, &obj); 
     
    342342} 
    343343 
    344 void JVMLinkClient::setVar(std::string argname, bool* obj, int length) { 
     344void JVMLinkClient::setVar(const std::string& argname, bool* obj, int length) { 
    345345        debug("setVar: " << argname << " (bool array)"); 
    346346        JVMLinkObject* jvmObj = new JVMLinkObject(argname, BOOL_TYPE, length, obj); 
     
    349349} 
    350350 
    351 void JVMLinkClient::setVar(std::string argname, double obj) { 
     351void JVMLinkClient::setVar(const std::string& argname, double obj) { 
    352352        debug("setVar: " << argname << " = " << obj << " (double)"); 
    353353        JVMLinkObject* jvmObj = new JVMLinkObject(argname, DOUBLE_TYPE, &obj); 
     
    356356} 
    357357 
    358 void JVMLinkClient::setVar(std::string argname, double* obj, int length) { 
     358void JVMLinkClient::setVar(const std::string& argname, double* obj, int length) { 
    359359        debug("setVar: " << argname << " (double array)"); 
    360360        JVMLinkObject* jvmObj = new JVMLinkObject(argname, DOUBLE_TYPE, length, obj); 
     
    363363} 
    364364 
    365 void JVMLinkClient::setVar(std::string argname, long long obj) { 
     365void JVMLinkClient::setVar(const std::string& argname, long long obj) { 
    366366        debug("setVar: " << argname << " = " << obj << " (long)"); 
    367367        JVMLinkObject* jvmObj = new JVMLinkObject(argname, LONG_TYPE, &obj); 
     
    370370} 
    371371 
    372 void JVMLinkClient::setVar(std::string argname, long long* obj, int length) { 
     372void JVMLinkClient::setVar(const std::string& argname, long long* obj, int length) { 
    373373        debug("setVar: " << argname << " (long array)"); 
    374374        JVMLinkObject* jvmObj = new JVMLinkObject(argname, LONG_TYPE, length, obj); 
     
    377377} 
    378378 
    379 void JVMLinkClient::setVar(std::string argname, short obj) { 
     379void JVMLinkClient::setVar(const std::string& argname, short obj) { 
    380380        debug("setVar: " << argname << " = " << obj << " (short)"); 
    381381        JVMLinkObject* jvmObj = new JVMLinkObject(argname, SHORT_TYPE, &obj); 
     
    384384} 
    385385 
    386 void JVMLinkClient::setVar(std::string argname, short* obj, int length) { 
     386void JVMLinkClient::setVar(const std::string& argname, short* obj, int length) { 
    387387        debug("setVar: " << argname << " (short array)"); 
    388388        JVMLinkObject* jvmObj = new JVMLinkObject(argname, SHORT_TYPE, length, obj); 
     
    391391} 
    392392 
    393 void JVMLinkClient::setVarNull(std::string argname) { 
     393void JVMLinkClient::setVarNull(const std::string& argname) { 
    394394        debug("setVarNull: " << argname); 
    395395        JVMLinkObject* jvmObj = new JVMLinkObject(argname, NULL_TYPE, NULL); 
     
    400400// -- Private methods -- 
    401401 
    402 void JVMLinkClient::sendMessage(std::string message) { 
     402void JVMLinkClient::sendMessage(const std::string& message) { 
    403403        int sent = 0; 
    404404        const char* buf = message.c_str(); 
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkClient.h

    r7812 r7813  
    3131*/ 
    3232 
    33 #pragma once 
     33#ifndef JVMLINKCLIENT_HH 
     34#define JVMLINKCLIENT_HH 
     35 
    3436#include "JVMLinkObject.h" 
    3537 
     
    5052#endif 
    5153 
    52         void sendMessage(std::string); 
     54        void sendMessage(const std::string&); 
    5355        void* readMessage(int); 
    5456        void sendInt(int); 
     
    6668 
    6769        JVMLinkClient(); 
    68         void startJava(int, std::string); 
     70        void startJava(int, const std::string&); 
    6971        void shutJava(); 
    7072        ConnectionCode establishConnection(); 
    7173        int closeConnection(); 
    72         JVMLinkObject* getVar(std::string); 
     74        JVMLinkObject* getVar(const std::string&); 
    7375        void setVar(JVMLinkObject*); 
    74         void setVar(std::string, int); 
    75         void setVar(std::string, int*, int); 
    76         void setVar(std::string, std::string*); 
    77         void setVar(std::string, std::string*, int); 
    78         void setVar(std::string, char); 
    79         void setVar(std::string, char*, int); 
    80         void setVar(std::string, Byte); 
    81         void setVar(std::string, Byte*, int); 
    82         void setVar(std::string, float); 
    83         void setVar(std::string, float*, int); 
    84         void setVar(std::string, bool); 
    85         void setVar(std::string, bool*, int); 
    86         void setVar(std::string, double); 
    87         void setVar(std::string, double*, int); 
    88         void setVar(std::string, long long); 
    89         void setVar(std::string, long long*, int); 
    90         void setVar(std::string, short); 
    91         void setVar(std::string, short*, int); 
    92         void setVarNull(std::string); 
    93         void exec(std::string); 
     76        void setVar(const std::string&, int); 
     77        void setVar(const std::string&, int*, int); 
     78        void setVar(const std::string&, std::string*); 
     79        void setVar(const std::string&, std::string*, int); 
     80        void setVar(const std::string&, char); 
     81        void setVar(const std::string&, char*, int); 
     82        void setVar(const std::string&, Byte); 
     83        void setVar(const std::string&, Byte*, int); 
     84        void setVar(const std::string&, float); 
     85        void setVar(const std::string&, float*, int); 
     86        void setVar(const std::string&, bool); 
     87        void setVar(const std::string&, bool*, int); 
     88        void setVar(const std::string&, double); 
     89        void setVar(const std::string&, double*, int); 
     90        void setVar(const std::string&, long long); 
     91        void setVar(const std::string&, long long*, int); 
     92        void setVar(const std::string&, short); 
     93        void setVar(const std::string&, short*, int); 
     94        void setVarNull(const std::string&); 
     95        void exec(const std::string&); 
    9496 
    9597        ~JVMLinkClient(void); 
    9698}; 
     99 
     100#endif // JVMLINKCLIENT_HH 
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkObject.cpp

    r7812 r7813  
    3434#include "JVMLinkObject.h" 
    3535 
    36 JVMLinkObject::JVMLinkObject(std::string name) { 
     36JVMLinkObject::JVMLinkObject(const std::string& name) { 
    3737        this->name = name; 
    3838} 
    3939 
    4040// Constructor for single primitives 
    41 JVMLinkObject::JVMLinkObject(std::string name, Type type, void* data) { 
     41JVMLinkObject::JVMLinkObject(const std::string& name, Type type, void* data) { 
    4242        this->name = name; 
    4343        this->size = getSize(type); 
     
    4848 
    4949// Constructor for arrays 
    50 JVMLinkObject::JVMLinkObject(std::string name, Type type, int length, void* data) { 
     50JVMLinkObject::JVMLinkObject(const std::string& name, Type type, int length, void* data) { 
    5151        this->name = name; 
    5252        this->size = getSize(type); 
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkObject.h

    r7812 r7813  
    3131*/ 
    3232 
    33 #pragma once 
     33 
     34#ifndef JVMLINKOBJECT_HH 
     35#define JVMLINKOBJECT_HH 
    3436 
    3537#include <string> 
     
    6870 
    6971public: 
    70         JVMLinkObject(std::string); 
    71         JVMLinkObject(std::string, Type, void*); 
    72         JVMLinkObject(std::string, Type, int, void*); 
     72        JVMLinkObject(const std::string&); 
     73        JVMLinkObject(const std::string&, Type, void*); 
     74        JVMLinkObject(const std::string&, Type, int, void*); 
    7375 
    7476        ~JVMLinkObject(void); 
     
    99101        bool isDataNull(); 
    100102}; 
     103 
     104#endif // JVMLINKOBJECT_HH 
Note: See TracChangeset for help on using the changeset viewer.