Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. My New Friend

My New Friend

Scheduled Pinned Locked Moved The Lounge
c++linuxregexhelpannouncement
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BernardIE5317
    wrote on last edited by
    #1

    Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of switch case: statements utilizing numeric constants which should be in numeric order so the random number case argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in the switch statement are reorganized to match it is then necessary to renumber in sequence the lengthy list of case statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond Tutu

    CPalliniC M H 3 Replies Last reply
    0
    • B BernardIE5317

      Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of switch case: statements utilizing numeric constants which should be in numeric order so the random number case argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in the switch statement are reorganized to match it is then necessary to renumber in sequence the lengthy list of case statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond Tutu

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I'm perplexed.

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      In testa che avete, signor di Ceprano?

      B raddevusR 2 Replies Last reply
      0
      • B BernardIE5317

        Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of switch case: statements utilizing numeric constants which should be in numeric order so the random number case argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in the switch statement are reorganized to match it is then necessary to renumber in sequence the lengthy list of case statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond Tutu

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        Huh ? You have performance issues on a switch that you need to re-order the case statements ?

        CI/CD = Continuous Impediment/Continuous Despair

        B 1 Reply Last reply
        0
        • CPalliniC CPallini

          I'm perplexed.

          "In testa che avete, Signor di Ceprano?" -- Rigoletto

          B Offline
          B Offline
          BernardIE5317
          wrote on last edited by
          #4

          I swear English is my native language though I sometimes seem to speak it w/ a slight Polish accent. Maybe that's the cause of the confusion.

          1 Reply Last reply
          0
          • B BernardIE5317

            Greetings Kind Regards It is often necessary in my C++ test code to update a lengthy list of switch case: statements utilizing numeric constants which should be in numeric order so the random number case argument generator can know the limits. Each calls a method to a class being tested. I find myself frequently rearranging the order of the class method declarations. Once the called methods in the switch statement are reorganized to match it is then necessary to renumber in sequence the lengthy list of case statements. A tedious affair. After numerous such I finally spent an hour or two figuring out how awk can do it for me. It worked. Only one line of awk code. Then it occurred to me to seek AI assistance. I posed the awk problem to Perplexity. Bingo Presto Voila. It worked also. Perplexity is my new friend. - Cheerios "I want to sing, I want to cry, I want to laugh. Everything together. And jump and dance. The day has arrived - yippee!" - Desmond Tutu

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            Why are you reordering the switch, exactly? Performance issues? If so, you might get a lot more mileage out of using compiler specific extensions to implement a pure jump table out of it.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            A 1 Reply Last reply
            0
            • M Maximilien

              Huh ? You have performance issues on a switch that you need to re-order the case statements ?

              CI/CD = Continuous Impediment/Continuous Despair

              B Offline
              B Offline
              BernardIE5317
              wrote on last edited by
              #6

              The performance issue was re/ my fingers re-editing the lengthy list of case statements. Fortunately awk will from now on do it for me.

              1 Reply Last reply
              0
              • H honey the codewitch

                Why are you reordering the switch, exactly? Performance issues? If so, you might get a lot more mileage out of using compiler specific extensions to implement a pure jump table out of it.

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                A Offline
                A Offline
                Alister Morton
                wrote on last edited by
                #7

                Maybe relying on fall through?

                H 1 Reply Last reply
                0
                • A Alister Morton

                  Maybe relying on fall through?

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  Yikes. :~

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  J 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    I'm perplexed.

                    "In testa che avete, Signor di Ceprano?" -- Rigoletto

                    raddevusR Offline
                    raddevusR Offline
                    raddevus
                    wrote on last edited by
                    #9

                    Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?

                    interface IDataSaver(){
                    int Save();
                    }

                    class InternetSaver : IDataSaver{
                    String dataToSave;
                    Int Save(){
                    // 1. Http write dataToSave to URL;
                    //. 2. Return 0 - success
                    }
                    }

                    class FileSaver : IDataSaver{
                    String dataToSave;
                    Int Save(){
                    // 1. File write dataToSave to FILE;
                    //. 2. Return 0 - success
                    }
                    }

                    class DBSaver : IDataSaver{
                    String dataToSave;
                    Int Save(){
                    // 1. write dataToSave to DATABASE;
                    //. 2. Return 0 - success
                    }
                    }

                    // driver
                    List allDataSavers = new List();
                    allDataSavers.Add(new InternetSaver());
                    allDataSavers.Add(new FileSaver());
                    allDataSavers.Add(new DBSaver());

                    foreach (IDataSaver ds in allDataSavers){
                    ds.Save(); /// no need to determine type (no switch) bec all implement Save()
                    }

                    CPalliniC B 2 Replies Last reply
                    0
                    • H honey the codewitch

                      Yikes. :~

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      J Offline
                      J Offline
                      jmaida
                      wrote on last edited by
                      #10

                      yikes, indeed, like a cliff.

                      "A little time, a little trouble, your better day" Badfinger

                      1 Reply Last reply
                      0
                      • raddevusR raddevus

                        Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?

                        interface IDataSaver(){
                        int Save();
                        }

                        class InternetSaver : IDataSaver{
                        String dataToSave;
                        Int Save(){
                        // 1. Http write dataToSave to URL;
                        //. 2. Return 0 - success
                        }
                        }

                        class FileSaver : IDataSaver{
                        String dataToSave;
                        Int Save(){
                        // 1. File write dataToSave to FILE;
                        //. 2. Return 0 - success
                        }
                        }

                        class DBSaver : IDataSaver{
                        String dataToSave;
                        Int Save(){
                        // 1. write dataToSave to DATABASE;
                        //. 2. Return 0 - success
                        }
                        }

                        // driver
                        List allDataSavers = new List();
                        allDataSavers.Add(new InternetSaver());
                        allDataSavers.Add(new FileSaver());
                        allDataSavers.Add(new DBSaver());

                        foreach (IDataSaver ds in allDataSavers){
                        ds.Save(); /// no need to determine type (no switch) bec all implement Save()
                        }

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #11

                        Imagine the class diagram. :-D

                        "In testa che avete, Signor di Ceprano?" -- Rigoletto

                        In testa che avete, signor di Ceprano?

                        raddevusR 1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          Imagine the class diagram. :-D

                          "In testa che avete, Signor di Ceprano?" -- Rigoletto

                          raddevusR Offline
                          raddevusR Offline
                          raddevus
                          wrote on last edited by
                          #12

                          CPallini wrote:

                          Imagine the class diagram

                          You mean in the original situation where he is creating separate classes for each of his switch statements, right? Yeah, it would get crazy big!

                          CPalliniC 1 Reply Last reply
                          0
                          • raddevusR raddevus

                            CPallini wrote:

                            Imagine the class diagram

                            You mean in the original situation where he is creating separate classes for each of his switch statements, right? Yeah, it would get crazy big!

                            CPalliniC Offline
                            CPalliniC Offline
                            CPallini
                            wrote on last edited by
                            #13

                            Exactly!

                            "In testa che avete, Signor di Ceprano?" -- Rigoletto

                            In testa che avete, signor di Ceprano?

                            1 Reply Last reply
                            0
                            • raddevusR raddevus

                              Are you perplexed because he could’ve used Polymorphism via Interfaces and solved this problem?

                              interface IDataSaver(){
                              int Save();
                              }

                              class InternetSaver : IDataSaver{
                              String dataToSave;
                              Int Save(){
                              // 1. Http write dataToSave to URL;
                              //. 2. Return 0 - success
                              }
                              }

                              class FileSaver : IDataSaver{
                              String dataToSave;
                              Int Save(){
                              // 1. File write dataToSave to FILE;
                              //. 2. Return 0 - success
                              }
                              }

                              class DBSaver : IDataSaver{
                              String dataToSave;
                              Int Save(){
                              // 1. write dataToSave to DATABASE;
                              //. 2. Return 0 - success
                              }
                              }

                              // driver
                              List allDataSavers = new List();
                              allDataSavers.Add(new InternetSaver());
                              allDataSavers.Add(new FileSaver());
                              allDataSavers.Add(new DBSaver());

                              foreach (IDataSaver ds in allDataSavers){
                              ds.Save(); /// no need to determine type (no switch) bec all implement Save()
                              }

                              B Offline
                              B Offline
                              BernardIE5317
                              wrote on last edited by
                              #14

                              Perhaps I should provide the code. I prefer them in the same order as declared in the class not shown as it is a class cTest global variable.

                              void Random\_\_METHOD()
                              {
                              	static const int last\_case = 96;
                                    // Random Number Generator
                              	auto \_case\_ = m\_cSCALAR\_RNG.operator() < int > (0, last\_case);
                              		switch(\_case\_)
                              		{
                              		default: throw einternal\_error\_eXception;
                              		case 0: Random\_\_default\_constructor(); break;
                              		case 1: Random\_\_primordialTimePoint(); break;
                              		case 2: Random\_\_DIAGNOSTIC\_SNAPSHOT\_HASH(); break;
                              		case 3: Random\_\_recordTermination\_time\_point\_node\_spec();
                              		case 4: Random\_\_open\_with\_arguments(); break;
                              		case 5: Random\_\_open(); break;
                              		case 6: Random\_\_close(); break;
                              		case 7: Random\_\_is\_open(); break;
                              		case 8: Random\_\_set\_toNascentState(); break;
                              		case 10: Random\_\_swap(); break;
                              		case 11: Random\_\_startTransaction(); break;
                              		case 12: Random\_\_endTransaction();  break;
                              		case 13: Random\_\_cancelTransaction(); break;
                              		case 14: Random\_\_is\_activeTransaction(); break;
                              		case 15: Random\_\_activeTransaction\_ctransaction\_datum(); break;
                              		case 16: Random\_\_is\_saved(); break;
                              		case 17: Random\_\_save(); break;
                              		case 18: Random\_\_offset(); break;
                              		case 19: Random\_\_size(); break;
                              		case 20: Random\_\_eofOffset(); break;
                              		case 21: Random\_\_mirror(); break;
                              		case 22: Random\_\_archivesPaths(); break;
                              		case 23: Random\_\_archivesFilenames(); break;
                              		case 24: Random\_\_fullPath(); break;
                              		case 25: Random\_\_fileName(); break;
                              		case 26: if(m\_rfe) {} break;
                              		case 27: if(!m\_rfe) {} break;
                              		case 28: m\_rfe == m\_rfe; break;
                              		case 29: m\_rfe != m\_rfe; break;
                              		case 30: Random\_\_read(); break;
                              		case 31: Random\_\_output(); break;
                              		case 32: Random\_\_delete(); break;
                              		case 33: Random\_\_setOffset(); break;
                              		case 34: Random\_\_incOffset(); break;
                              		case 35: Random\_\_decOffset(); break;
                              		case 36: Random\_\_adjust\_eofOffset(); break;
                              		case 37: Random\_\_set\_eofOffset(); break;
                              		case 38: Random\_\_initializedIntervals(); break;
                              		case 39: Random\_\_uninitializedIntervals(); break;
                              		case 40: Random\_\_treeEmpty(); break;
                              		case 41: Random\_\_treeSize(); break;
                              		case 42: Random\_\_number\_ofUndosAvailable(); break;
                              		case 43: Random\_\_undo(); break;
                              		case 44: Random\_\_redo(); break;
                              		case 45: Random\_\_number\_ofRedoBranches(); break;
                              		case 46: Random\_\_undo\_node\_spec\_time\_point(); break;
                              		case 47: Random\_\_undo\_node\_spec\_ctransaction\_datum(); break;
                              		case 48: Random\_\_undo\_node\_spec\_time\_point\_vector\_cedit\_datum(); break;
                              		case 49: R
                              
                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups