Hello everybody;
Sorry for my normal english.
I got back the program cpp of the api to connect me and print the various information of a mikrotik card.
I have an error during the compilation which I do not manage to solve
The error is the following one:
redefinition of ’ class sentence ’
previous definition of ’ class sentence ’
redefinition of ’ class block ’
previous definition of ’ class block ’
Code I gor back :
MikrotikAPITypes.h
\
//
// MikrotikAPITypes.h
// WinboxMobile
//
// Created by Joey Gentry on 2/11/10.
// Copyright 2010 MyCompanyName. All rights reserved.
//
#include
#include
#include
#include <stdio.h>
#include <stdlib.h>
#include
#define DEBUG 1
#define NONE 0
#define DONE 1
#define TRAP 2
#define FATAL 3
class Sentence {
std::vectorstd::string strWords; // vecor of strings representing individual words
int returnType; // return type of sentence
void Tokenize(const std::string &str, std::vectorstd::string &tokens,
const std::string &delimiters = " ");
public:
void SetReturnType(int returnTypeIn) { returnType = returnTypeIn; }
int GetReturnType() { return returnType; }
void AddWord(const std::string &strWordToAdd) { strWords.push_back(strWordToAdd); }
void Clear() { strWords.clear(); returnType = 0; }
int Length() { return strWords.size(); }
std::string operator(int index) { return strWords[index]; }
std::string GetWord(int index) { return strWords[index]; }
void GetMap(int index, std::map<std::string, std::string> &sentenceMap);
bool Print();
};
class Block {
std::vector sentences;
public:
int Length() { return sentences.size(); }
void AddSentence(const Sentence &sentence);
void Clear() { sentences.clear(); }
Sentence operator(int index) { return sentences[index]; }
bool Print();
};
\
MikrotikAPITypes.cpp
//
// untitled.mm
// WinboxMobile
//
// Created by Joey Gentry on 2/13/10.
// Copyright 2010 MyCompanyName. All rights reserved.
//
#include “MikrotikAPITypes.h”
using namespace std;
/********************************************************************
- Print a sentence.
********************************************************************/
bool Sentence::Print()
{
DEBUG ? printf(“Sentence Word Count = %d\n”, strWords.size()) : 0;
DEBUG ? printf(“Sentence returnType = %d\n”, returnType) : 0;
for (int i = 0; i < strWords.size(); ++i) {
printf(“%s\n”, strWords_.c_str());
}
printf(“\n”);
return true;
}
void Sentence::GetMap(map<string, string> &sentenceMap)
{
for (int i = 0; i < strWords.size(); ++i) {
string tmpDataString = strWords;
vector dataStrings;
Tokenize(tmpDataString, dataStrings, “=”);
if (returnType == NONE && dataStrings.size() > 1) {
sentenceMap.insert(make_pair(dataStrings[1], dataStrings[2]));
}
}
}
void Sentence::Tokenize(const string &str, vector &tokens, const string &delimiters)
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first “non-delimiter”.
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the “not_of”
lastPos = str.find_first_not_of(delimiters, pos);
// Find next “non-delimiter”
pos = str.find_first_of(delimiters, lastPos);
}
}
/********************************************************************
- Add a Sentence to a block
/
void Block::AddSentence(const Sentence &sentence)
{
sentences.push_back(sentence);
DEBUG ? printf(“AddSentenceToBlock Size=%d\n”, sentences.size()) : 0;
}
/ - Print a block.
********************************************************************/
bool Block::Print()
{
DEBUG ? printf(“PrintBlock\n”) : 0;
DEBUG ? printf(“Block Size = %d\n”, sentences.size()) : 0;
for (int i = 0; i < sentences.size(); ++i) {
sentences.Print();
}
return true;
}_