Column.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright: All Rights Reserved
  2. // Author: egametang@gmail.com (tanghai)
  3. #include <boost/foreach.hpp>
  4. #include <boost/format.hpp>
  5. #include <google/protobuf/descriptor.h>
  6. #include "Base/Marcos.h"
  7. #include "Orm/Column.h"
  8. #include "Orm/Exception.h"
  9. namespace Egametang {
  10. Column::Column()
  11. {
  12. }
  13. Column::Column(const std::string& name)
  14. {
  15. columns.push_back(name);
  16. }
  17. Column::Column(const Column& column)
  18. {
  19. columns = column.columns;
  20. }
  21. Column::~Column()
  22. {
  23. }
  24. Column& Column::operator()(const std::string& name)
  25. {
  26. columns.push_back(name);
  27. return *this;
  28. }
  29. bool Column::Empty() const
  30. {
  31. return !columns.size();
  32. }
  33. std::string Column::ToString() const
  34. {
  35. std::string columnStr;
  36. foreach (const std::string& column, columns)
  37. {
  38. columnStr += column + ", ";
  39. }
  40. columnStr.resize(columnStr.size() - 2);
  41. return columnStr;
  42. }
  43. void Column::CheckAllColumns(const google::protobuf::Message& message) const
  44. {
  45. const google::protobuf::Descriptor* descriptor = message.GetDescriptor();
  46. foreach (const std::string& column, columns)
  47. {
  48. if (column == "*")
  49. {
  50. continue;
  51. }
  52. if (!descriptor->FindFieldByName(column))
  53. {
  54. boost::format format("message: %1%, field: %2%");
  55. format % message.GetTypeName() % column;
  56. throw MessageHasNoSuchFeildException() << MessageHasNoSuchFeildErrStr(format.str());
  57. }
  58. }
  59. }
  60. } // namespace Egametang