本文整理汇总了C++中document::Ptr::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::add方法的具体用法?C++ Ptr::add怎么用?C++ Ptr::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类document::Ptr
的用法示例。
在下文中一共展示了Ptr::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCursorRequest
void MongoDBTest::testCursorRequest()
{
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
Document::Ptr doc = new Document();
doc->add("number", i);
insertRequest->documents().push_back(doc);
}
_mongo->sendRequest(*insertRequest);
Poco::Int64 count = db.count(*_mongo, "numbers");
assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers");
int n = 0;
Poco::MongoDB::ResponseMessage& response = cursor.next(*_mongo);
while(1)
{
n += response.documents().size();
if ( response.cursorID() == 0 )
break;
response = cursor.next(*_mongo);
}
assert(n == 10000);
Poco::MongoDB::QueryRequest drop("team.$cmd");
drop.setNumberToReturn(1);
drop.selector().add("drop", std::string("numbers"));
Poco::MongoDB::ResponseMessage responseDrop;
_mongo->sendRequest(drop, responseDrop);
}
示例2: testCursorRequest
void MongoDBTest::testCursorRequest()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
Document::Ptr doc = new Document();
doc->add("number", i);
insertRequest->documents().push_back(doc);
}
_mongo.sendRequest(*insertRequest);
double count = db.count(_mongo, "numbers");
assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers");
int n = 0;
Poco::MongoDB::ResponseMessage& response = cursor.next(_mongo);
while(1)
{
n += response.documents().size();
if ( response.cursorID() == 0 )
break;
response = cursor.next(_mongo);
}
std::cout << "n= " << n << std::endl;
assert(n == 10000);
Poco::MongoDB::QueryRequest drop("team.$cmd");
drop.setNumberToReturn(1);
drop.selector().add("drop", std::string("numbers"));
Poco::MongoDB::ResponseMessage responseDrop;
_mongo.sendRequest(drop, responseDrop);
if ( responseDrop.documents().size() > 0 )
{
std::cout << responseDrop.documents()[0]->toString(2) << std::endl;
}
}
示例3: main
int main(int argc, char *argv[])
{
int sockfd, newsockfd, port_no, bindfd, listenfd, bytes_sent, bytes_recvd;
char sbuffer[512], cli_ip[16], sname[64], cname[64];
char *ptr_buff, *ptr_port;
const char *ptr_cli_ip;
struct sockaddr_in serv_addr, cli_addr;
socklen_t serv_size, cli_size;
int inp_true = 0, count = 0, inp, ni, x, y, toss;
char serv_choice, cli_choice, nc;
char choice_buffer[2], co_ordinates_buffer[2], toss_buffer;
system("clear");
ptr_buff = &sbuffer[0];
ptr_port = (char *)&PORT;
//creating sever side socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
perror("Server side listening Socket could not be created!");
return 1;
}
memset(&serv_addr, 0, sizeof(serv_addr));
port_no = atoi(ptr_port);
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port_no);
serv_addr.sin_addr.s_addr = INADDR_ANY;
//binding socket
bindfd = bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (bindfd == -1)
{
perror("Failed to bind!");
return 1;
}
Repo repo(MONGODB_HOST, MONGODB_PORT);
cout<<"--Player History--"<<endl;
repo.Read();
cout<<endl<<"Enter your Name : ";
cin>>sname;
Player *playerExist = Exist(sname);
if (playerExist->name != "")
{
cout<<endl<<"Welcome back "<<sname;
cout<<endl<<"Your history : ";
cout<<endl<<"win = "<<playerExist->win;
cout<<endl<<"lose = "<<playerExist->lose;
cout<<endl<<"draw = "<<playerExist->draw;
}
else
{
Document::Ptr person = new Document();
person->add("name", string(sname));
person->add("win", 0);
person->add("lose", 0);
person->add("draw", 0);
repo.Create(person);
}
char ans;
cout<<endl<<"Reset Game History ? (y/N)";
cin>>ans;
if (ans == 'y')
{
repo.Delete("all");
cout<<"--Player History--"<<endl;
repo.Read();
}
/*-----*/
cout<<"Server created!"<<endl<<"Waiting for a Player..."<<endl;
//listening for incoming connections
listenfd = listen(sockfd, 5);
if (listenfd == -1)
{
perror("Failed to listen!");
return 1;
}
serv_size = sizeof(serv_addr);
cli_size = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &cli_size);
if (newsockfd == -1)
{
perror("Failed to accept from client!");
return 1;
}
ptr_cli_ip = inet_ntop(AF_INET, &cli_addr.sin_addr, cli_ip, cli_size);
//.........这里部分代码省略.........