example_tc_config.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "util/tc_config.h"
  17. #include "util/tc_file.h"
  18. #include <iterator>
  19. #include <sys/time.h>
  20. using namespace tars;
  21. int main(int argc, char *argv[])
  22. {
  23. try
  24. {
  25. TC_Config conf;
  26. conf.parseFile("./template.config.conf");
  27. cout << "parseFile************************************" << endl;
  28. cout << conf.tostr() << endl;
  29. vector<string> n = conf.getDomainVector("/");
  30. cout << TC_Common::tostr(n) << endl;
  31. return 0;
  32. cout << "parseFile************************************" << endl;
  33. TC_Config conft = conf;
  34. cout << conft.tostr() << endl;
  35. cout << conf["/tars/application/client<locator>"] << endl;
  36. map<string, string> m1 = conf.getDomainMap("/tars/allow");
  37. cout << TC_Common::tostr(m1) << endl;
  38. cout << conf["/tars/allow<A>"] << endl;
  39. cout << "parseString************************************" << endl;
  40. TC_File tf;
  41. conf.parseString(tf.load2str("./template.config.conf"));
  42. cout << conf.tostr() << endl;
  43. cout << conf["/tars/application/client<locator>"] << endl;
  44. cout << "insertDomain create false************************************" << endl;
  45. conf.insertDomain("/tars/insert", "insert", false);
  46. cout << conf.tostr() << endl;
  47. conf.parseString(conf.tostr());
  48. cout << conf.tostr() << endl;
  49. cout << "insertDomain create true************************************" << endl;
  50. conf.insertDomain("/tars/insert", "insert", true);
  51. cout << conf.tostr() << endl;
  52. conf.parseString(conf.tostr());
  53. cout << conf.tostr() << endl;
  54. cout << "insertDomainParam************************************" << endl;
  55. map<string, string> m;
  56. m["abc"] = "def";
  57. m["ttt"] = "yyy";
  58. conf.insertDomainParam("/tars/insert/insert1", m, false);
  59. cout << conf.tostr() << endl;
  60. conf.insertDomainParam("/tars/insert/insert1", m, true);
  61. cout << conf.tostr() << endl;
  62. cout << "joinConfig true************************************" << endl;
  63. TC_Config conf1;
  64. conf1.parseFile("./log.config.conf");
  65. conf1.joinConfig(conf, true);
  66. cout << conf1.tostr() << endl;
  67. cout << "joinConfig false************************************" << endl;
  68. TC_Config conf2;
  69. conf2.parseFile("./log.config.conf");
  70. conf2.joinConfig(conf, false);
  71. cout << conf2.tostr() << endl;
  72. TC_Config conf3 = conf2;
  73. cout << conf3.tostr() << endl;
  74. }
  75. catch(exception &ex)
  76. {
  77. cout << ex.what() << endl;
  78. }
  79. return 0;
  80. }