NCBI C++ ToolKit
util_misc.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef UTIL___UTIL_MISC__HPP
2 #define UTIL___UTIL_MISC__HPP
3 
4 /* $Id: util_misc.hpp 98121 2022-09-30 15:38:11Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Sergey Satskiy
30  *
31  */
32 
33 #include <corelib/ncbifile.hpp>
34 
35 
37 
38 
39 /// Get a password without echoing the user input
40 ///
41 /// @param
42 /// prompt Printed before the user input
43 /// @return
44 /// The user input till the first carriage return
45 /// @warning
46 /// UNIX and Windows implementations differ at processing Ctrl+C:
47 /// - UNIX (except FreeBSD & IntelMAC): The usual SIGINT is
48 /// generated by the system
49 /// - UNIX (FreeBSD & IntelMAC): Ignored
50 /// - Windows: an exception is thrown
51 /// @exception
52 /// The function throws CGetPasswordFromConsoleException exception if
53 /// anything goes wrong
55 extern string g_GetPasswordFromConsole(const string& prompt);
56 
57 
58 
59 /// Exception class for g_GetPasswordFromConsole
61 {
62 public:
63  enum EErrCode {
64  eGetPassError, ///< UNIX specific: error getting password
65  eKeyboardInterrupt ///< WIN specific: Ctrl+C has been sent
66  };
67 
68  /// Translate from the error code value to its string representation
69  virtual const char* GetErrCodeString(void) const override;
70 
72 };
73 
74 
75 /// Look for an NCBI application data file or directory of the given name and
76 /// type; in general, searches directories listed in the registry entry
77 /// [NCBI] DataPath (which the environment variable NCBI_DATA_PATH may
78 /// override) followed by [NCBI] Data (or NCBI_DATA). (Passing an absolute
79 /// path bypasses this step.) NCBI_DATA_PATH and [NCBI] DataPath may both
80 /// list multiple directories, delimited as per PATH (by ';' on Windows, ':'
81 /// on Unix).
82 /// @param name The name of the file or directory to look for.
83 /// @param type The type to look for (following links unless explicitly
84 /// looking for one); CDirEntry::eUnknown matches anything.
85 /// @return
86 /// A full path if found, the empty string otherwise.
88 extern string g_FindDataFile(const CTempString& name,
90 
91 /// Ignore (or stop ignoring, depending on do_ignore) NCBI application
92 /// data files matching the given pattern to force the use of built-in
93 /// fallbacks; mainly of interest to unit tests.
95 extern void g_IgnoreDataFile(const string& pattern, bool do_ignore = true);
96 
97 /// Check whether the given file (a full path, as returned by
98 /// g_FindDataFile) is older than a built-in version containing
99 /// the specified "$Id: ..." line.
101 extern bool g_IsDataFileOld(const CTempString& path,
102  const CTempString& id_line);
103 
104 /// Check whether the given file (a full path, as returned by
105 /// g_FindDataFile) is older than a built-in version with the
106 /// specified timestamp.
108 extern bool g_IsDataFileOld(const CTempString& path,
109  const CTime& builtin_timestamp);
110 
112 
113 
114 #endif /* UTIL___UTIL_MISC__HPP */
Exception class for g_GetPasswordFromConsole.
Definition: util_misc.hpp:61
NCBI_EXCEPTION_DEFAULT(CGetPasswordFromConsoleException, CException)
@ eGetPassError
UNIX specific: error getting password.
Definition: util_misc.hpp:64
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTime –.
Definition: ncbitime.hpp:296
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
EType
Directory entry type.
Definition: ncbifile.hpp:782
@ eFile
Regular file.
Definition: ncbifile.hpp:783
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
NCBI_XUTIL_EXPORT
Parameter to control printing diagnostic message about conversion of static array data from a differe...
Definition: static_set.hpp:72
Definition: type.c:6
string g_GetPasswordFromConsole(const string &prompt)
Get a password without echoing the user input.
Definition: util_misc.cpp:62
string g_FindDataFile(const CTempString &name, CDirEntry::EType type=CDirEntry::eFile)
Look for an NCBI application data file or directory of the given name and type; in general,...
Definition: util_misc.cpp:139
bool g_IsDataFileOld(const CTempString &path, const CTempString &id_line)
Check whether the given file (a full path, as returned by g_FindDataFile) is older than a built-in ve...
Definition: util_misc.cpp:193
void g_IgnoreDataFile(const string &pattern, bool do_ignore=true)
Ignore (or stop ignoring, depending on do_ignore) NCBI application data files matching the given patt...
Definition: util_misc.cpp:182
Modified on Mon Mar 04 05:15:02 2024 by modify_doxy.py rev. 669887