Caffe源码中各种依赖库的作用及简单使用(2)

class implementation {
public:
 ~implementation() { std::cout << "destroying implementation\n"; }
 void do_something() { std::cout << "did something\n"; }
};

int test_Boost()
{
 //http://www.cnblogs.com/tianfang/archive/2008/09/19/1294521.html
 boost::shared_ptr<implementation> sp1(new implementation());
 std::cout << "The Sample now has " << sp1.use_count() << " references\n";

boost::shared_ptr<implementation> sp2 = sp1;
 std::cout << "The Sample now has " << sp2.use_count() << " references\n";

sp1.reset();
 std::cout << "After Reset sp1. The Sample now has " << sp2.use_count() << " references\n";

sp2.reset();
 std::cout << "After Reset sp2.\n";

return 0;
}

DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german", "comma-separated list of languages to offer in the 'lang' menu");

int test_GFlags(int argc, char* argv[])
{
 //http://dreamrunner.org/blog/2014/03/09/gflags-jian-ming-shi-yong/
 //http://www.leoox.com/?p=270
 int tmp_argc = 3;
 char** tmp_argv = NULL;
 tmp_argv = new char*[3];
 tmp_argv[0] = "";
 tmp_argv[1] = "--big_menu=false";
 tmp_argv[2] = "--languages=chinese";

//google::ParseCommandLineFlags(&argc, &argv, true);
 google::ParseCommandLineFlags(&tmp_argc, &tmp_argv, true);

std::cout << "argc=" << argc << std::endl;
 if (FLAGS_big_menu) {
  std::cout << "big menu is ture" << std::endl;
 }
 else {
  std::cout << "big menu is flase" << std::endl;
 }

std::cout << "languages=" << FLAGS_languages << std::endl;

return 0;
}

void thread1_test()
{
 std::string strTmp = "thread1_test";
 for (int i = 0; i< 1000; i++) {
  //LOG(INFO) << i;
  LOG_IF(INFO, i < 10) << i;
  //CHECK_EQ(i, 100) << "error!";
  //LOG(INFO) << strTmp;
  //Sleep(10);
 }
}

void thread2_test()
{
 std::string strTmp = "thread2_test";
 for (int i = 1000; i< 2000; i++) {
  //LOG(INFO) << i;
  LOG_IF(INFO, i < 1100) << i;
  //LOG(INFO) << strTmp;
  //Sleep(10);
 }
}

int test_GLog()
{
 //http://www.yeolar.com/note/2014/12/20/glog/
 //http://www.cppblog.com/pizzx/archive/2014/06/18/207320.aspx
 const char* exe = "E:/GitCode/Caffe/lib/dbg/x86_vc12/testThridLibrary[dbg_x86_vc12].exe";
 //Initialize Google's logging library.
 //google::InitGoogleLogging(argv[0]);
 google::InitGoogleLogging(exe);

//为不同级别的日志设置不同的文件basename。
 google::SetLogDestination(google::INFO, "E:/tmp/loginfo");
 google::SetLogDestination(google::WARNING, "E:/tmp/logwarn");
 google::SetLogDestination(google::GLOG_ERROR, "E:/tmp/logerror");
 
 //缓存的最大时长,超时会写入文件
 FLAGS_logbufsecs = 60;

//单个日志文件最大,单位M
 FLAGS_max_log_size = 10;

//设置为true,就不会写日志文件了
 FLAGS_logtostderr = false;
 boost::thread t1(boost::bind(&thread1_test));
 boost::thread t2(boost::bind(&thread2_test));

t1.join();
 t2.join();

//LOG(FATAL)<<"exit";
 google::ShutdownGoogleLogging();

return 0;
}

int test_LevelDB()
{
 //http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html
 //http://www.bubuko.com/infodetail-411090.html
 //http://qiuqiang1985.iteye.com/blog/1255365
 leveldb::DB* db;
 leveldb::Options options;
 options.create_if_missing = true;
 leveldb::Status status = leveldb::DB::Open(options, "E:/tmp/testLevelDB", &db);
 assert(status.ok());

//write key1,value1
 std::string key = "key";
 std::string value = "value";

//write
 status = db->Put(leveldb::WriteOptions(), key, value);
 assert(status.ok());

//read
 status = db->Get(leveldb::ReadOptions(), key, &value);
 assert(status.ok());
 std::cout << value << std::endl;
 std::string key2 = "key2";

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b4757544dc3cf42f4c437584fa8527cf.html