11 #ifndef UT_PackageUtils_H
12 #define UT_PackageUtils_H
28 #include <hboost/any.hpp>
48 static const char *path_sep()
53 static char path_sep_char()
58 static const char *vardef_sep()
63 static UT_StringHolder makeVarRef(
const char * var_name,
bool use_symbol=
true,
64 const char * prefix=
nullptr,
const char * suffix=
nullptr)
69 wb.
format(
"{}{}{}{}", use_symbol ?
"$" :
"", prefix ? prefix :
"", var_name, suffix ? suffix :
"");
77 out_major = (_MSC_FULL_VER / 10000000) % 10000;
78 out_minor = (_MSC_FULL_VER / 100000) % 100;
80 #elif defined(__clang__)
82 out_major = __clang_major__;
83 out_minor = __clang_minor__;
85 #elif defined(__GNUC__)
88 out_minor = __GNUC_MINOR__;
105 sval.strip(kStripables.asHolder());
118 const char * var_value,
152 template <
typename T,
typename... Args>
155 return UTmakeShared<T>(std::forward<Args>(
args)...);
197 return SYSversionCompare(
246 return compare(other,
false ) == 0;
256 if (tokens.
size() > 4)
261 else if (tokens.
size()==1)
263 hver.
myMajor = SYSatoi(tokens[0].c_str());
265 else if (tokens.
size()==2)
267 hver.
myMajor = SYSatoi(tokens[0].c_str());
268 hver.
myMinor = SYSatoi(tokens[1].c_str());
270 else if (tokens.
size()==3)
272 hver.
myMajor = SYSatoi(tokens[0].c_str());
273 hver.
myMinor = SYSatoi(tokens[1].c_str());
274 hver.
myBuild = SYSatoi(tokens[2].c_str());
278 hver.
myMajor = SYSatoi(tokens[0].c_str());
279 hver.
myMinor = SYSatoi(tokens[1].c_str());
280 hver.
myBuild = SYSatoi(tokens[2].c_str());
281 hver.
myPatch = SYSatoi(tokens[3].c_str());
297 static char const* toString();
310 return myMajor - other.
myMajor;
322 return myMinor - other.
myMinor;
327 return myMicro - other.
myMicro;
377 if (tokens.
size() > 3)
382 else if (tokens.
size()==1)
384 pyver.
myMajor = SYSatoi(tokens[0].c_str());
386 else if (tokens.
size()==2)
388 pyver.
myMajor = SYSatoi(tokens[0].c_str());
389 pyver.
myMinor = SYSatoi(tokens[1].c_str());
391 else if (tokens.
size()==3)
393 pyver.
myMajor = SYSatoi(tokens[0].c_str());
394 pyver.
myMinor = SYSatoi(tokens[1].c_str());
395 pyver.
myMicro = SYSatoi(tokens[2].c_str());
468 if (!ver_str || !strlen(ver_str))
477 if (tokens.
size() < 1 || tokens.
size() > 3)
483 if (tokens.
size()==1)
485 pbver.
myName = tokens[0].c_str();
487 else if (tokens.
size()==2)
489 pbver.
myName = tokens[0].c_str();
490 pbver.
myMajor = SYSatoi(tokens[1].c_str());
494 pbver.
myName = tokens[0].c_str();
495 pbver.
myMajor = SYSatoi(tokens[1].c_str());
496 pbver.
myMinor = SYSatoi(tokens[2].c_str());
602 void set(
const char *value)
654 wb.
format(
"{}", hboost::any_cast<fpreal64>(myValue));
656 else if (isA<int64>())
658 wb.
format(
"{}", hboost::any_cast<int64>(myValue));
660 else if (isA<bool>())
662 wb.
format(
"{}", hboost::any_cast<bool>(myValue) ?
"1" :
"0");
664 else if (isA<std::string>())
666 wb.
format(
"{}",hboost::any_cast<std::string>(myValue));
668 else if (isA<HVersion>())
670 auto && hver = hboost::any_cast<
HVersion>(myValue);
671 wb.
format(
"{}.{}.{}.{}",hver.myMajor,hver.myMinor,hver.myBuild,hver.myPatch);
673 else if (isA<PYVersion>())
675 auto && pyver = hboost::any_cast<
PYVersion>(myValue);
676 wb.
format(
"python{}.{}", pyver.myMajor,pyver.myMinor);
678 else if (isA<HPlatformBuildVersion>())
681 wb = hbc_ver.toString();
685 UT_ASSERT(!
"Unknown type in UT_Package::utils::Value");
691 template <
typename T>
692 T const &
get()
const
694 return hboost::any_cast<
T const &>(myValue);
697 template <
typename T>
700 return hboost::typeindex::type_id<T>() == myValue.type();
705 return !myValue.empty();
714 auto && lhs = hboost::any_cast<
std::string>(myValue);
716 return compareIgnoreCase(lhs, rhs);
724 if (isA<int64>() && other.
isA<
int64>())
726 return get<int64>() == other.
get<
int64>();
734 if (isA<bool>() && other.
isA<
bool>())
736 return get<bool>() == other.
get<
bool>();
747 return get<HVersion>() == hver;
764 return get<PYVersion>() == pyver;
781 return get<HPlatformBuildVersion>() == pbver;
790 throw std::runtime_error(
"utils::Value::isEqual: unsupported type");
808 return get<HVersion>() > hver;
825 return get<PYVersion>() > pyver;
842 return get<HPlatformBuildVersion>() > pbver;
853 throw std::runtime_error(
"utils::Value::isGreater: unsupported types");
879 return get<HVersion>() < hver;
896 return get<PYVersion>() < pyver;
913 return get<HPlatformBuildVersion>() < pbver;
924 throw std::runtime_error(
"utils::Value::isLess: unsupported types");
938 if (
valid() && isA<std::string>())
940 auto && to_replace = get<std::string>();
954 return ((s1.size() == s2.size()) &&
956 [](
char & c1,
char & c2)
958 return (c1 == c2 || std::toupper(c1) == std::toupper(c2));
981 : myHasErrorFlag(false)
982 , myLog(&myDefaultLog)
983 , myVerboseFlag(false)
989 myVerboseFlag = flag;
994 return myVerboseFlag;
1002 myHasErrorFlag =
true;
1006 template<
typename ...Args >
1012 myHasErrorFlag =
true;
1025 template<
typename ...Args >
1041 addToBuffer(
nullptr, msg);
1044 template<
typename ...Args >
1051 addToBuffer(
nullptr, formatMsg(msg, std::forward<Args>(
args)...));
1059 template<
typename ...Args >
1067 myDefaultLog.
clear();
1069 myEntryArray.
clear();
1070 myErrorArray.
clear();
1071 myWarningArray.
clear();
1072 myHasErrorFlag =
false;
1077 myErrorArray.
clear();
1078 myHasErrorFlag =
false;
1083 for (
auto && entry : myEntryArray)
1085 os << entry.c_str() << std::endl;
1086 auto && it = myEntryMap.find(entry);
1087 os << it->second.c_str() << std::endl;
1092 os << myDefaultLog.
c_str() << std::endl;
1101 if (header && myVerboseFlag)
1103 log +=
"= = = Houdini Package log = = =\n";
1108 if (header && myVerboseFlag)
1110 log +=
"= = = = = = = = = = = = = = = =\n";
1117 return myErrorArray;
1122 return myWarningArray;
1129 std::cout << title << std::endl;
1134 std::cerr << title << std::endl;
1144 myLog = &myDefaultLog;
1149 if (!myEntryMap.count(entry))
1152 myEntryArray.
append(entry);
1154 myLog = &myEntryMap[entry];
1159 return myHasErrorFlag;
1177 template<
typename ...Args >
1185 void addToBuffer(
const char* prefix,
const char* msg)
1187 if (!msg || !strlen(msg))
1202 myErrorArray.
append(msg);
1206 myWarningArray.
append(msg);
1226 bool myHasErrorFlag;
1233 #endif // UT_PackageUtils_H
bool isGreaterEqual(utils::Value const &other) const
std::string ignore_case(std::string item)
Helper function to allow ignore_case to be passed to IsMember or Transform.
int getVersion(int version)
UT_API void normalizePath(UT_String &file_path, bool want_marker=false, bool always_want_expanded_path=false)
bool isGreater(utils::Value const &other) const
bool operator>(HVersion const &other) const
UT_API bool buildVarDependency(UT_StringHolder const &var_name, const char *var_value, UT_StringArray &unset_vars, UT_StringMap< UT_StringSet > &vars_dep_map, UT_StringMap< UT_StringSet > &vars_circ_dep)
UT_StringHolder toString(bool header=true) const
void start(char const *entry)
bool operator>=(HVersion const &other) const
SYS_FORCE_INLINE void clear()
int compare(HVersion const &other, bool full=true) const
GLsizei const GLchar *const * string
bool operator<(HVersion const &other) const
bool isEmpty() const
Same as !isstring()
UT_API UT_StringHolder makeVarRefPlatform(const char *var)
SYS_FORCE_INLINE const char * buffer() const
void info(char const *msg, Args &&...args)
int compare(PYVersion const &other) const
int substitute(const char *find, const char *replacement, int count=-1)
An output stream object that owns its own string buffer storage.
void message(char const *msg)
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
bool equal(const UT_StringRef &str, bool ignore_case=false) const
void message(char const *msg, Args &&...args)
bool substitute(char const *find, char const *replace_with)
bool operator<=(HVersion const &other) const
UT_StringArray const & errors() const
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
const UT_WorkBuffer & str()
Returns a read-only reference to the underlying UT_WorkBuffer.
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
void toStream(std::ostream &os) const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
void error(char const *msg, Args &&...args)
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
UT_StringHolder toString() const
void set(PYVersion value)
void set(HPlatformBuildVersion value)
int tokenize(char *argv[], int max_args, char separator)
bool any(const vbool4 &v)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
UT_API const char * pathSepShell()
UT_WorkBuffer toWorkBuffer() const
UT_StringArray const & warnings() const
bool isLess(utils::Value const &other) const
hboost::any const & value() const
GLint GLint GLsizei GLint GLenum format
Value(UT_StringRef const &value)
static UT_SharedPtr< T > make(Args &&...args)
UT_API UT_StringHolder expandVar(const char *arg, bool want_marker)
static PYVersion convert(char const *pyver_str)
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
void set(const char *value)
bool isEqual(utils::Value const &other, bool ignore_case=false) const
SYS_FORCE_INLINE const char * c_str() const
void error(char const *msg)
void warning(char const *msg, Args &&...args)
UT_API UT_StringHolder cnormalizePath(UT_StringHolder const &file_path, bool want_marker=false, bool always_want_expanded_path=false)
constexpr UT_StringLit klog_error
bool operator==(HVersion const &other) const
void append(Logger const &logger)
UT_StringMap< UT_StringHolder > EntryMap
UT_StringArray EntryArray
UT_API void normalizeEnvVarPath(UT_String &file_path, bool want_marker=false, bool always_want_expanded_path=false)
size_t format(const char *fmt, const Args &...args)
constexpr UT_StringLit klog_info
void log(char const *title, Flags flags=Flags::all) const
constexpr UT_StringLit klog_warning
SYS_FORCE_INLINE const UT_StringHolder & asHolder() const
**If you just want to fire and args
void info(char const *msg)
void clear()
Resets list to an empty list.
static HVersion convert(UT_StringRef const &str)
void setAsVerbose(bool flag)
bool startsWith(const UT_StringView &prefix, bool case_sensitive=true) const
void warning(char const *msg)
bool isLessEqual(utils::Value const &other) const
Value(HPlatformBuildVersion value)
SYS_FORCE_INLINE bool isstring() const
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool