Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTNumList Class Reference

#include <OTNumList.hpp>

Public Member Functions

EXPORT OTNumList (const std::set< int64_t > &theNumbers)
 
EXPORT OTNumList (const OTString &strNumbers)
 
EXPORT OTNumList (const std::string &strNumbers)
 
EXPORT OTNumList (int64_t lInput)
 
EXPORT OTNumList ()
 
EXPORT ~OTNumList ()
 
EXPORT bool Add (const OTString &strNumbers)
 
EXPORT bool Add (const std::string &strNumbers)
 
EXPORT bool Add (const int64_t &theValue)
 
EXPORT bool Remove (const int64_t &theValue)
 
EXPORT bool Verify (const int64_t &theValue) const
 
EXPORT bool Add (const OTNumList &theNumList)
 
EXPORT bool Add (const std::set< int64_t > &theNumbers)
 
EXPORT bool Remove (const std::set< int64_t > &theNumbers)
 
EXPORT bool Verify (const std::set< int64_t > &theNumbers) const
 
EXPORT bool Verify (const OTNumList &rhs) const
 
EXPORT bool VerifyAny (const OTNumList &rhs) const
 
EXPORT bool VerifyAny (const std::set< int64_t > &setData) const
 
EXPORT int32_t Count () const
 
EXPORT bool Peek (int64_t &lPeek) const
 
EXPORT bool Pop ()
 
EXPORT bool Output (std::set< int64_t > &theOutput) const
 
EXPORT bool Output (OTString &strOutput) const
 
EXPORT void Release ()
 

Detailed Description

Definition at line 156 of file OTNumList.hpp.

Constructor & Destructor Documentation

opentxs::OTNumList::OTNumList ( const std::set< int64_t > &  theNumbers)

Definition at line 148 of file OTNumList.cpp.

149 {
150  Add(theNumbers);
151 }
opentxs::OTNumList::OTNumList ( const OTString strNumbers)

Definition at line 164 of file OTNumList.cpp.

165 {
166  Add(strNumbers);
167 }
opentxs::OTNumList::OTNumList ( const std::string &  strNumbers)

Definition at line 169 of file OTNumList.cpp.

170 {
171  Add(strNumbers);
172 }
opentxs::OTNumList::OTNumList ( int64_t  lInput)

Definition at line 153 of file OTNumList.cpp.

154 {
155  Add(lInput);
156 }
opentxs::OTNumList::OTNumList ( )

Definition at line 174 of file OTNumList.cpp.

175 {
176 }
opentxs::OTNumList::~OTNumList ( )

Definition at line 178 of file OTNumList.cpp.

179 {
180 }

Member Function Documentation

bool opentxs::OTNumList::Add ( const OTString strNumbers)

Definition at line 182 of file OTNumList.cpp.

185 {
186  return Add(strNumbers.Get());
187 }
bool opentxs::OTNumList::Add ( const std::string &  strNumbers)

Definition at line 189 of file OTNumList.cpp.

193 {
194  return Add(strNumbers.c_str());
195 }
bool opentxs::OTNumList::Add ( const int64_t &  theValue)

Definition at line 272 of file OTNumList.cpp.

274 {
275  auto it = m_setData.find(theValue);
276 
277  if (m_setData.end() == it) // it's not already there, so add it.
278  {
279  m_setData.insert(theValue);
280  return true;
281  }
282  return false; // it was already there.
283 }
bool opentxs::OTNumList::Add ( const OTNumList theNumList)

Definition at line 386 of file OTNumList.cpp.

389 {
390  std::set<int64_t> theOutput;
391  theNumList.Output(theOutput); // returns false if the numlist was empty.
392 
393  return Add(theOutput);
394 }
bool opentxs::OTNumList::Add ( const std::set< int64_t > &  theNumbers)

Definition at line 396 of file OTNumList.cpp.

400 {
401  bool bSuccess = true;
402 
403  for (const auto& it : theNumbers) {
404  if (!Add(it)) // It must have already been there.
405  bSuccess = false;
406  }
407 
408  return bSuccess;
409 }
int32_t opentxs::OTNumList::Count ( ) const

Definition at line 460 of file OTNumList.cpp.

461 {
462  return static_cast<int32_t>(m_setData.size());
463 }
bool opentxs::OTNumList::Output ( std::set< int64_t > &  theOutput) const

Definition at line 430 of file OTNumList.cpp.

