Apollo  6.0
Open source self driving car software
Classes | Enumerations | Functions | Variables
apollo::cyber::common Namespace Reference

Classes

class  GlobalData
 

Enumerations

enum  FileType { TYPE_FILE, TYPE_DIR }
 

Functions

std::string GetEnv (const std::string &var_name, const std::string &default_value="")
 
const std::string WorkRoot ()
 
bool SetProtoToASCIIFile (const google::protobuf::Message &message, int file_descriptor)
 
bool SetProtoToASCIIFile (const google::protobuf::Message &message, const std::string &file_name)
 Sets the content of the file specified by the file_name to be the ascii representation of the input protobuf. More...
 
bool GetProtoFromASCIIFile (const std::string &file_name, google::protobuf::Message *message)
 Parses the content of the file specified by the file_name as ascii representation of protobufs, and merges the parsed content to the proto. More...
 
bool SetProtoToBinaryFile (const google::protobuf::Message &message, const std::string &file_name)
 Sets the content of the file specified by the file_name to be the binary representation of the input protobuf. More...
 
bool GetProtoFromBinaryFile (const std::string &file_name, google::protobuf::Message *message)
 Parses the content of the file specified by the file_name as binary representation of protobufs, and merges the parsed content to the proto. More...
 
bool GetProtoFromFile (const std::string &file_name, google::protobuf::Message *message)
 Parses the content of the file specified by the file_name as a representation of protobufs, and merges the parsed content to the proto. More...
 
bool GetContent (const std::string &file_name, std::string *content)
 Get file content as string. More...
 
std::string GetAbsolutePath (const std::string &prefix, const std::string &relative_path)
 Get absolute path by concatenating prefix and relative_path. More...
 
bool PathExists (const std::string &path)
 Check if the path exists. More...
 
bool DirectoryExists (const std::string &directory_path)
 Check if the directory specified by directory_path exists and is indeed a directory. More...
 
std::vector< std::string > Glob (const std::string &pattern)
 Expand path pattern to matched paths. More...
 
bool CopyFile (const std::string &from, const std::string &to)
 Copy a file. More...
 
bool CopyDir (const std::string &from, const std::string &to)
 Copy a directory. More...
 
bool Copy (const std::string &from, const std::string &to)
 Copy a file or directory. More...
 
bool EnsureDirectory (const std::string &directory_path)
 Check if a specified directory specified by directory_path exists. If not, recursively create the directory (and its parents). More...
 
bool RemoveAllFiles (const std::string &directory_path)
 Remove all the files under a specified directory. Note that sub-directories are NOT affected. More...
 
std::vector< std::string > ListSubPaths (const std::string &directory_path, const unsigned char d_type=DT_DIR)
 List sub-paths. More...
 
std::string GetFileName (const std::string &path, const bool remove_extension=false)
 
std::string GetCurrentPath ()
 
bool DeleteFile (const std::string &filename)
 
bool GetType (const std::string &filename, FileType *type)
 
bool CreateDir (const std::string &dir)
 
template<typename T >
UnixToGpsSeconds (T unix_seconds)
 
int64_t UnixToGpsMicroseconds (int64_t unix_microseconds)
 
int64_t UnixToGpsNanoseconds (int64_t unix_nanoseconds)
 
template<typename T >
GpsToUnixSeconds (T gps_seconds)
 
int64_t GpsToUnixMicroseconds (int64_t gps_microseconds)
 
int64_t GpsToUnixNanoseconds (int64_t gps_nanoseconds)
 
uint64_t GpsToUnixMicroseconds (uint64_t gps_microseconds)
 
uint64_t GpsToUnixNanoseconds (uint64_t gps_nanoseconds)
 
uint64_t StringToUnixSeconds (const std::string &time_str, const std::string &format_str="%Y-%m-%d %H:%M:%S")
 
std::string UnixSecondsToString (uint64_t unix_seconds, const std::string &format_str="%Y-%m-%d-%H:%M:%S")
 
std::size_t Hash (const std::string &key)
 
template<typename Enum >
auto ToInt (Enum const value) -> typename std::underlying_type< Enum >::type
 

Variables

constexpr int32_t UNIX_GPS_DIFF = 315964800
 
constexpr int64_t ONE_MILLION = 1000000L
 
constexpr int64_t ONE_BILLION = 1000000000L
 

Enumeration Type Documentation

◆ FileType

Enumerator
TYPE_FILE 
TYPE_DIR 

Function Documentation

◆ Copy()

bool apollo::cyber::common::Copy ( const std::string &  from,
const std::string &  to 
)

Copy a file or directory.

Parameters
fromThe path to copy from.
toThe path to copy to.
Returns
If the action is successful.

◆ CopyDir()

bool apollo::cyber::common::CopyDir ( const std::string &  from,
const std::string &  to 
)

Copy a directory.

Parameters
fromThe path to copy from.
toThe path to copy to.
Returns
If the action is successful.

◆ CopyFile()

bool apollo::cyber::common::CopyFile ( const std::string &  from,
const std::string &  to 
)

Copy a file.

Parameters
fromThe file path to copy from.
toThe file path to copy to.
Returns
If the action is successful.

◆ CreateDir()

bool apollo::cyber::common::CreateDir ( const std::string &  dir)

◆ DeleteFile()

bool apollo::cyber::common::DeleteFile ( const std::string &  filename)

◆ DirectoryExists()

bool apollo::cyber::common::DirectoryExists ( const std::string &  directory_path)

Check if the directory specified by directory_path exists and is indeed a directory.

Parameters
directory_pathDirectory path.
Returns
If the directory specified by directory_path exists and is indeed a directory.

◆ EnsureDirectory()

bool apollo::cyber::common::EnsureDirectory ( const std::string &  directory_path)

Check if a specified directory specified by directory_path exists. If not, recursively create the directory (and its parents).

Parameters
directory_pathDirectory path.
Returns
If the directory does exist or its creation is successful.

◆ GetAbsolutePath()

std::string apollo::cyber::common::GetAbsolutePath ( const std::string &  prefix,
const std::string &  relative_path 
)

Get absolute path by concatenating prefix and relative_path.

Returns
The absolute path.

◆ GetContent()

bool apollo::cyber::common::GetContent ( const std::string &  file_name,
std::string *  content 
)

Get file content as string.

Parameters
file_nameThe name of the file to read content.
contentThe file content.
Returns
If the action is successful.

◆ GetCurrentPath()

std::string apollo::cyber::common::GetCurrentPath ( )

◆ GetEnv()

std::string apollo::cyber::common::GetEnv ( const std::string &  var_name,
const std::string &  default_value = "" 
)
inline

◆ GetFileName()

std::string apollo::cyber::common::GetFileName ( const std::string &  path,
const bool  remove_extension = false 
)

◆ GetProtoFromASCIIFile()

bool apollo::cyber::common::GetProtoFromASCIIFile ( const std::string &  file_name,
google::protobuf::Message *  message 
)

Parses the content of the file specified by the file_name as ascii representation of protobufs, and merges the parsed content to the proto.

Parameters
file_nameThe name of the file to parse whose content.
messageThe proto to carry the parsed content in the specified file.
Returns
If the action is successful.

◆ GetProtoFromBinaryFile()

bool apollo::cyber::common::GetProtoFromBinaryFile ( const std::string &  file_name,
google::protobuf::Message *  message 
)

Parses the content of the file specified by the file_name as binary representation of protobufs, and merges the parsed content to the proto.

Parameters
file_nameThe name of the file to parse whose content.
messageThe proto to carry the parsed content in the specified file.
Returns
If the action is successful.

◆ GetProtoFromFile()

bool apollo::cyber::common::GetProtoFromFile ( const std::string &  file_name,
google::protobuf::Message *  message 
)

Parses the content of the file specified by the file_name as a representation of protobufs, and merges the parsed content to the proto.

Parameters
file_nameThe name of the file to parse whose content.
messageThe proto to carry the parsed content in the specified file.
Returns
If the action is successful.

◆ GetType()

bool apollo::cyber::common::GetType ( const std::string &  filename,
FileType type 
)

◆ Glob()

std::vector<std::string> apollo::cyber::common::Glob ( const std::string &  pattern)

Expand path pattern to matched paths.

Parameters
patternPath pattern, which may contain wildcards [?*].
Returns
Matched path list.

◆ GpsToUnixMicroseconds() [1/2]

int64_t apollo::cyber::common::GpsToUnixMicroseconds ( int64_t  gps_microseconds)
inline

◆ GpsToUnixMicroseconds() [2/2]

uint64_t apollo::cyber::common::GpsToUnixMicroseconds ( uint64_t  gps_microseconds)
inline

◆ GpsToUnixNanoseconds() [1/2]

int64_t apollo::cyber::common::GpsToUnixNanoseconds ( int64_t  gps_nanoseconds)
inline

◆ GpsToUnixNanoseconds() [2/2]

uint64_t apollo::cyber::common::GpsToUnixNanoseconds ( uint64_t  gps_nanoseconds)
inline

◆ GpsToUnixSeconds()

template<typename T >
T apollo::cyber::common::GpsToUnixSeconds ( gps_seconds)

◆ Hash()

std::size_t apollo::cyber::common::Hash ( const std::string &  key)
inline

◆ ListSubPaths()

std::vector<std::string> apollo::cyber::common::ListSubPaths ( const std::string &  directory_path,
const unsigned char  d_type = DT_DIR 
)

List sub-paths.

Parameters
directory_pathDirectory path.
d_typeSub-path type, DT_DIR for directory, or DT_REG for file.
Returns
A vector of sub-paths, without the directory_path prefix.

◆ PathExists()

bool apollo::cyber::common::PathExists ( const std::string &  path)

Check if the path exists.

Parameters
patha file name, such as /a/b/c.txt
Returns
If the path exists.

◆ RemoveAllFiles()

bool apollo::cyber::common::RemoveAllFiles ( const std::string &  directory_path)

Remove all the files under a specified directory. Note that sub-directories are NOT affected.

Parameters
directory_pathDirectory path.
Returns
If the action is successful.

◆ SetProtoToASCIIFile() [1/2]

bool apollo::cyber::common::SetProtoToASCIIFile ( const google::protobuf::Message &  message,
int  file_descriptor 
)

◆ SetProtoToASCIIFile() [2/2]

bool apollo::cyber::common::SetProtoToASCIIFile ( const google::protobuf::Message &  message,
const std::string &  file_name 
)

Sets the content of the file specified by the file_name to be the ascii representation of the input protobuf.

Parameters
messageThe proto to output to the specified file.
file_nameThe name of the target file to set the content.
Returns
If the action is successful.

◆ SetProtoToBinaryFile()

bool apollo::cyber::common::SetProtoToBinaryFile ( const google::protobuf::Message &  message,
const std::string &  file_name 
)

Sets the content of the file specified by the file_name to be the binary representation of the input protobuf.

Parameters
messageThe proto to output to the specified file.
file_nameThe name of the target file to set the content.
Returns
If the action is successful.

◆ StringToUnixSeconds()

uint64_t apollo::cyber::common::StringToUnixSeconds ( const std::string &  time_str,
const std::string &  format_str = "%Y-%m-%d %H:%M:%S" 
)
inline

◆ ToInt()

template<typename Enum >
auto apollo::cyber::common::ToInt ( Enum const  value) -> typename std::underlying_type<Enum>::type

◆ UnixSecondsToString()

std::string apollo::cyber::common::UnixSecondsToString ( uint64_t  unix_seconds,
const std::string &  format_str = "%Y-%m-%d-%H:%M:%S" 
)
inline

◆ UnixToGpsMicroseconds()

int64_t apollo::cyber::common::UnixToGpsMicroseconds ( int64_t  unix_microseconds)
inline

◆ UnixToGpsNanoseconds()

int64_t apollo::cyber::common::UnixToGpsNanoseconds ( int64_t  unix_nanoseconds)
inline

◆ UnixToGpsSeconds()

template<typename T >
T apollo::cyber::common::UnixToGpsSeconds ( unix_seconds)

◆ WorkRoot()

const std::string apollo::cyber::common::WorkRoot ( )
inline

Variable Documentation

◆ ONE_BILLION

constexpr int64_t apollo::cyber::common::ONE_BILLION = 1000000000L

◆ ONE_MILLION

constexpr int64_t apollo::cyber::common::ONE_MILLION = 1000000L

◆ UNIX_GPS_DIFF

constexpr int32_t apollo::cyber::common::UNIX_GPS_DIFF = 315964800