Skip to content

Commit

Permalink
Standardise use of type aliases and rvalue references in for loops (#32)
Browse files Browse the repository at this point in the history
We currently use a mixture of type aliases and typedefs in our code. Since type aliasing 
provides a strict superset of the functionality of typedefs, but is otherwise essentially 
equivalent, it seems sensible to standardise on only using type aliasing throughout. This also 
adopts the convention of not using rvalue references in for loops, except for template code, on 
grounds of readability.
  • Loading branch information
tveasey committed Apr 4, 2018
1 parent f26b907 commit ec28abd
Show file tree
Hide file tree
Showing 400 changed files with 2,996 additions and 2,997 deletions.
2 changes: 1 addition & 1 deletion bin/autoconfig/CCmdLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace autoconfig
class CCmdLineParser
{
public:
typedef std::vector<std::string> TStrVec;
using TStrVec = std::vector<std::string>;

public:
//! Parse the arguments and return options if appropriate.
Expand Down
33 changes: 17 additions & 16 deletions include/api/CAnomalyJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,22 @@ class API_EXPORT CAnomalyJob : public CDataProcessor


public:
typedef std::function<void(const CModelSnapshotJsonWriter::SModelSnapshotReport &)> TPersistCompleteFunc;
typedef model::CAnomalyDetector::TAnomalyDetectorPtr TAnomalyDetectorPtr;
typedef std::vector<TAnomalyDetectorPtr> TAnomalyDetectorPtrVec;
typedef std::vector<TAnomalyDetectorPtr>::iterator TAnomalyDetectorPtrVecItr;
typedef std::vector<TAnomalyDetectorPtr>::const_iterator TAnomalyDetectorPtrVecCItr;
typedef std::vector<model::CSearchKey> TKeyVec;
typedef boost::unordered_map<model::CSearchKey::TStrKeyPr,
TAnomalyDetectorPtr,
model::CStrKeyPrHash,
model::CStrKeyPrEqual> TKeyAnomalyDetectorPtrUMap;
typedef std::pair<model::CSearchKey::TStrCRefKeyCRefPr, TAnomalyDetectorPtr> TKeyCRefAnomalyDetectorPtrPr;
typedef std::vector<TKeyCRefAnomalyDetectorPtrPr> TKeyCRefAnomalyDetectorPtrPrVec;
typedef model::CAnomalyDetector::TModelPlotDataVec TModelPlotDataVec;
typedef TModelPlotDataVec::const_iterator TModelPlotDataVecCItr;
typedef model::CBucketQueue<TModelPlotDataVec> TModelPlotDataVecQueue;
using TPersistCompleteFunc = std::function<void(const CModelSnapshotJsonWriter::SModelSnapshotReport &)>;
using TAnomalyDetectorPtr = model::CAnomalyDetector::TAnomalyDetectorPtr;
using TAnomalyDetectorPtrVec = std::vector<TAnomalyDetectorPtr>;
using TAnomalyDetectorPtrVecItr = std::vector<TAnomalyDetectorPtr>::iterator;
using TAnomalyDetectorPtrVecCItr = std::vector<TAnomalyDetectorPtr>::const_iterator;
using TKeyVec = std::vector<model::CSearchKey>;
using TKeyAnomalyDetectorPtrUMap =
boost::unordered_map<model::CSearchKey::TStrKeyPr,
TAnomalyDetectorPtr,
model::CStrKeyPrHash,
model::CStrKeyPrEqual>;
using TKeyCRefAnomalyDetectorPtrPr = std::pair<model::CSearchKey::TStrCRefKeyCRefPr, TAnomalyDetectorPtr>;
using TKeyCRefAnomalyDetectorPtrPrVec = std::vector<TKeyCRefAnomalyDetectorPtrPr>;
using TModelPlotDataVec = model::CAnomalyDetector::TModelPlotDataVec;
using TModelPlotDataVecCItr = TModelPlotDataVec::const_iterator;
using TModelPlotDataVecQueue = model::CBucketQueue<TModelPlotDataVec>;

struct API_EXPORT SRestoredStateDetail
{
Expand Down Expand Up @@ -155,7 +156,7 @@ class API_EXPORT CAnomalyJob : public CDataProcessor
TKeyCRefAnomalyDetectorPtrPrVec s_Detectors;
};

typedef boost::shared_ptr<SBackgroundPersistArgs> TBackgroundPersistArgsPtr;
using TBackgroundPersistArgsPtr = boost::shared_ptr<SBackgroundPersistArgs>;

public:
CAnomalyJob(const std::string &jobId,
Expand Down
16 changes: 8 additions & 8 deletions include/api/CBenchMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ class API_EXPORT CBenchMarker
{
public:
//! A count and and example string
typedef std::pair<size_t, std::string> TSizeStrPr;
using TSizeStrPr = std::pair<size_t, std::string>;

//! Used for mapping Ml type to count and example
typedef std::map<int, TSizeStrPr> TIntSizeStrPrMap;
typedef TIntSizeStrPrMap::iterator TIntSizeStrPrMapItr;
typedef TIntSizeStrPrMap::const_iterator TIntSizeStrPrMapCItr;
using TIntSizeStrPrMap = std::map<int, TSizeStrPr>;
using TIntSizeStrPrMapItr = TIntSizeStrPrMap::iterator;
using TIntSizeStrPrMapCItr = TIntSizeStrPrMap::const_iterator;

//! A regex and its corresponding type count map
typedef std::pair<core::CRegex, TIntSizeStrPrMap> TRegexIntSizeStrPrMapPr;
using TRegexIntSizeStrPrMapPr = std::pair<core::CRegex, TIntSizeStrPrMap>;

//! Vector of regexes with corresponding type count maps
typedef std::vector<TRegexIntSizeStrPrMapPr> TRegexIntSizeStrPrMapPrVec;
typedef TRegexIntSizeStrPrMapPrVec::iterator TRegexIntSizeStrPrMapPrVecItr;
typedef TRegexIntSizeStrPrMapPrVec::const_iterator TRegexIntSizeStrPrMapPrVecCItr;
using TRegexIntSizeStrPrMapPrVec = std::vector<TRegexIntSizeStrPrMapPr>;
using TRegexIntSizeStrPrMapPrVecItr = TRegexIntSizeStrPrMapPrVec::iterator;
using TRegexIntSizeStrPrMapPrVecCItr = TRegexIntSizeStrPrMapPrVec::const_iterator;

public:
CBenchMarker(void);
Expand Down
4 changes: 2 additions & 2 deletions include/api/CCategoryExamplesCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace api
class API_EXPORT CCategoryExamplesCollector
{
public:
typedef std::set<std::string> TStrSet;
typedef TStrSet::const_iterator TStrSetCItr;
using TStrSet = std::set<std::string>;
using TStrSetCItr = TStrSet::const_iterator;

//! Truncate examples to be no longer than this
static const size_t MAX_EXAMPLE_LENGTH;
Expand Down
6 changes: 3 additions & 3 deletions include/api/CCsvOutputWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class API_EXPORT CCsvOutputWriter : public COutputHandler
//! an appropriate level, avoiding regular memory allocations.
std::string m_WorkRecord;

typedef std::pair<std::string, std::string > TStrStrPr;
typedef std::set<TStrStrPr> TStrStrPrSet;
typedef TStrStrPrSet::const_iterator TStrStrPrSetCItr;
using TStrStrPr = std::pair<std::string, std::string>;
using TStrStrPrSet = std::set<TStrStrPr>;
using TStrStrPrSetCItr = TStrStrPrSet::const_iterator;

//! Messages to be printed before the next lot of output
TStrStrPrSet m_Messages;
Expand Down
12 changes: 6 additions & 6 deletions include/api/CDataProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class API_EXPORT CDataProcessor : private core::CNonCopyable
static const std::string CONTROL_FIELD_NAME;

public:
typedef std::vector<std::string> TStrVec;
typedef TStrVec::iterator TStrVecItr;
typedef TStrVec::const_iterator TStrVecCItr;
using TStrVec = std::vector<std::string>;
using TStrVecItr = TStrVec::iterator;
using TStrVecCItr = TStrVec::const_iterator;

typedef boost::unordered_map<std::string, std::string> TStrStrUMap;
typedef TStrStrUMap::iterator TStrStrUMapItr;
typedef TStrStrUMap::const_iterator TStrStrUMapCItr;
using TStrStrUMap = boost::unordered_map<std::string, std::string>;
using TStrStrUMapItr = TStrStrUMap::iterator;
using TStrStrUMapCItr = TStrStrUMap::const_iterator;

public:
CDataProcessor(void);
Expand Down
8 changes: 4 additions & 4 deletions include/api/CDataTyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class API_EXPORT CDataTyper
{
public:
//! Used for storing distinct token IDs
typedef boost::unordered_map<std::string, std::string> TStrStrUMap;
typedef TStrStrUMap::const_iterator TStrStrUMapCItr;
using TStrStrUMap = boost::unordered_map<std::string, std::string>;
using TStrStrUMapCItr = TStrStrUMap::const_iterator;

//! Shared pointer to an instance of this class
typedef boost::shared_ptr<CDataTyper> TDataTyperP;
using TDataTyperP = boost::shared_ptr<CDataTyper>;

//! Shared pointer to an instance of this class
typedef std::function<void(core::CStatePersistInserter &)> TPersistFunc;
using TPersistFunc = std::function<void(core::CStatePersistInserter &)>;

public:
CDataTyper(const std::string &fieldName);
Expand Down
4 changes: 2 additions & 2 deletions include/api/CDetectionRulesJsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace api
class API_EXPORT CDetectionRulesJsonParser
{
public:
typedef std::vector<model::CDetectionRule> TDetectionRuleVec;
typedef boost::unordered_map<std::string, core::CPatternSet> TStrPatternSetUMap;
using TDetectionRuleVec = std::vector<model::CDetectionRule>;
using TStrPatternSetUMap = boost::unordered_map<std::string, core::CPatternSet>;

public:
//! Default constructor
Expand Down
26 changes: 13 additions & 13 deletions include/api/CFieldConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class API_EXPORT CFieldConfig
//! Uniqueness is enforced by config key and also by the combination of
//! function, field name, by field name, over field name and
//! partition field name.
typedef boost::multi_index::multi_index_container<
using TFieldOptionsMIndex = boost::multi_index::multi_index_container<
CFieldOptions,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
Expand All @@ -361,28 +361,28 @@ class API_EXPORT CFieldConfig
>
>
>
> TFieldOptionsMIndex;
>;

typedef TFieldOptionsMIndex::iterator TFieldOptionsMIndexItr;
typedef TFieldOptionsMIndex::const_iterator TFieldOptionsMIndexCItr;
using TFieldOptionsMIndexItr = TFieldOptionsMIndex::iterator;
using TFieldOptionsMIndexCItr = TFieldOptionsMIndex::const_iterator;

//! Used to maintain a list of all unique config keys
typedef std::set<int> TIntSet;
using TIntSet = std::set<int>;

//! Used to return the superset of enabled field names
typedef std::set<std::string> TStrSet;
using TStrSet = std::set<std::string>;

//! Used to obtain command line clause tokens
typedef std::vector<std::string> TStrVec;
typedef TStrVec::iterator TStrVecItr;
using TStrVec = std::vector<std::string>;
using TStrVecItr = TStrVec::iterator;

typedef std::vector<model::CDetectionRule> TDetectionRuleVec;
typedef boost::unordered_map<int, TDetectionRuleVec> TIntDetectionRuleVecUMap;
using TDetectionRuleVec = std::vector<model::CDetectionRule>;
using TIntDetectionRuleVecUMap = boost::unordered_map<int, TDetectionRuleVec>;

typedef boost::unordered_map<std::string, core::CPatternSet> TStrPatternSetUMap;
using TStrPatternSetUMap = boost::unordered_map<std::string, core::CPatternSet>;

typedef std::pair<std::string, model::CDetectionRule> TStrDetectionRulePr;
typedef std::vector<TStrDetectionRulePr> TStrDetectionRulePrVec;
using TStrDetectionRulePr = std::pair<std::string, model::CDetectionRule>;
using TStrDetectionRulePrVec = std::vector<TStrDetectionRulePr>;

public:
//! Construct empty. This call should generally be followed by a call to
Expand Down
24 changes: 12 additions & 12 deletions include/api/CFieldDataTyper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ class API_EXPORT CFieldDataTyper : public CDataProcessor
public:
// A type of token list data typer that DOESN'T exclude fields from its
// analysis
typedef CTokenListDataTyper<true, // Warping
true, // Underscores
true, // Dots
true, // Dashes
true, // Ignore leading digit
true, // Ignore hex
true, // Ignore date words
false, // Ignore field names
2, // Min dictionary word length
core::CWordDictionary::TWeightVerbs5Other2>
TTokenListDataTyperKeepsFields;
using TTokenListDataTyperKeepsFields =
CTokenListDataTyper<true, // Warping
true, // Underscores
true, // Dots
true, // Dashes
true, // Ignore leading digit
true, // Ignore hex
true, // Ignore date words
false, // Ignore field names
2, // Min dictionary word length
core::CWordDictionary::TWeightVerbs5Other2>;

public:
//! Construct without persistence capability
Expand Down Expand Up @@ -151,7 +151,7 @@ class API_EXPORT CFieldDataTyper : public CDataProcessor
void acknowledgeFlush(const std::string &flushId);

private:
typedef CCategoryExamplesCollector::TStrSet TStrSet;
using TStrSet = CCategoryExamplesCollector::TStrSet;

private:
//! The job ID
Expand Down
6 changes: 3 additions & 3 deletions include/api/CHierarchicalResultsWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class API_EXPORT CHierarchicalResultsWriter : public model::CHierarchicalResults
};

public:
typedef SResults TResults;
typedef std::function<bool(TResults)> TResultWriterFunc;
typedef std::function<bool(core_t::TTime, TNode, bool)> TPivotWriterFunc;
using TResults = SResults;
using TResultWriterFunc = std::function<bool(TResults)>;
using TPivotWriterFunc = std::function<bool(core_t::TTime, TNode, bool)>;

public:
CHierarchicalResultsWriter(const model::CLimits &limits,
Expand Down
22 changes: 11 additions & 11 deletions include/api/CInputParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ namespace api
class API_EXPORT CInputParser : private core::CNonCopyable
{
public:
typedef std::vector<std::string> TStrVec;
typedef TStrVec::iterator TStrVecItr;
typedef TStrVec::const_iterator TStrVecCItr;
using TStrVec = std::vector<std::string>;
using TStrVecItr = TStrVec::iterator;
using TStrVecCItr = TStrVec::const_iterator;

typedef boost::unordered_map<std::string, std::string> TStrStrUMap;
typedef TStrStrUMap::iterator TStrStrUMapItr;
typedef TStrStrUMap::const_iterator TStrStrUMapCItr;
using TStrStrUMap = boost::unordered_map<std::string, std::string>;
using TStrStrUMapItr = TStrStrUMap::iterator;
using TStrStrUMapCItr = TStrStrUMap::const_iterator;

//! For fast access to the field values without repeatedly computing the
//! hash, we maintain references to the values in the hash map
typedef boost::reference_wrapper<std::string> TStrRef;
typedef std::vector<TStrRef> TStrRefVec;
typedef TStrRefVec::iterator TStrRefVecItr;
typedef TStrRefVec::const_iterator TStrRefVecCItr;
using TStrRef = boost::reference_wrapper<std::string>;
using TStrRefVec = std::vector<TStrRef>;
using TStrRefVecItr = TStrRefVec::iterator;
using TStrRefVecCItr = TStrRefVec::const_iterator;

//! Callback function prototype that gets called for each record
//! read from the input stream. Return false to exit reader loop.
//! Arguments are:
//! 1) Header row fields
//! 2) Data row fields
typedef std::function<bool(const TStrStrUMap &)> TReaderFunc;
using TReaderFunc = std::function<bool(const TStrStrUMap &)>;

public:
CInputParser(void);
Expand Down
56 changes: 28 additions & 28 deletions include/api/CJsonOutputWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,29 @@ namespace api
class API_EXPORT CJsonOutputWriter : public COutputHandler
{
public:
typedef boost::shared_ptr<rapidjson::Document> TDocumentPtr;
typedef boost::weak_ptr<rapidjson::Document> TDocumentWeakPtr;
typedef std::vector<TDocumentWeakPtr> TDocumentWeakPtrVec;
typedef TDocumentWeakPtrVec::iterator TDocumentWeakPtrVecItr;
typedef TDocumentWeakPtrVec::const_iterator TDocumentWeakPtrVecCItr;

typedef std::pair<TDocumentWeakPtr, int> TDocumentWeakPtrIntPr;
typedef std::vector<TDocumentWeakPtrIntPr> TDocumentWeakPtrIntPrVec;
typedef TDocumentWeakPtrIntPrVec::iterator TDocumentWeakPtrIntPrVecItr;
typedef std::map<std::string, TDocumentWeakPtrVec> TStrDocumentPtrVecMap;

typedef std::vector<std::string> TStrVec;
typedef core::CSmallVector<std::string, 1> TStr1Vec;
typedef std::vector<core_t::TTime> TTimeVec;
typedef std::vector<double> TDoubleVec;
typedef std::pair<double, double> TDoubleDoublePr;
typedef std::vector<TDoubleDoublePr> TDoubleDoublePrVec;
typedef std::pair<double, TDoubleDoublePr> TDoubleDoubleDoublePrPr;
typedef std::vector<TDoubleDoubleDoublePrPr> TDoubleDoubleDoublePrPrVec;
typedef std::pair<std::string, double> TStringDoublePr;
typedef std::vector<TStringDoublePr> TStringDoublePrVec;

typedef boost::shared_ptr<rapidjson::Value> TValuePtr;
using TDocumentPtr = boost::shared_ptr<rapidjson::Document>;
using TDocumentWeakPtr = boost::weak_ptr<rapidjson::Document>;
using TDocumentWeakPtrVec = std::vector<TDocumentWeakPtr>;
using TDocumentWeakPtrVecItr = TDocumentWeakPtrVec::iterator;
using TDocumentWeakPtrVecCItr = TDocumentWeakPtrVec::const_iterator;

using TDocumentWeakPtrIntPr = std::pair<TDocumentWeakPtr, int>;
using TDocumentWeakPtrIntPrVec = std::vector<TDocumentWeakPtrIntPr>;
using TDocumentWeakPtrIntPrVecItr = TDocumentWeakPtrIntPrVec::iterator;
using TStrDocumentPtrVecMap = std::map<std::string, TDocumentWeakPtrVec>;

using TStrVec = std::vector<std::string>;
using TStr1Vec = core::CSmallVector<std::string, 1>;
using TTimeVec = std::vector<core_t::TTime>;
using TDoubleVec = std::vector<double>;
using TDoubleDoublePr = std::pair<double, double>;
using TDoubleDoublePrVec = std::vector<TDoubleDoublePr>;
using TDoubleDoubleDoublePrPr = std::pair<double, TDoubleDoublePr>;
using TDoubleDoubleDoublePrPrVec = std::vector<TDoubleDoubleDoublePrPr>;
using TStringDoublePr = std::pair<std::string, double>;
using TStringDoublePrVec = std::vector<TStringDoublePr>;

using TValuePtr = boost::shared_ptr<rapidjson::Value>;

//! Structure to buffer up information about each bucket that we have
//! unwritten results for
Expand Down Expand Up @@ -175,13 +175,13 @@ class API_EXPORT CJsonOutputWriter : public COutputHandler
TStr1Vec s_ScheduledEventDescriptions;
};

typedef std::map<core_t::TTime, SBucketData> TTimeBucketDataMap;
typedef TTimeBucketDataMap::iterator TTimeBucketDataMapItr;
typedef TTimeBucketDataMap::const_iterator TTimeBucketDataMapCItr;
using TTimeBucketDataMap = std::map<core_t::TTime, SBucketData>;
using TTimeBucketDataMapItr = TTimeBucketDataMap::iterator;
using TTimeBucketDataMapCItr = TTimeBucketDataMap::const_iterator;

private:
typedef CCategoryExamplesCollector::TStrSet TStrSet;
typedef TStrSet::const_iterator TStrSetCItr;
using TStrSet = CCategoryExamplesCollector::TStrSet;
using TStrSetCItr = TStrSet::const_iterator;

public:
//! Constructor that causes output to be written to the specified wrapped stream
Expand Down
2 changes: 1 addition & 1 deletion include/api/CLengthEncodedInputParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class API_EXPORT CLengthEncodedInputParser : public CInputParser
//! Reference to the stream we're going to read from
std::istream &m_StrmIn;

typedef boost::scoped_array<char> TScopedCharArray;
using TScopedCharArray = boost::scoped_array<char>;

//! The working buffer is also held as a member to avoid constantly
//! reallocating it. It is a raw character array rather than a string
Expand Down
Loading

0 comments on commit ec28abd

Please sign in to comment.