433 {
434  theOutput = m_setData;
435 
436  return !m_setData.empty();
437 }
bool opentxs::OTNumList::Output ( OTString strOutput) const

Definition at line 441 of file OTNumList.cpp.

443 {
444  int32_t nIterationCount = 0;
445 
446  for (auto& it : m_setData) {
447  nIterationCount++;
448 
449  strOutput.Concatenate(
450  "%s%lld",
451  // If first iteration, prepend a blank string (instead of a comma.)
452  // Like this: "%lld"
453  // But for all subsequent iterations, concatenate: ",%lld"
454  (1 == nIterationCount) ? "" : ",", it);
455  }
456 
457  return !m_setData.empty();
458 }
bool opentxs::OTNumList::Peek ( int64_t &  lPeek) const

Definition at line 285 of file OTNumList.cpp.

286 {
287  auto it = m_setData.begin();
288 
289  if (m_setData.end() != it) // it's there.
290  {
291  lPeek = *it;
292  return true;
293  }
294  return false;
295 }
bool opentxs::OTNumList::Pop ( )

Definition at line 297 of file OTNumList.cpp.

298 {
299  auto it = m_setData.begin();
300 
301  if (m_setData.end() != it) // it's there.
302  {
303  m_setData.erase(it);
304  return true;
305  }
306  return false;
307 }
void opentxs::OTNumList::Release ( )

Definition at line 465 of file OTNumList.cpp.

466 {
467  m_setData.clear();
468 }
bool opentxs::OTNumList::Remove ( const int64_t &  theValue)

Definition at line 309 of file OTNumList.cpp.

311 {
312  auto it = m_setData.find(theValue);
313 
314  if (m_setData.end() != it) // it's there.
315  {
316  m_setData.erase(it);
317  return true;
318  }
319  return false; // it wasn't there (so how could you remove it then?)
320 }
bool opentxs::OTNumList::Remove ( const std::set< int64_t > &  theNumbers)

Definition at line 411 of file OTNumList.cpp.

416 {
417  bool bSuccess = true;
418 
419  for (const auto& it : theNumbers) {
420  if (!Remove(it)) // It must have NOT already been there.
421  bSuccess = false;
422  }
423 
424  return bSuccess;
425 }
EXPORT bool Remove(const int64_t &theValue)
Definition: OTNumList.cpp:309
bool opentxs::OTNumList::Verify ( const int64_t &  theValue) const

Definition at line 322 of file OTNumList.cpp.

325 {
326  auto it = m_setData.find(theValue);
327 
328  return (m_setData.end() == it) ? false : true;
329 }
bool opentxs::OTNumList::Verify ( const std::set< int64_t > &  theNumbers) const

Definition at line 335 of file OTNumList.cpp.

336 {
337  bool bSuccess = true;
338 
339  for (const auto& it : theNumbers) {
340  if (!Verify(it)) // It must have NOT already been there.
341  bSuccess = false;
342  }
343 
344  return bSuccess;
345 }
EXPORT bool Verify(const int64_t &theValue) const
Definition: OTNumList.cpp:322
bool opentxs::OTNumList::Verify ( const OTNumList rhs) const

True/False, based on whether OTNumLists MATCH in COUNT and CONTENT (NOT ORDER.)

Definition at line 350 of file OTNumList.cpp.

351 {
352  // Verify they have the same number of elements.
353  //
354  if (Count() != rhs.Count()) return false;
355 
356  // Verify each value on *this is also found on rhs.
357  //
358  for (auto& it : m_setData) {
359  if (!rhs.Verify(it)) return false;
360  }
361 
362  return true;
363 }
EXPORT int32_t Count() const
Definition: OTNumList.cpp:460
bool opentxs::OTNumList::VerifyAny ( const OTNumList rhs) const

True/False, based on whether ANY of the numbers in rhs are found in *this.

Definition at line 367 of file OTNumList.cpp.

368 {
369  return rhs.VerifyAny(m_setData);
370 }
bool opentxs::OTNumList::VerifyAny ( const std::set< int64_t > &  setData) const

Verify whether ANY of the numbers on *this are found in setData.

Definition at line 374 of file OTNumList.cpp.

375 {
376  for (const auto& it : m_setData) {
377  auto it_find = setData.find(it);
378 
379  if (it_find != setData.end()) // found a match.
380  return true;
381  }
382 
383  return false;
384 }

The documentation for this class was generated from the following files: