MRPT  2.0.4
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/core/exceptions.h>
12 #include <cstdio>
13 #include <iostream>
14 
15 using namespace mrpt;
16 using namespace mrpt::system;
17 using namespace std;
18 
19 // ------------------------------------------------------
20 // TestWatch
21 // ------------------------------------------------------
22 void TestWatch()
23 {
25  CFileSystemWatcher::TFileSystemChangeList::iterator it;
26 
27  CFileSystemWatcher watch(".");
28 
29  printf("Watching directory '.'...\n Press any key to exit.\n");
30 
31  while (!mrpt::system::os::kbhit())
32  {
33  watch.getChanges(lstChanges);
34 
35  for (it = lstChanges.begin(); it != lstChanges.end(); it++)
36  {
37  cout << "changed: '" << it->path << "' ";
38  if (it->isDir) cout << "isDir ";
39  if (it->eventModified) cout << "modified ";
40  if (it->eventCloseWrite) cout << "close_write ";
41  if (it->eventDeleted) cout << "deleted ";
42  if (it->eventMovedTo) cout << "moved_to ";
43  if (it->eventMovedFrom) cout << "moved_from ";
44  if (it->eventCreated) cout << "created ";
45  if (it->eventAccessed) cout << "accessed";
46 
47  cout << endl;
48  }
49 
50  std::this_thread::sleep_for(100ms);
51  }
52 }
53 
54 int main()
55 {
56  try
57  {
58  TestWatch();
59  return 0;
60  }
61  catch (const std::exception& e)
62  {
63  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
64  return -1;
65  }
66 }
STL namespace.
std::deque< TFileSystemChange > TFileSystemChangeList
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This class subscribes to notifications of file system changes, thus it can be used to efficiently sta...
void TestWatch()
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:403
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020