IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques C++ Discussion :

l'équivalent des packeges JAVA en C/C++.


Sujet :

Bibliothèques C++

  1. #1
    Membre habitué Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Points : 136
    Points
    136
    Par défaut l'équivalent des packeges JAVA en C/C++.
    Bonjour,

    Actuellement je suis entrain de traduire un code source java en C/C++, je suis fasse à:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
     
    import javax.microedition.midlet.*;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.*;
     
    import org.json.me.JSONException;
    import org.json.me.JSONObject;
    Normalement l'équivalent de ces packegs sous C/C++ c'est les librairys, svp c'est quoi le nom des librairys que je peux utilisé pour remplacer ces packages dans mon code C/C++, sachant que je vais traduire le code java en C/C++ alors je serais surement appeler à faire des appelles à des fonctions.

    Merci d'avance.

  2. #2
    Inactif  


    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    5 288
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Novembre 2008
    Messages : 5 288
    Points : 15 620
    Points
    15 620
    Par défaut
    Bonjour et bienvenue sur le forum C++ alors, si tu es un dev Java

    Première précision, C et C++ sont deux langages différents (même si effectivement, on peut utiliser des libs C en C++, si tu es habitué à la POO, tu vas avoir plus de mal avec les libs C)

    Une grosse différence entre le Java et le C++, c'est que celui ci inclut dans le langage que le minimum, le reste étant développé + ou - indépendamment dans des libs externes (boost, Qt par exemple, mais bien d'autres)

    Pour répondre à ta question, je ne suis pas sur de ce que font les fonctions java citées. En me basant sur le nom :

    import java.io.ByteArrayOutputStream; -> std::iostream (STL), QDataStream (Qt)
    import java.io.IOException; -> std::exception (STL)
    import java.io.InputStream; -> std::iostream (STL), QDataStream (Qt)

    import javax.microedition.midlet.*;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection; -> QHttpConnection (Qt)
    import javax.microedition.lcdui.*;

    import org.json.me.JSONException; -> QJson
    import org.json.me.JSONObject;

    Précise peut être ce que tu souhaites comme fonctionnalités, il y a peut être des équivalents différents en C++

  3. #3
    Membre émérite
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    2 764
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 2 764
    Points : 2 704
    Points
    2 704
    Par défaut
    Citation Envoyé par gbdivers Voir le message
    import java.io.ByteArrayOutputStream; -> std::iostream (STL)
    import java.io.InputStream; -> std::iostream (STL
    Respectivement std::ostram et std::istream, non ?

    Pour JSon, il existe plusieurs bibliothèques externes.

    Pour Java MicroEdition, c'est très spécifique à un domaine que je ne connais pas.

  4. #4
    Membre habitué Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Points : 136
    Points
    136
    Par défaut
    Bonjour,

    Merci pour vos réponses, pardon c'est moi qui s'est mal exprimer. Durent mon stage je dois modifier une grand système embarqué et très répartie, ma modification ce porte sur la partie GPS. En effet nous utilisent des librarys C/C++ et ça m'aide beaucoup. en ce moment je suis entrain de traduire le code suivant https://labs.ericsson.com/apis/mobil.../documentation et je ne suis pas vraiment un expert en JAVA (pour ne pas dire que je n'aime pas beaucoup JAVA lol), dans le système il y a toutes les librarys que vous avez cité, pour les classes je pense que je peux m'en sortir mais pour les package je ne sais pas beaucoup:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
     
    import javax.microedition.midlet.*;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.*;
     
    import org.json.me.JSONException;
    import org.json.me.JSONObject;
     
    /**
     * A minimal example MIDlet implemented
     * with Cell-ID look-up API.
     */
    public class CellIdLookUpMidlet extends MIDlet
     implements CommandListener, Runnable {
     
     // **** Set the developer key here ****
     private final static String API_KEY = "";
     
     private Command exitCommand; 
     private Cell cell;
     private Form form;
     
     private StringItem itemLongitude, itemLatitude;
     private StringItem itemAccuracy, itemName;
     private double longitude, latitude, accuracy;
     private String cellName;
     
     public CellIdLookUpMidlet() {
     
      cell = new Cell();
     
      exitCommand = new Command("Exit", Command.EXIT, 1);
     
      form = new Form(null);
     
      itemLongitude = new StringItem("longitude: ",
    		  Double.toString(longitude));
      itemLatitude = new StringItem("latitude: ",
    		  Double.toString(latitude));
      itemAccuracy = new StringItem("accuracy: ",
    		  Double.toString(accuracy));
      itemName = new StringItem("name: ",cellName);
     
      form.insert(0, itemLongitude);
      form.insert(1, itemLatitude);
      form.insert(2, itemAccuracy);
      form.insert(3, itemName);
     
      form.addCommand(exitCommand);
      form.setCommandListener(this);
     
      Thread t = new Thread(this);
      t.start();
     }
     
     public void run() {
      updatePosition();
     }
     
     private void updateForm() {
      itemLongitude.setText(Double.toString(longitude));
      itemLatitude.setText(Double.toString(latitude));
      itemAccuracy.setText(Double.toString(accuracy));
      itemName.setText(cellName);
     }
     
     protected void startApp() {
      Display.getDisplay(this).setCurrent(form);
     }
     
     protected void pauseApp() {}
     protected void destroyApp(boolean bool) {}
     
     public void commandAction(Command cmd, Displayable d) {
      if(cmd==exitCommand) {
       destroyApp(false);
       notifyDestroyed();
      }
     }
     
     /**
      * updatePosition
      * The format of the position data is either xml or json.
      * In this example we are using json
      */
     public void updatePosition() {
      StringBuffer url = new StringBuffer();
      url.append("<a href="http://cellid.labs.ericsson.net/json/lookup"">http://cellid.labs.ericsson.net/json/lookup"</a>);
      url.append("?cellid=").append(cell.getCellId());
      url.append("&mnc=").append(cell.getMnc());
      url.append("&mcc=").append(cell.getMcc());
      url.append("&lac=").append(cell.getLac());
      url.append("&key=").append(API_KEY);
     
      try {
       byte[] data = getHttp(url.toString());
       if(data!=null) {
    	parseJSON(new String(data));
    	updateForm();
       }
      } catch (IOException e) {
       e.printStackTrace();
      }
     }
     
     /**
      * parseJSON
      * 
      * For JSON support we are using org.json.me
      * The JSON package can be downloaded from here:
      *  <a href="http://www.json.org/java/org.json.me.zip
    ">www.json.org/java/org.json.me.zip
    </a>  */
     public void parseJSON(String jsonString) {
      try {
       JSONObject o = new JSONObject(jsonString);
       JSONObject pos = o.getJSONObject("position");
       this.longitude = pos.getDouble("longitude");
       this.latitude = pos.getDouble("latitude");
       this.accuracy = pos.getDouble("accuracy");
       this.cellName = pos.optString("name");
      } catch(JSONException e) {
       e.printStackTrace();
      }
     }
     
     static public byte[] getHttp(String url)
      throws IOException {
     
      HttpConnection c = null;
      InputStream is = null;
      byte[] data = null;
     
      try {
       c = (HttpConnection)Connector.open(url);
       int rc = c.getResponseCode();            
     
       // handle the HTTP response codes used by the API
       if(rc!=HttpConnection.HTTP_OK) {
    	switch(rc) {
    	case HttpConnection.HTTP_NO_CONTENT:
    	 throw new IOException("The cell could not be "+
    		"found in the database");
    	case HttpConnection.HTTP_BAD_REQUEST:
    	 throw new IOException("Check if some parameter "+
    		"is missing or misspelled");
    	case HttpConnection.HTTP_UNAUTHORIZED:
    	 throw new IOException("Make sure the API key is "+
    		"present and valid");
    	case HttpConnection.HTTP_FORBIDDEN:
    	 throw new IOException("You have reached the limit "+
    		"for the number of requests per day. The maximum "+
    		"number of requests per day is currently 500.");
    	case HttpConnection.HTTP_NOT_FOUND:
    	 throw new IOException("The cell could not be found "+
    			 "in the database");
    	default:
    	 throw new IOException("HTTP response code: " + rc);
    	}
       }
     
       is = c.openInputStream();
     
       int actual = 0;
       int len = (int)c.getLength();
       if(len>0) {
    	int bytesread = 0 ;
    	// the server returned a length so we can allocate
    	// a byte array directly
    	data = new byte[len];
    	// loop until there is nothing more to read or
    	// until buffer is full
    	while((bytesread != len) && (actual != -1)) {
    	 actual = is.read(data, bytesread, len - bytesread);
    	 bytesread += actual;
    	}
       } else {
    	// the server is not returning a length
    	// so we need a ByteArrayOutputStream
    	ByteArrayOutputStream bos = new ByteArrayOutputStream();
    	// create a 256 bytes read buffer to
    	// improve reading performance
    	byte buf[] = new byte[256];
    	// loop for as long as we get data from the server
    	// and add it to the output stream
    	while((actual = is.read(buf, 0, 256))!=-1) {
    	 bos.write(buf, 0, actual);
    	}
    	bos.flush();
    	data = bos.toByteArray();
       }
      } catch (ClassCastException e) {
       throw new IllegalArgumentException("Not an HTTP URL");
      } finally {
       try { if (c != null) c.close(); } catch(IOException e) {};
       try { if (is != null) is.close(); } catch(IOException e) {};
      }
      return data;
     }
     
     /**
      * Cell class to handle cell id parameters.
      * Note that this is Sony Ericsson specific code.
      */
     public class Cell {
     
      private String id;
      private String lac;
      private String mcc;
      private String mnc;
     
      public Cell() {
       update();
      }
     
      public void update() {
       try {
    	id = System.getProperty("com.sonyericsson.net.cellid");
    	lac = System.getProperty("com.sonyericsson.net.lac");
    	mcc = System.getProperty("com.sonyericsson.net.cmcc");
    	mnc = System.getProperty("com.sonyericsson.net.cmnc");
       } catch(Exception e) {
    	e.printStackTrace();
       }
      }
     
      public String getCellId() { return id; }
      public String getLac() { return lac; }
      public String getMcc() { return mcc; }
      public String getMnc() { return mnc; }
     }
    }
    Merci d'avance.

  5. #5
    Inactif  


    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    5 288
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Novembre 2008
    Messages : 5 288
    Points : 15 620
    Points
    15 620
    Par défaut
    C'est un besoin a priori très spécifique, donc pas sur que tu aies beaucoup d'aide.
    La seule chose à laquelle ça me fait penser, c'est à QMobility, un module Qt pour gérer tout ce qui est spécifique aux portables : http://qt.developpez.com/tutoriels/#qtmobility

  6. #6
    Membre habitué Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Points : 136
    Points
    136
    Par défaut
    Bonjour et merci pour vos réponses: je pense que j'ai trouvé la solution, c'est la librairy Gnokii.h le fichier Gniokii.c : http://gnokii.sourcearchive.com/docu...8c-source.html

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Équivalent des fonctions C fread() et fwrite() en Java ?
    Par kar31 dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 17/10/2011, 17h13
  2. [PHP 5.3] Équivalent des collections Java
    Par kaljerhom dans le forum Langage
    Réponses: 8
    Dernier message: 14/05/2009, 14h14
  3. [SWT]équivalent des JOptionPane Swing
    Par Le Marlou dans le forum SWT/JFace
    Réponses: 1
    Dernier message: 18/02/2004, 10h56
  4. [info]Licence des produits Java
    Par XavierZERO dans le forum Général Java
    Réponses: 12
    Dernier message: 16/01/2004, 16h27
  5. Inserer des classes java existantes
    Par 2000 dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 20/03/2003, 12h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo