void initialize(Application& self) //
void uninitialize() //
void reinitialize(Application& self) //
void defineOptions() //
void handleOption() //
int main(const std::vector<std::string>& args) //
class myApp : public Application { public: myApp(int argc, char** argv) : Application(argc,argv) {} void initialize(Application& self) { cout << "" << endl; loadConfiguration(); // Application::initialize(self); } void reinitialize() { cout << "" << endl; Application::uninitialize(); } void uninitialize(Application& self) { cout << "" << endl; Application::reinitialize(self); } void HelpHim(const std::string& name, const std::string& value) { cout << " - " << endl; } void Configure(const std::string& name, const std::string& value) { cout << " " << endl; } void defineOptions(OptionSet& options) { cout << " " << endl; Application::defineOptions(options); options.addOption( Option("help", "h", " . ") .required(false) // .repeatable(false) // //myApp::handleOption - - .callback(OptionCallback<myApp>(this, &myApp::handleOption))); options.addOption( Option("config-file", "f", " ") .required(false) .repeatable(true) .argument("file") .callback(OptionCallback<myApp>(this, &myApp::Configure))); options.addOption( Option("bind", "b", " =") .required(false) // - .argument("value") // , , [0; 100] .validator(new IntValidator(0, 100)) .binding("test.property")); // } int main(const std::vector<std::string>& args) { cout << " -" << endl; } }; // POCO_APP_MAIN - : // int wmain(int argc, wchar_t** argv) // { // myApp A(argc,argv); // return A.run(); // } POCO_APP_MAIN(myApp)
class myServerTask: public Task { public: myServerTask(): Task("MyTask") // "MyTask" { } // void runTask() { Application& app = Application::instance(); while (!isCancelled()) { // sleep(1000); // Application::instance().logger().information (" " + DateTimeFormatter::format(app.uptime())); } } };
class myServer: public ServerApplication { protected: void initialize(Application& self) { // loadConfiguration(); // ServerApplication ServerApplication::initialize(self); // logger().setChannel(AutoPtr<FileChannel>(new FileChannel("C:\\log.log"))); // logger().information(""); } void uninitialize() { logger().information(""); // ServerApplication ServerApplication::uninitialize(); } int main(const std::vector<std::string>& args) { if (!config().getBool("application.runAsDaemon") && !config().getBool("application.runAsService")) { // // cout << " , " << endl; } else { // // // TaskManager tm; // tm.start(new myServerTask); // waitForTerminationRequest(); // tm.cancelAll(); tm.joinAll(); } // return Application::EXIT_OK; } }; // POCO_SERVER_MAIN(myServer)
void loadConfiguration(const std::string& path, int priority = PRIO_DEFAULT);
<?xml version="1.0" encoding="UTF-8"?> <recipe name="" preptime="5" cooktime="180"> <title> </title> <composition> <ingredient amount="3" unit=""></ingredient> <ingredient amount="0.25" unit=""></ingredient> <ingredient amount="1.5" unit=""> </ingredient> <ingredient amount="1" unit=" "></ingredient> </composition> <instructions> <step> .</step> <step> .</step> <!-- <step> .</step> - ... --> <step> , .</step> </instructions> </recipe>
void initialize(Application& self) { ofstream file("out.txt"); cout << "" << endl; loadConfiguration("a:\\conf.xml"); file << " : " << config().getString("title") << endl << " : " << config().getString("composition.ingredient[0]") << " : " << config().getString("composition.ingredient[0][@amount]") << " " << config().getString("composition.ingredient[0][@unit]") << endl << config().getString("composition.ingredient[1]") << " : " << config().getString("composition.ingredient[1][@amount]") << " " << config().getString("composition.ingredient[1][@unit]") << endl << config().getString("composition.ingredient[2]") << " : " << config().getString("composition.ingredient[2][@amount]") << " " << config().getString("composition.ingredient[2][@unit]") << endl << config().getString("composition.ingredient[3]") << " : " << config().getString("composition.ingredient[3][@amount]") << " " << config().getString("composition.ingredient[3][@unit]") << endl << " : " << endl << config().getString("instructions.step[0]") << endl << config().getString("instructions.step[1]") << endl << config().getString("instructions.step[2]") << endl; int timeToCook = config().getInt("[@cooktime]"); file << " : " << timeToCook << endl; file.close(); }
We cook: Simple bread
For this we need: Flour: 3 glass
Yeast: 0.25 grams
Warm water: 1.5 glass
Salt: 1 tsp.
Perform the steps:
Mix all ingredients and knead thoroughly.
Cover with a cloth and leave for one hour in a warm room.
Knead again, put on a baking sheet and put in the oven.
Cooking time: 180
;INI-File [Group] ValueText = "hello world" IntValue = 123
std::string text = config().getString("Group.ValueText"); // text == "Hello world" int value = config().getInt("Group.IntValue"); // value == 123
; Java property file
Value.Text = "hello world"
Int.Value = 123
std::string text = config().getString("Value.Text"); // text == "Hello world" int value = config().getInt("Int.Value"); // value == 123
// AutoPtr<ConsoleChannel> console(new ConsoleChannel); // AutoPtr<PatternFormatter> formater(new PatternFormatter); formater->setProperty("pattern", "%Y-%m-%d %H:%M:%S %s: %t"); // AutoPtr<FormattingChannel> formatingChannel(new FormattingChannel(formater, console)); // Logger::root().setChannel(formatingChannel); // Logger::get("Console").information(" "); // AutoPtr<FormattingChannel> file(new FormattingChannel(formater, AutoPtr<FileChannel>(new FileChannel("A:\\123.txt")))); // Logger::create("File", file); // Logger::get("File").fatal("I want to play a game. "); // AutoPtr<SplitterChannel> splitter(new SplitterChannel); // splitter->addChannel(file); splitter->addChannel(console); // Logger::create("AllChannel", file); // Logger::get("AllChannel").fatal(" "); // AutoPtr<EventLogChannel> event(new EventLogChannel); // Logger::create("Event", event); // ( Windows) Logger::get("Event").fatal(" ");
// sort.h class ABaseSort { protected: vector<int> array; // public: ABaseSort () {} // - virtual ~ABaseSort() {} // virtual string name() const = 0; // name , // virtual void sort() = 0; // - void loadVector(vector<int>& lArray) { array.assign(lArray.begin(), lArray.end()); } vector<int> getArray() { return array; } //Xor-swap static void swap(int &A, int &B) { A ^= B ^= A ^= B; } };
// // sort.cpp #include "sort.h" class bubbleSort : public ABaseSort { public: // string name() const { return "Bubble Sort"; } // void sort() { size_t size = array.size(); for (int i=0; i<size-1; ++i) for (int j=i; j<size; ++j) if (array[i] > array[j]) swap(array[i],array[j]); } }; // STL (std::stable_sort) class stableSort : public ABaseSort { public: // string name() const { return "Stable Sort"; } // void sort() { stable_sort(array.begin(), array.end()); } };
POCO_BEGIN_MANIFEST(ABaseSort) // POCO_EXPORT_CLASS(bubbleSort) // POCO_EXPORT_CLASS(stableSort) // stable_sort POCO_END_MANIFEST
// logic.cpp #include "sort.h" // ABaseSort Poco::ClassLoader<ABaseSort> loader; loader.loadLibrary("myImportedFile.dll"); // if (loader.isLibraryLoaded("myImportedFile.dll")) { // cout << " : " << endl; for (auto it = loader.begin(); it != loader.end(); ++it) { cout << " '" << it->first << "': " << endl; for (auto jt = it->second->begin(); jt != it->second->end(); ++jt) { cout << jt->name() << endl; } } // int arr[13] = {32,41,23,20,52,67,52,34,2,5,23,52,3}; vector<int> A (arr,arr+13); // if (ABaseSort *sort = loader.create("bubbleSort")) { // sort->loadVector(A); // sort->sort(); // auto vect = sort->getArray(); // for (auto it = vect.begin(); it != vect.end(); ++it) cout << *it << " "; cout << endl; // loader.classFor("bubbleSort").autoDelete(sort); } // stableSort if (ABaseSort *sort = loader.create("stableSort")) { sort->loadVector(A); sort->sort(); auto vect = sort->getArray(); for (auto it = vect.begin(); it != vect.end(); ++it) cout << *it << " "; cout << endl; loader.classFor("stableSort").autoDelete(sort); } }
Source: https://habr.com/ru/post/148227/
All Articles